我正在处理片段类和广播接收器类。问题是,我需要将一个值从广播接收器类传递给片段类并启动片段类(如果我使用活动类,则为 startActivity(intent))。我从谷歌尝试了很多方法,但程序崩溃了。有什么办法吗?
我无法将片段更改为片段活动/其他,因为其他类受到影响。我也无法使广播接收器类分段。
这是广播接收器类:
Fragmented fragment = new Fragmented();
Bundle bundle2 = new Bundle();
bundle2.putString("key", key);
fragment.setArguments(bundle2);
fragment.onStart();
这是片段类:
@Override
public void onStart()
{
Bundle bundle = this.getArguments();
String hello = bundle.getString("key");
System.out.println(hello);
super.onStart();
FlurryAgent.onStartSession(getActivity().getApplicationContext(),"xxxx");
EasyTracker.getInstance().activityStart(getActivity());
EasyTracker.getTracker().sendView("(2.0)New_MainView");
}
和日志猫:
E/AndroidRuntime(16572): java.lang.RuntimeException: Unable to start receiver com.XX.XX.Receiver: java.lang.NullPointerException 10-20
13:20:30.790: E/AndroidRuntime(16572): at android.app.ActivityThread.handleReceiver(ActivityThread.java:1809)10-20
13:20:30.790: E/AndroidRuntime(16572): at android.app.ActivityThread.access$2400(ActivityThread.java:117) 10-20
13:20:30.790: E/AndroidRuntime(16572): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:985)10-20
13:20:30.790: E/AndroidRuntime(16572): at android.os.Handler.dispatchMessage(Handler.java:99)10-20
13:20:30.790: E/AndroidRuntime(16572): at android.os.Looper.loop(Looper.java:130)10-20
13:20:30.790: E/AndroidRuntime(16572): at android.app.ActivityThread.main(ActivityThread.java:3691)10-20
13:20:30.790: E/AndroidRuntime(16572): at java.lang.reflect.Method.invokeNative(Native Method)10-20
13:20:30.790: E/AndroidRuntime(16572): at java.lang.reflect.Method.invoke(Method.java:507)10-20
13:20:30.790: E/AndroidRuntime(16572): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:907)10-20
13:20:30.790: E/AndroidRuntime(16572): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:665)10-20
13:20:30.790: E/AndroidRuntime(16572): at dalvik.system.NativeStart.main(Native Method)10-20
13:20:30.790: E/AndroidRuntime(16572): Caused by: java.lang.NullPointerException10-20
13:20:30.790: E/AndroidRuntime(16572): at com.XX.XX.Fragmented.onStart(Fragmented.java:265)10-20
13:20:30.790: E/AndroidRuntime(16572): at com.xx.xx.Receiver.onReceive(Receiver.java:84)10-20
13:20:30.790: E/AndroidRuntime(16572): at android.app.ActivityThread.handleReceiver(ActivityThread.java:1798)