Reputation: 1307
i'm trying to put some intents in a List to a specific place but the app crashes 'cause of NullPointerExecption but don't understand why !
private ArrayList<PendingIntent> test;
[...]
try
{
test.add( 42, alarm_Intent);
// I tried aswell without index ( it makes it crash too ) :
test.add(alarm_Intent);
}
catch (Exception e)
{
Toast.makeText(this, ""+e.toString(), Toast.LENGTH_LONG).show();
}
Here is the error :
[2014-06-08 18:30:41 - ddms] null
java.lang.NullPointerException
at com.android.ddmlib.Client.read(Client.java:698)
at com.android.ddmlib.MonitorThread.processClientActivity(MonitorThread.java:311)
at com.android.ddmlib.MonitorThread.run(MonitorThread.java:263)
What did i do wrong ?
Upvotes: 1
Views: 2115
Reputation: 1851
You never called ctor of your array list and therefore it is null while calling add.
Upvotes: 1
Reputation: 1565
initialise test array. private ArrayList<PendingIntent> test = new ArrayList<PendingIntent>();
Upvotes: 1
Reputation: 12725
You need to initialize test
.
Do it this way:
private ArrayList<PendingIntent> test = new ArrayList<PendingIntent>;
Upvotes: 1
Reputation: 48232
Should be
ArrayList<PendingIntent> test = new ArrayList<PendingIntent>();
Upvotes: 1