我想知道我在启动我的应用程序时是否有移动网络:
final ConnectivityManager connMgr = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
final android.net.NetworkInfo mobileInfo = connMgr.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
在我的开始应用程序类中:
public class StartApplication extends Application {
我遇到了一些错误:
04-23 14:41:36.683: E/AndroidRuntime(1280): FATAL EXCEPTION: main
04-23 14:41:36.683: E/AndroidRuntime(1280): java.lang.RuntimeException: Unable to instantiate application com.chipsat.sigue.StartApplication: java.lang.NullPointerException
04-23 14:41:36.683: E/AndroidRuntime(1280): at android.app.LoadedApk.makeApplication(LoadedApk.java:504)
04-23 14:41:36.683: E/AndroidRuntime(1280): at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4364)
04-23 14:41:36.683: E/AndroidRuntime(1280): at android.app.ActivityThread.access$1300(ActivityThread.java:141)
04-23 14:41:36.683: E/AndroidRuntime(1280): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1294)
04-23 14:41:36.683: E/AndroidRuntime(1280): at android.os.Handler.dispatchMessage(Handler.java:99)
04-23 14:41:36.683: E/AndroidRuntime(1280): at android.os.Looper.loop(Looper.java:137)
04-23 14:41:36.683: E/AndroidRuntime(1280): at android.app.ActivityThread.main(ActivityThread.java:5041)
04-23 14:41:36.683: E/AndroidRuntime(1280): at java.lang.reflect.Method.invokeNative(Native Method)
04-23 14:41:36.683: E/AndroidRuntime(1280): at java.lang.reflect.Method.invoke(Method.java:511)
04-23 14:41:36.683: E/AndroidRuntime(1280): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
04-23 14:41:36.683: E/AndroidRuntime(1280): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
04-23 14:41:36.683: E/AndroidRuntime(1280): at dalvik.system.NativeStart.main(Native Method)
04-23 14:41:36.683: E/AndroidRuntime(1280): Caused by: java.lang.NullPointerException
04-23 14:41:36.683: E/AndroidRuntime(1280): at android.content.ContextWrapper.getSystemService(ContextWrapper.java:495)
04-23 14:41:36.683: E/AndroidRuntime(1280): at com.chipsat.sigue.StartApplication.<init>(StartApplication.java:82)
04-23 14:41:36.683: E/AndroidRuntime(1280): at java.lang.Class.newInstanceImpl(Native Method)
04-23 14:41:36.683: E/AndroidRuntime(1280): at java.lang.Class.newInstance(Class.java:1319)
04-23 14:41:36.683: E/AndroidRuntime(1280): at android.app.Instrumentation.newApplication(Instrumentation.java:983)
04-23 14:41:36.683: E/AndroidRuntime(1280): at android.app.Instrumentation.newApplication(Instrumentation.java:968)
04-23 14:41:36.683: E/AndroidRuntime(1280): at android.app.LoadedApk.makeApplication(LoadedApk.java:499)
04-23 14:41:36.683: E/AndroidRuntime(1280): ... 11 more