0

this NullPointerException i am getting makes no sense to me. I have a webview that was just working fine for a long time and now it is showing null for no reason i can see.

public class SmsMain extends Activity {

@Override
public void onCreate(Bundle savedInstanceState){
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    WebView browser = (WebView) findViewById(R.id.webView2); //debugger says browser is null
    browser.loadUrl("file:///android_asset/smsabout.html"); //error is here 
}

xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_height="fill_parent" android:layout_width="match_parent">

    <WebView android:id="@+id/webView2" 
    android:layout_height="fill_parent" 
    android:layout_width="fill_parent"></WebView>

</LinearLayout>

as you can see it is defined properly and referenced properly but browser is null when i trace it in the debugger. It cant be the html file because i know its there and i didnt change anything with it. so why is it giving me this?

1 Answer 1

1

I assume your XML is located in a res/layout* directory appropriate for your current device configuration. Might want to clean and rebuild to make sure the Android resources are in sync with your code.

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

Comments

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.