0

I am trying to pass data through an intent, but its throwing an error I don't understand.

Activity:

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>();
}

and this is the error am getting android is not being helpful in telling me what is wrong.

Error:

    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) 
Bhavesh Odedra
  • 10,990
  • 12
  • 33
  • 58
  • http://stackoverflow.com/questions/18823792/how-to-fix-java-lang-indexoutofboundsexception – airowe Oct 06 '15 at 14:20
  • your pieces arraylist is empty...It is initialized but has no values it in...so check whether you are adding data to pieces arraylist properly – Shadow Droid Oct 06 '15 at 14:26
  • You are sending empty data to your adapter always. See you are creating new object in your adapter. mEditorAdapater = new EditorAdapter(this, **new ArrayList()**); I am not sure how you are populating your listview. And logcat saying your `pieces` ArrayList is also empty. – Kunu Oct 06 '15 at 14:38

1 Answers1

0

This is a problem with your "pieces" array list-- it has nothing to do with starting a new activity or passing data through an intent. Maybe comment everything out in the onItemClick method and put

log.v("PIECES SIZE: ",""+pieces.size());

If this logs a 0, then you know your problem lies within that array.