java.lang.RuntimeException: Error receiving broadcast Intent { act=android.net.wifi.SCAN_RESULTS flg


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.(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


java.lang.RuntimeException: Error receiving broadcast Intent { act=android.net.wifi.SCAN_RESULTS flg_第1张图片


WlanListActivity.java


WlanListPresenter.java



问题是:

广播new出来的WlanListPresenter对象,activity页面new出来的WlanListPresenter对象不是同一个,
WlanListPresenter构造方法构造的页面不是new了WlanListPresenter对象的Activity页面。
所以报 has extras,它们是外部的,没有各自的联系。

解决方法:
广播作为页面Activity的内部类
 
  
WlanListPresenter构造方法传入new WlanListPresenter的Activity

 
  



你可能感兴趣的:(Android开发)