Any idea why the error (see stack trace below) and how to resolve it?
In my Activity class, I have these. It never gets into the onReceive method.. why?
private UpdateResultReceiver mUpdateResultReceiver;
@Override
protected void onCreate(Bundle savedInstanceState) {
//other stuff...
registerReceiver();
}
@Override
protected void onResume() {
super.onResume();
// Register BroadcastReceiver
registerReceiver();
}
@Override
protected void onPause() {
super.onPause();
// Unregister BroadcastReceiver
unregisterReceiver();
}
/**
* Register a BroadcastReceiver that receives a result
* from the services
*/
private void registerReceiver() {
// Create an Intent filter that handles Intents from the services
IntentFilter intentFilter =
new IntentFilter(UpdateService1.ACTION_1);
intentFilter.addCategory(Intent.CATEGORY_DEFAULT);
intentFilter.addAction(UpdateService2.ACTION_2);
// Register the BroadcastReceiver.
LocalBroadcastManager.getInstance(this)
.registerReceiver(mUpdateResultReceiver,
intentFilter);
}
/**
* Unregister the receivers
*/
private void unregisterReceiver() {
LocalBroadcastManager.getInstance(this)
.unregisterReceiver(mUpdateResultReceiver);
}
/**
* The Broadcast Receiver that registers itself to receive result
* from UploadVideoService.
*/
private class UpdateResultReceiver
extends BroadcastReceiver {
/**
* Hook method that's dispatched when the UploadService has
* uploaded the Video.
*/
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(UpdateService1.ACTION_1)) {
mFragment1.getProfileInfo();
ViewUtils.showToast(getApplicationContext(), "updated profile");
} else if(intent.getAction().equals(UpdateService2.ACTION_2)) {
mFragment2.getApptList();
ViewUtils.showToast(getApplicationContext(), "updated appts");
}
}
}
In my UpdateService1 class I have debugged till the sendBroadcast method and the program crashes:
private void sendBroadcast(){ // Use a LocalBroadcastManager to restrict the scope of this // Intent to the VideoUploadClient application. LocalBroadcastManager.getInstance(this) .sendBroadcast(new Intent(ACTION_1) .addCategory(Intent.CATEGORY_DEFAULT)); }
Error Stack Trace:
11-01 19:22:09.041: E/AndroidRuntime(26763): java.lang.NullPointerException: Attempt to invoke virtual method 'void android.content.BroadcastReceiver.onReceive(android.content.Context, android.content.Intent)' on a null object reference
11-01 19:22:09.041: E/AndroidRuntime(26763): at android.support.v4.content.LocalBroadcastManager.executePendingBroadcasts(LocalBroadcastManager.java:297)
11-01 19:22:09.041: E/AndroidRuntime(26763): at android.support.v4.content.LocalBroadcastManager.access$000(LocalBroadcastManager.java:46)
11-01 19:22:09.041: E/AndroidRuntime(26763): at android.support.v4.content.LocalBroadcastManager$1.handleMessage(LocalBroadcastManager.java:116)
11-01 19:22:09.041: E/AndroidRuntime(26763): at android.os.Handler.dispatchMessage(Handler.java:102)
11-01 19:22:09.041: E/AndroidRuntime(26763): at android.os.Looper.loop(Looper.java:145)
11-01 19:22:09.041: E/AndroidRuntime(26763): at android.app.ActivityThread.main(ActivityThread.java:5942)
11-01 19:22:09.041: E/AndroidRuntime(26763): at java.lang.reflect.Method.invoke(Native Method)
11-01 19:22:09.041: E/AndroidRuntime(26763): at java.lang.reflect.Method.invoke(Method.java:372)
11-01 19:22:09.041: E/AndroidRuntime(26763): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1400)
11-01 19:22:09.041: E/AndroidRuntime(26763): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1195)