E/AndroidRuntime: FATAL EXCEPTION: main
? ? ? ? ? ? ? ? ? Process: com.nokia.wlanapp, PID: 18526? ? ? ? ? ? ? ? ? java.lang.RuntimeException: Error receiving broadcast Intent { act=android.net.wifi.SCAN_RESULTS flg=0x4000010 (has extras【外部】) } in com.nokia.wlanapp.Receiver.WifiReceiver@22f1b23
? ? ? ? ? ? ? ? ? ? ? at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:975)
? ? ? ? ? ? ? ? ? ? ? at android.os.Handler.handleCallback(Handler.java:815)
? ? ? ? ? ? ? ? ? ? ? at android.os.Handler.dispatchMessage(Handler.java:104)
? ? ? ? ? ? ? ? ? ? ? at android.os.Looper.loop(Looper.java:207)
? ? ? ? ? ? ? ? ? ? ? at android.app.ActivityThread.main(ActivityThread.java:5902)
? ? ? ? ? ? ? ? ? ? ? at java.lang.reflect.Method.invoke(Native Method)
? ? ? ? ? ? ? ? ? ? ? at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:945)
? ? ? ? ? ? ? ? ? ? ? at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:806)
? ? ? ? ? ? ? ? ? ?Caused by: java.lang.IllegalStateException: System services not available to Activities before onCreate()
? ? ? ? ? ? ? ? ? ? ? at android.app.Activity.getSystemService(Activity.java:5383)
? ? ? ? ? ? ? ? ? ? ? at android.widget.SimpleAdapter.<init>(SimpleAdapter.java:93)
? ? ? ? ? ? ? ? ? ? ? at com.nokia.wlanapp.view.impl.WlanListActivity.setWlanApList(WlanListActivity.java:50)
? ? ? ? ? ? ? ? ? ? ? at com.nokia.wlanapp.presenter.WlanListPresenter.getWlanApList(WlanListPresenter.java:45)
? ? ? ? ? ? ? ? ? ? ? at com.nokia.wlanapp.Receiver.WifiReceiver.onReceive(WifiReceiver.java:21)
? ? ? ? ? ? ? ? ? ? ? at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:963)
? ? ? ? ? ? ? ? ? ? ? at android.os.Handler.handleCallback(Handler.java:815)?
? ? ? ? ? ? ? ? ? ? ? at android.os.Handler.dispatchMessage(Handler.java:104)?
? ? ? ? ? ? ? ? ? ? ? at android.os.Looper.loop(Looper.java:207)?
? ? ? ? ? ? ? ? ? ? ? at android.app.ActivityThread.main(ActivityThread.java:5902)?
? ? ? ? ? ? ? ? ? ? ? at java.lang.reflect.Method.invoke(Native Method)?
? ? ? ? ? ? ? ? ? ? ? at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:945)?
? ? ? ? ? ? ? ? ? ? ? at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:806)?
I/Process: Sending signal. PID: 18526 SIG: 9
Disconnected from the target VM, address: 'localhost:8604', transport: 'socket'
問題在代碼new的問題。
WifiReceiver.java
WlanListActivity.java
WlanListPresenter.java
問題是:
廣播new出來的WlanListPresenter對象,activity頁面new出來的WlanListPresenter對象不是同一個,WlanListPresenter構造方法構造的頁面不是new了WlanListPresenter對象的Activity頁面。
所以報 has extras,它們是外部的,沒有各自的聯系。
解決方法:
廣播作為頁面Activity的內部類
WlanListPresenter構造方法傳入new WlanListPresenter的Activity