Graham Bright wrote:
>
> Hi I get a null point exception [sic] with the following code can anyone 
> help ? 
>

I can point out a few things wrong here that probably contribute to it, but 
your code is badly formatted and incomplete, making it difficult for one to 
be sure one has the right answer.
 

> I want to go through my array items and print each item to the user 
> using a toast message
>

You don't actually do anything with arrays in the snippet you showed us. 

package gb.org; 
>

That should  be 'package org.gb;'.  You have the package parts in the wrong 
order.  Top-level domain (TLD) first, then second-level, and so on, is the 
correct order.  Read the coding conventions document on the Oracle site and 
the coding-convention section in the Java Language Specification (JLS). 
 Follow the conventions. 

> import java.util.Arrays; 

You don't use this class.  Why do you import it?

> import java.util.ArrayList; 
> import android.widget.Toast; 
> import android.app.Activity; 
> 
> 
> //I need an activity for my toast to work correctly 
> public class ExtractContacts extends Activity{ 
> 
> ArrayList<String> items=new ArrayList<String>(); 
 
Indentation?

> public void addToArray(String contactToBlock) { 
> 
> //add a number to items 
> contactToBlock.toString(); 

Why make this call and throw away the result?  Why make it at all, given 
that the variable already is of type 'String'?

> items.add(contactToBlock); 
> String Temp; 

Variable names should begin with a lower-case letter unless they reference 
a constant.

Variables should only be decarled if they're used.

> for (int i =0;i<items.size();i++){ 
> System.out.println(items.get(i)); 
> Toast.makeText(this, "Hello world " + items.get(i), 
> Toast.LENGTH_LONG).show(); 
> } 
> 
> 
> 
> } 
> 
> 
> } 

What's certain, the error occurs in the code you omitted from this 
woefully-incomplete snippet you posted.

What's likely, although for some weird reason you haven't told us any 
details about the exception you see (not even its correct name), such as 
the error message (COPIED and pasted, not paraphrased) or exactly *what* 
pointer, pray tell, is 'null'.  My money's on 'contactToBlock'.  I notice 
you put no protection in your method against that variable being 'null', 
and in fact go out of your way with that strange call to 'toString()' to 
make sure there's trouble if it is.

Follow this standard in Usenet code posts:
http://sscce.org/

That way you won't waste your time or anyone else's.

-- 
Lew

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to