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. acp is not building on my m/c.

Hi All,
          while in normal build  "make acp" in dir out/host/executable/
inr.../ it is creating 3 files in out dir
          such as acp, acp.o acp.p in which acp is host
executable ,from acp.o acp.P it is building this host executable
acp ,i am using some diff compiler to generate .o and .p file so which
build options we need to specify in order to build host executable acp
I am getting this  error:
 L0084: option "--rpath-link out/target/product/generic/obj/lib" not
implemented
Command line : error: L0064: Linking aborted
collect2: ld returned 1 exit statusm getting following error

it is just compiling source files but not linking.
can anybody guide me on htis

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

2. Sharing activities/Services across packages

Hi,

I have two packages and would like to share activities and Services
between them. The following is what I have:

package1 -- com.android.rk1
This package consists of a service by the name "RKService1".

package2 -- com.android.rk2
This package consists of a service by the name "RKService2".

Now, from an activity of package2, I can call the service RKService2.
Intent serv = new Intent(this,RKTestService2.class);

But, I am not able to call RKService1 even after importing package1.

To begin with, I am seeing the compilation error:
"package com.android.rk1 does not exist"
where my import line says ..
"import com.android.rk1.RKService1;"

Any pointers will be appreciated.

Thanks,
Ravi
--~--~---------~--~----~------------~-------~--~----~

3. Problem when launch IM application on Cupcake...

4. Anybody uses Positron on Windows?

5. long home key press / task switcher

6. Share data between activities queston

7. G1 Camera Specs