Error using a WebView, NullPointerException

1

Good I have a problem when doing my WebView.

 05-02 23:38:11.239 29315-29315/srf.lec.noctambuloss E/AndroidRuntime: FATAL 
 EXCEPTION: main
                                                                  Process: 
 srf.lec.noctambuloss, PID: 29315

 java.lang.RuntimeException: Unable to start activity ComponentInfo{srf.lec.noctambuloss/srf.lec.noctambuloss.Boliches}: java.lang.NullPointerException
                                                                      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2429)
                                                                      at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2493)
                                                                      at android.app.ActivityThread.access$800(ActivityThread.java:166)
                                                                      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1283)
                                                                      at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                      at android.os.Looper.loop(Looper.java:136)
                                                                      at android.app.ActivityThread.main(ActivityThread.java:5584)
                                                                      at java.lang.reflect.Method.invokeNative(Native Method)
                                                                      at java.lang.reflect.Method.invoke(Method.java:515)
                                                                      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1268)
                                                                      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1084)
                                                                      at dalvik.system.NativeStart.main(Native Method)
                                                                   Caused by: java.lang.NullPointerException
                                                                      at srf.lec.noctambuloss.Boliches.onCreate(Boliches.java:22)
                                                                      at android.app.Activity.performCreate(Activity.java:5447)
                                                                      at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094)
                                                                      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2393)
                                                                      at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2493) 
                                                                      at android.app.ActivityThread.access$800(ActivityThread.java:166) 
                                                                      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1283) 
                                                                      at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                                      at android.os.Looper.loop(Looper.java:136) 
                                                                      at android.app.ActivityThread.main(ActivityThread.java:5584) 
                                                                      at java.lang.reflect.Method.invokeNative(Native Method) 
                                                                      at java.lang.reflect.Method.invoke(Method.java:515) 
                                                                      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1268) 
                                                                      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1084) 
                                                                      at dalvik.system.NativeStart.main(Native Method) 

My activity is boliches:

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_boliches);
        WebView view = (WebView) this.findViewById(R.id.Visorboliches);
        view.setWebViewClient(new WebViewClient());
        String url = "asdasd645546546";
        view.loadUrl(url);
        view.getSettings().setJavaScriptEnabled(true);


    }

}
    
asked by Emiliano Rigobello 03.05.2017 в 04:42
source

1 answer

1

Check that you actually have a WebView with id Visorboliches within the layout activity_boliches.xml , if it does not exist, the instance of the WebView (view) has a null value:

  WebView view = (WebView) this.findViewById(R.id.Visorboliches);
  view.setWebViewClient(new WebViewClient());
    
answered by 03.05.2017 в 17:33