0

So the error is

06-30 11:51:08.690: E/AndroidRuntime(1105): Caused by:
java.lang.NullPointerException
06-30 11:51:08.690: E/AndroidRuntime(1105):     
at com.bd.krowd.MainActivity.onCreate(MainActivity.java:54)

And my code here is:`

String url ="http://themeforest.net/item/forum-website-html-template/full_screen_preview/7968760";
    WebView view=(WebView) this.findViewById(R.id.webView1);
    view.getSettings().setJavaScriptEnabled(true);
    view.loadUrl(url);

Line 54 is

view.getSettings().setJavaScriptEnabled(true);

So what must be done?

9
  • 1
    do you have a webview with id webView1 in your xml ? Commented Jun 30, 2015 at 11:58
  • Is R.id.webView1 in the current layout? Commented Jun 30, 2015 at 11:59
  • can you post your layout file? Commented Jun 30, 2015 at 11:59
  • 1
    view is probably null. Is the layout set correctly before calling findViewById? Commented Jun 30, 2015 at 12:00
  • pastebin.com/BMfhRW8u Commented Jun 30, 2015 at 12:01

2 Answers 2

1

Something must be null! webview or the WebSettings object returned by getSettings().

WebView view=(WebView) findViewById(R.id.webView1);

view can be null if R.id.webView1 cannot be found

have you called :

setContentView(R.layout.yourWebviewLayout);

before in your oncreate??

Sign up to request clarification or add additional context in comments.

Comments

1

if ur webview is in activity... change the code as below...

String url ="http://themeforest.net/item/forum-website-html-template/full_screen_preview/7968760";
WebView view=(WebView) findViewById(R.id.webView1);
view.getSettings().setJavaScriptEnabled(true);
view.loadUrl(url);

call on create before adding this snippet..

1 Comment

That's what I wrote haha.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.