Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to pass an arrayList of objects from one activity to the other activity

 
elenora Rezaie
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I want to pass an arrayList of objects from one activity to the other activity. for doing this, I've written the code below:

In activity A:

In Activity B



but in the line getSerializableExtra("data");, there is null pointer!
I've tested the data if it has elements, and it had. Could anyone please help me to fix my problem?
 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You should not use constructors in activities (how would Android get a chance to populate the object with data when it's not even constructed yet?). Put that code into the onCreate or onResume method.
 
elenora Rezaie
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks for your reply, I did what you said but it still has the error:

05-26 16:20:34.071: E/AndroidRuntime(2706): Caused by: java.lang.NullPointerException
05-26 16:20:34.071: E/AndroidRuntime(2706): at quranlast.ir.Message.onCreate(Message.java:33)
It says that the soure_tableList has null pointer!



 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It says that the soure_tableList has null pointer!

Actually, it doesn't. In fact, "soure_tableList" does not figure into it, because you're not using it, so whether or not it is null is irrelevant. My guess is that "getIntent()" returns null.

As an unrelated aside, note that line 2 of this code accomplishes nothing. It allocates an ArrayList which is then replaced in the following line. You should delete it.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic