Null pointer exception while receiving at Broadcast receiver

by Asif k » Fri, 04 Sep 2009 13:50:26 GMT


Sponsored Links
 Hi all,

  I am receiving Text messages from another application sent through
broadcast intent. I am displaying these messages to my application's
GUI.

  In my application I had defined <broadcast receiver> in my
manifest.xml

------------------------------------------------------------------------------
<receiver android:name=".HHBroadcastReceiver">
                        <intent-filter>
                        <action android:name="android.demo.test"/>
                        </intent-filter>
                </receiver>
-------------------------------------------------------------------------------------
and also define the logic in the Broadcast receiver class

-------------------------------------------------------------------------------------------
public class HHBroadcastReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
//TODO: React to the Intent received.
        String msg_receive = intent.getStringExtra("message1");
        AssetTest.hh_text.append("\n\n"+msg_receive);
}
}
---------------------------------------------------------------------------------------------

but I am getting following error,

09-04 10:49:04.275: ERROR/AndroidRuntime(912):
java.lang.RuntimeException: Unable to start receiver
android.hh.HHBroadcastReceiver: java.lang.NullPointerException
09-04 10:49:04.275: ERROR/AndroidRuntime(912):     at
android.app.ActivityThread.handleReceiver(ActivityThread.java:2417)
09-04 10:49:04.275: ERROR/AndroidRuntime(912):     at
android.app.ActivityThread.access$2700(ActivityThread.java:112)
09-04 10:49:04.275: ERROR/AndroidRuntime(912):     at
android.app.ActivityThread$H.handleMessage(ActivityThread.java:1741)
09-04 10:49:04.275: ERROR/AndroidRuntime(912):     at
android.os.Handler.dispatchMessage(Handler.java:99)
09-04 10:49:04.275: ERROR/AndroidRuntime(912):     at
android.os.Looper.loop(Looper.java:123)
09-04 10:49:04.275: ERROR/AndroidRuntime(912):     at
android.app.ActivityThread.main(ActivityThread.java:3948)
09-04 10:49:04.275: ERROR/AndroidRuntime(912):     at
java.lang.reflect.Method.invokeNative(Native Method)
09-04 10:49:04.275: ERROR/AndroidRuntime(912):     at
java.lang.reflect.Method.invoke(Method.java:521)
09-04 10:49:04.275: ERROR/AndroidRuntime(912):     at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run
(ZygoteInit.java:782)
09-04 10:49:04.275: ERROR/AndroidRuntime(912):     at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:540)
09-04 10:49:04.275: ERROR/AndroidRuntime(912):     at
dalvik.system.NativeStart.main(Native Method)
09-04 10:49:04.275: ERROR/AndroidRuntime(912): Caused by:
java.lang.NullPointerException
09-04 10:49:04.275: ERROR/AndroidRuntime(912):     at
android.hh.HHBroadcastReceiver.onReceive(HHBroadcastReceiver.java:12)
09-04 10:49:04.275: ERROR/AndroidRuntime(912):     at
android.app.ActivityThread.handleReceiver(ActivityThread.java:2408)
09-04 10:49:04.275: ERROR/AndroidRuntime(912):     ... 10 more


Please help.

Thanks,
Asif


--~--~---------~--~----~------------~-------~--~----~



Null pointer exception while receiving at Broadcast receiver

by Randy McEoin » Sun, 06 Sep 2009 17:36:18 GMT


 t would be best to check for null before attempting to use.  Perhaps
whatever is issuing the broadcast is not adding the string extra.

String msg_receive = intent.getStringExtra("message1");
if (msg_receive != null) {
AssetTest.hh_text.append("\n\n"+msg_receive);
}

Randy

On Sep 3, 10:49pm, Asif k <asifk1...@gmail.com> wrote:
--~--~---------~--~----~------------~-------~--~----~


Sponsored Links


Other Threads

1. How can I get Activity object from Intent object or something else

When you are able to get the handle for the intent, you should be able
to use

 intent.getExtras();

The API returns a bundle object which you should have used to send
your complex object.

--
Roman Baumgaertner
Sr. SW Engineer-OSDC
T  Mobile stick together
The views, opinions and statements in this email are those of the
author solely in their individual capacity, and do not necessarily
represent those of T-Mobile USA, Inc.



--~--~---------~--~----~------------~-------~--~----~

2. slider keyboard open detection

I want to use the SetupWizard from the android development phone as a
means to sign in to my google account. The problem is is that a one
point in the setup process it waits for the slider keyboard to open.
On the system I'm porting android, which is a LCD TV system, I don't
have a slider keyboard.

Question is is how is the open detection of a slider keyboard handled
in android. Is there a specific kernel module? is it GPIO. Where is it
handled in the android platform code? I did a search in the source
tree but could not find anything that was related to this.

Anybody any idea,

Thnx

MeElvis


--~--~---------~--~----~------------~-------~--~----~
unsubscribe: android-porting+unsubscr...@googlegroups.com
website: 

3. Android as a virtual PBX

4. Camera Button Broadcast Receiver Problem...

5. How to detect All Ram Memory?

6. To Display Calendar ........

7. Zipalign utility not available in android 1.5_r3