我正在制作一个使用互联网连接的应用程序。当我尝试下载数据,但没有互联网连接应用程序强制关闭。如果我希望应用程序不抛出强制关闭消息,而是我自己的消息,例如“没有连接......”,然后关闭活动,我需要做什么。谢谢!
我的 logcat 输出:
09-23 14:56:15.411: E/AndroidRuntime(20770): FATAL EXCEPTION: main
09-23 14:56:15.411: E/AndroidRuntime(20770): java.lang.RuntimeException: Unable to start activity ComponentInfo{lt.prasom/lt.prasom.GoodOffers}: java.lang.NullPointerException
09-23 14:56:15.411: E/AndroidRuntime(20770): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
09-23 14:56:15.411: E/AndroidRuntime(20770): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
09-23 14:56:15.411: E/AndroidRuntime(20770): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
09-23 14:56:15.411: E/AndroidRuntime(20770): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
09-23 14:56:15.411: E/AndroidRuntime(20770): at android.os.Handler.dispatchMessage(Handler.java:99)
09-23 14:56:15.411: E/AndroidRuntime(20770): at android.os.Looper.loop(Looper.java:130)
09-23 14:56:15.411: E/AndroidRuntime(20770): at android.app.ActivityThread.main(ActivityThread.java:3683)
09-23 14:56:15.411: E/AndroidRuntime(20770): at java.lang.reflect.Method.invokeNative(Native Method)
09-23 14:56:15.411: E/AndroidRuntime(20770): at java.lang.reflect.Method.invoke(Method.java:507)
09-23 14:56:15.411: E/AndroidRuntime(20770): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
09-23 14:56:15.411: E/AndroidRuntime(20770): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
09-23 14:56:15.411: E/AndroidRuntime(20770): at dalvik.system.NativeStart.main(Native Method)
09-23 14:56:15.411: E/AndroidRuntime(20770): Caused by: java.lang.NullPointerException
09-23 14:56:15.411: E/AndroidRuntime(20770): at java.io.StringReader.<init>(StringReader.java:46)
09-23 14:56:15.411: E/AndroidRuntime(20770): at lt.prasom.functions.XMLParser.getDomElement(XMLParser.java:73)
09-23 14:56:15.411: E/AndroidRuntime(20770): at lt.prasom.GoodOffers.onCreate(GoodOffers.java:68)
09-23 14:56:15.411: E/AndroidRuntime(20770): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
09-23 14:56:15.411: E/AndroidRuntime(20770): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
09-23 14:56:15.411: E/AndroidRuntime(20770): ... 11 more