0

Why does it like instantly crash and say "x keeps stopping" when BufferedReader is declared in the code?

This is the code for now (not everything):

web.setWebViewClient(new WebViewClient() {
 public void onPageFinished(WebView view, String url) {
  web.getSettings().setDomStorageEnabled(true);
  web.loadUrl("javascript: {" + 
           "document.getElementsByName('authid')[0].value = '" + ID + "';" +
           "document.getElementsByName('authpw')[0].value = '" + PASS 
           + "';" + "var submit = document.getElementsByClassName('inputbutton');" 
           + "submit[0].click(); };");
 }
});
try {
 BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
} catch (IOException e) {
 e.printStackTrace();
}

From the LogCat:

E/AndroidRuntime: FATAL EXCEPTION: main
              Process: de.kurt.vertretungsplan, PID: 4525
              java.lang.RuntimeException: Unable to start activity ComponentInfo{de.kurt.vertretungsplan/de.kurt.vertretungsplan.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'java.io.InputStream java.net.URL.openStream()' on a null object reference
                  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2665)
                  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726)
                  at android.app.ActivityThread.-wrap12(ActivityThread.java)
                  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477)
                  at android.os.Handler.dispatchMessage(Handler.java:102)
                  at android.os.Looper.loop(Looper.java:154)
                  at android.app.ActivityThread.main(ActivityThread.java:6119)
                  at java.lang.reflect.Method.invoke(Native Method)
                  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
                  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
               Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.io.InputStream java.net.URL.openStream()' on a null object reference
                  at de.kurt.vertretungsplan.MainActivity.onCreate(MainActivity.java:89)
                  at android.app.Activity.performCreate(Activity.java:6679)
                  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
                  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2618)
                  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726) 
                  at android.app.ActivityThread.-wrap12(ActivityThread.java) 
                  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477) 
                  at android.os.Handler.dispatchMessage(Handler.java:102) 
                  at android.os.Looper.loop(Looper.java:154) 
                  at android.app.ActivityThread.main(ActivityThread.java:6119) 
                  at java.lang.reflect.Method.invoke(Native Method) 
                  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886) 
                  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776) E/libEGL: validate_display:99 error 3008 (EGL_BAD_DISPLAY)

Where do you see the problem?

ρяσѕρєя K
  • 132,198
  • 53
  • 198
  • 213
quidproquo
  • 27
  • 9
  • 1
    [Use LogCat to examine the Java stack trace associated with your crashes](https://stackoverflow.com/questions/23353173/unfortunately-myapp-has-stopped-how-can-i-solve-this). You should have at least two of these: the one that is triggering the dialog that you are seeing, and [the `NetworkOnMainThreadException`](http://stackoverflow.com/questions/6343166/how-to-fix-android-os-networkonmainthreadexception) from your `try`/`catch` block (since you appear to be attempting to perform network I/O on the main application thread). – CommonsWare Jan 29 '17 at 19:38
  • I have added some text from the LogCat, thank you – quidproquo Jan 29 '17 at 19:47
  • 1
    `url` would appear to be `null`. – CommonsWare Jan 29 '17 at 19:49
  • it doesn't work like this too: try { URL url = new URL("http://google.de"); BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream())); } catch (IOException e) { e.printStackTrace(); } – quidproquo Jan 29 '17 at 20:07
  • Most likely, you have a different Java stack trace now. – CommonsWare Jan 29 '17 at 20:33

0 Answers0