1

I always get nullPointerException while starting karsilastir activity in my code here sending activity code:

  karsilastir.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {

                Intent intent_notify=new Intent();
                intent_notify.setClass(Evraka1Activity.this,karsilastir.class);

             Bundle bundle=new Bundle();

                 bundle.putStringArrayList("urunler", urunler);

                 intent_notify.putExtra("urunler",bundle);

                 //startService(intent_notify);
                 startActivity(intent_notify);
}

here receive activity code:

public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.karsilastirmasonuclari);
        Intent intent = getIntent();

        Bundle b = intent.getExtras();
       gelenurunler = b.getStringArrayList("urunler"); 
}
cyo
  • 193
  • 2
  • 4
  • 17

2 Answers2

2

It depends on the type of arraylist(copied from here)

  1. putIntegerArrayListExtra(String name, ArrayList value)
  2. putParcelableArrayListExtra(String name, ArrayList value)
  3. putStringArrayListExtra(String name, ArrayList value)
  4. putCharSequenceArrayListExtra(String name, ArrayList value)

Then you can read from you next activity by replacing put with get with key string as argument,eg

myIntent.getStringArrayListExtra("arrayPeople");

Updated::

Intent i = new Intent(this,name.class);
Bundle b = new Bundle();
b.putIntegerArrayListExtra(String name, ArrayList<Integer> value);
i.putExtra(String name,b);
startActivity(i);

And get data into another activity like

Bundle b = getIntent().getExtra().putParcelableArrayListExtra(String name);   
Community
  • 1
  • 1
Shankar Agarwal
  • 34,573
  • 7
  • 66
  • 64
  • i've try whatever says from your link but it doesn't also work – cyo May 26 '12 at 13:20
  • b.putIntegerArrayListExtra(String name, ArrayList value);i got compilation error it says :"The method putStringArrayListExtra(String, ArrayList) is undefined for the type Bundle" – cyo May 26 '12 at 13:25
0

Create a member field local variable the the top of your class. The m denotes a member field and is part of the Android coding style standards. Check the Android Notepad tutorial for reference.

http://developer.android.com/resources/tutorials/notepad/notepad-ex2.html

public class karsilastir extends ListActivity {

/* Create an instance variable just below the class constructor. */    
ArrayList mUrunler;

....

karsilastir.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {

            Intent intent_notify=new Intent();
            intent_notify.setClass(Evraka1Activity.this,karsilastir.class);

         Bundle bundle=new Bundle();

             bundle.putStringArrayList("urunler", mUrunler);

             intent_notify.putExtra("urunler",bundle);

             //startService(intent_notify);
             startActivity(intent_notify);
        }
    }
dpott197
  • 1,060
  • 1
  • 9
  • 11