I can just pass the name but when i want to pass the email too the program crashes.
Ruben Matt wrote:The problem is when i try to send the information from the first activity to the second.
I'm almost sure that is the ArrayList that is wrong and i dont know what to change.
Unfortunately 'almost sure' isn't really helpful. Like Ulf said, the stack trace in LogCat should tell you exactly what line the exception is at. That will tell us which objects are in use, then you know which one to track down why it has no value. You could be correct in that the problem is the ArrayList - I don't see its purpose. But, on the other hand, that could be a red-herring. The stack trace will tell you where the problem actually manifests.
Ruben Matt wrote:The stack trace shows this.
... at com.exaple.listview.MainActivity$2$1.onItemClick(MainActivity.java:101)
What is line 101 in the MainActivity? It is in the onItemClick() method somewhere.
You said you dont see the purpose of the ArrayList. Could you tell me another way to pass the information from the database to te other activity (TextViews)??
Here is the pertinent code:
In English that would be:
"1) Create a new empty list
2) Add one thing to it
3) Get one thing from it"
If the list only holds one thing, and you immediately pull it out of the list... why do you put the item in the list to begin with? Why not directly assign it to the email variable? Also, the code as posted is an IndexOutOfBoundsException waiting to happen. The List will only ever have one value, but your ListView might have more so the position parameter may be greater than the number of items in emailLists.. If you click on anything but the first email then you will be attempting to get something from the list beyond the List's size.
But none of that would give you a NullPointerException, so it is a side topic - a problem you have to fix when you are done fixing your NPE.
Ruben Matt wrote:This one:
Now we are getting somewhere. There is only one reason for a NullPointerException: A variable being used hasn't been assigned a value yet. You use three Objects in that line of code:
emailLists, cursor, and the String "email". The String is hardcoded, so not null. The emailLists variable was assigned an object in the previous line of code, so it isn't null either. The only one left is cursor.
Your cursor variable has no Object reference, so you can't call methods on it. You have to go back to how the cursor is created, when it is assigned a value, and how it is used and figure out why it is null at this point. Then you have to fix it so it gets a value.
This should be more efficient because you aren't getting a bunch of data you don't need, and then have to cycle through it all to fill your list(s). The other problem with the approach you had was it relied on the details coming back in the same order as the names in the list. This probably isn't guaranteed unless you use an ORDER BY clause both when getting the names and the details.