• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Crash on no internet connection

tomstr

Lurker
Hello,

i'm trying to make a app but when i have no internet the app crash immediately. The apps loads a XML file from the internet on the beginning but if i comment that it will crash also so that's the weird part.

Hopefully someone can help me.

I think it has something to do with my android manifest because i request there NETWORK ACCESS and i don't have it.

Greetings,
Tom
 
You should probably wrap your code (which makes http requests) in try-catch block. In case of no connection you'll catch an exception (most likely SocketTimeoutException) and handle it (maybe show some message to the user).
Your app crashes because of unandled exceptions. Look for stack traces in logcat tab.
 
That doesn't solve my problem but when i set my internet connection off, it wont even load the onCreate function with a System.out.printIn("hello"); into it.

As soon the internet is disabled it will crash.

Hopefully someone can help me out.

Tom
 
Code:
FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.mynewapp/com.example.mynewapp.MainActivity}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2171)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2295)
at android.app.ActivityThread.access$700(ActivityThread.java:150)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1280)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:175)
at android.app.ActivityThread.main(ActivityThread.java:5279)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at java.io.StringReader.<init>(StringReader.java:47)
at com.example.mynewapp.XMLParser.getDomElement(XMLParser.java:72)
at com.example.mynewapp.MainActivity.<init>(MainActivity.java:48)
at java.lang.Class.newInstanceImpl(Native Method)
at java.lang.Class.newInstance(Class.java:1319)
at android.app.Instrumentation.newActivity(Instrumentation.java:1071)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2162)
... 11 more

Getting this errors, maybe its handy to know :)
 
Do you have registered activity in manifest? In the manifest you should have line like this:
<activity android:name="com.example.mynewapp.MainActivity"/>
Also check in code if your activity is public (and not abstract)
 
Code:
<activity android:name="com.example.mynewapp.MainActivity" android:label="My New App" >

Code:
public class MainActivity extends ActionBarActivity

i think this is good ?
 
If you still have problems, posting the manifest file would help, I think something is set up wrong there because you said you're not even getting onCreate called.
 
Back
Top Bottom