0
我試圖通過一個意圖傳遞數據,但它拋出一個錯誤,我不明白。我在列表視圖的setOnItemClickListener上遇到錯誤
活動:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_editor);
conn = new ConnectionDetector(this);
mEditorAdapater = new EditorAdapter(this, new ArrayList<ParseObject>());
mListView = (ListView) findViewById(R.id.listEditor);
mListView.setAdapter(mEditorAdapater);
swipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.swipe_refresh_layout_edit);
swipeRefreshLayout.setOnRefreshListener(this);
swipeRefreshLayout.post(new Runnable() {
@Override
public void run() {
swipeRefreshLayout
.setRefreshing(true);
queryPieces();
}
});
mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
String title = pieces.get(position).getString("title");
String status = pieces.get(position).getString("status");
String story = pieces.get(position).getString("story");
String category = pieces.get(position).getString("category");
String location = pieces.get(position).getString("location");
String journo = pieces.get(position).getString("Journo");
String objectId = pieces.get(position).getObjectId();
// byte[] storyClip = pieces.get(position).getBytes("storyClip");
Intent in = new Intent(Editor.this, EditPieceActivity.class);
in.putExtra("title", title);
in.putExtra("status", status);
in.putExtra("story", story);
in.putExtra("category", category);
in.putExtra("location", location);
in.putExtra("id", objectId);
startActivity(in);
//in.putExtra()
}
});
pieces = new ArrayList<ParseObject>();
}
,這是錯誤我得到Android是不是在告訴我什麼是錯的幫助。
錯誤:
10-06 10:16:52.675 12167-12167/main.itprogrammer.journo E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: main.itprogrammer.journo, PID: 12167
java.lang.IndexOutOfBoundsException: Invalid index 0, size is 0
at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:255)
at java.util.ArrayList.get(ArrayList.java:308)
at main.itprogrammer.journo.Editor$2.onItemClick(Editor.java:56)
at android.widget.AdapterView.performItemClick(AdapterView.java:299)
at android.widget.AbsListView.performItemClick(AbsListView.java:1113)
at android.widget.AbsListView$PerformClick.run(AbsListView.java:2911)
at android.widget.AbsListView$3.run(AbsListView.java:3645)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5001)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
at dalvik.system.NativeStart.main(Native Method)
http://stackoverflow.com/questions/18823792/how-to-fix-java-lang-indexoutofboundsexception – airowe
你的作品arraylist是空的......它被初始化但沒有值它在...所以檢查是否您正在將數據正確添加到arraylist中 –
您正在向適配器發送空數據。看到您正在適配器中創建新對象。 mEditorAdapater = new EditorAdapter(this,** new ArrayList()**); 我不知道你是如何填充你的列表視圖。 而logcat說你的'pieces' ArrayList也是空的。 –
Kunu