一直苦苦挣扎一周
我有两个类WiFiScanReceiver,它扩展了BroadcastReceiver,WiFiNewClass扩展了Service。 WifiScanReceiver运行WifiNewclass作为服务。 WifiNewclass具有以下代码
public class WiFiNewClass extends Service{
private static final String TAG = "WiFiScanReceiver";
private static final Object IMEI = null;
private static final Object VER = null;
Wifiscan wifiDemo;
TelephonyManager Tel;
PhoneStateListener MyListener;
public WiFiNewClass(Wifiscan wifiDemo) {
super();
this.wifiDemo = wifiDemo;
}
public void test(){
wifiDemo = new Wifiscan();
////some other code
}
@Override
public IBinder onBind(Intent arg0) {
// TODO Auto-generated method stub
return null;
}
public void onCreate(){
test();
this.stopSelf();
}
}
当我运行此代码时,我收到以下错误。任何人都可以帮帮我。提前致谢
06-08 18:50:07.014: ERROR/AndroidRuntime(3199): java.lang.RuntimeException: Unable to instantiate service org.wifi.WiFiNewClass: java.lang.InstantiationException: org.wifi.WiFiNewClass
06-08 18:50:07.014: ERROR/AndroidRuntime(3199): at android.app.ActivityThread.handleCreateService(ActivityThread.java:2764)
06-08 18:50:07.014: ERROR/AndroidRuntime(3199): at android.app.ActivityThread.access$3200(ActivityThread.java:119)
06-08 18:50:07.014: ERROR/AndroidRuntime(3199): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1917)
06-08 18:50:07.014: ERROR/AndroidRuntime(3199): at android.os.Handler.dispatchMessage(Handler.java:99)
06-08 18:50:07.014: ERROR/AndroidRuntime(3199): at android.os.Looper.loop(Looper.java:123)
06-08 18:50:07.014: ERROR/AndroidRuntime(3199): at android.app.ActivityThread.main(ActivityThread.java:4363)
06-08 18:50:07.014: ERROR/AndroidRuntime(3199): at java.lang.reflect.Method.invokeNative(Native Method)
06-08 18:50:07.014: ERROR/AndroidRuntime(3199): at java.lang.reflect.Method.invoke(Method.java:521)
06-08 18:50:07.014: ERROR/AndroidRuntime(3199): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:862)
06-08 18:50:07.014: ERROR/AndroidRuntime(3199): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:620)
06-08 18:50:07.014: ERROR/AndroidRuntime(3199): at dalvik.system.NativeStart.main(Native Method)
06-08 18:50:07.014: ERROR/AndroidRuntime(3199): Caused by: java.lang.InstantiationException: org.wifi.WiFiNewClass
06-08 18:50:07.014: ERROR/AndroidRuntime(3199): at java.lang.Class.newInstanceImpl(Native Method)
06-08 18:50:07.014: ERROR/AndroidRuntime(3199): at java.lang.Class.newInstance(Class.java:1479)
06-08 18:50:07.014: ERROR/AndroidRuntime(3199): at android.app.ActivityThread.handleCreateService(ActivityThread.java:2761)
答案 0 :(得分:1)
我认为你的问题是你的构造函数:
public WiFiNewClass(Wifiscan wifiDemo) {
super();
this.wifiDemo = wifiDemo;
}
框架如何在Wifiscan
对象中传递?尝试删除它,然后查看它是否启动。