This is the code that is getting the null pointer exception:
SimpleDateFormat df = new SimpleDateFormat("MMMM dd, yyyy");
String temp = df.format(load.getDeliveryDate());
System.out.println(temp);
date.setText(temp);
This is my code that creates a random date (for test data):
private Date randomDate(){
int month, year, day;
Random call = new Random();
month = call.nextInt(12);
year = call.nextInt(2012);
day = call.nextInt(31);
Date toReturn = new Date(year, month, day);
System.out.println(toReturn.toString());
return toReturn;
}
I was originally getting an error on the line that is setting the text for my date item. Now I'm also getting an error on my date format declaration line.
I'm already checking load to make sure it is not null. It is a custom class that includes a Date attribute.
Logcat Output (after rebuild):
04-30 12:56:10.423: E/AndroidRuntime(8212): FATAL EXCEPTION: main
04-30 12:56:10.423: E/AndroidRuntime(8212): java.lang.NullPointerException
04-30 12:56:10.423: E/AndroidRuntime(8212): at java.util.Calendar.setTime(Calendar.java:1325)
04-30 12:56:10.423: E/AndroidRuntime(8212): at java.text.SimpleDateFormat.formatImpl(SimpleDateFormat.java:536)
04-30 12:56:10.423: E/AndroidRuntime(8212): at java.text.SimpleDateFormat.format(SimpleDateFormat.java:818)
04-30 12:56:10.423: E/AndroidRuntime(8212): at java.text.DateFormat.format(DateFormat.java:376)