Reputation: 407
I am currently encountering a NullPointerException
. I have used log statements to realize that it it shuts down when one specific line of code is read.
I have read lots about this type of exception, however I don't understand what is wrong with this specific statement.
try {
Log.i(TAG, "1"); // Breaks here
mDiaryId = ContentUris.parseId(launchingIntent.getData());
Log.i(TAG, "2");
} catch (NumberFormatException e) {
Log.i(TAG, "3");
mDiaryId = -1;
}
Upvotes: 0
Views: 129
Reputation: 20426
You need to check for null
after calling launchingIntent.getData()
. Like this.
try {
Log.i(TAG, "1");
Uri data = getIntent().getData();
if (data != null) { // <-- check data for null
mDiaryId = ContentUris.parseId(data);
} else {
mDiaryId = -1;
Log.i(TAG, "Data is null");
}
Log.i(TAG, "2");
} catch (NumberFormatException e){
Log.i(TAG, "3");
mDiaryId = -1;
}
Upvotes: 1