문제

public class WypadekInformacjeActivity extends Activity {
    TextView tv1;

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.wypadek);

        WebView webView = (WebView) findViewById(R.id.webView);
//        webView.setScrollBarStyle(WebView.SCROLLBARS_INSIDE_OVERLAY);

        webView.setBackgroundColor(0);
        LoadText lt = new LoadText();
        String html = lt.load(R.raw.wypadek, this);

        webView.loadDataWithBaseURL(null, html, "text/html", "UTF-8", null);

        Pattern pattern = Pattern.compile("\\d{3}?");

        tv1 = (TextView) findViewById(R.id.textView1);
        tv1.setAutoLinkMask(0);
//        Linkify.addLinks(tv1, pattern, "tel: ");
//        tv1.setAutoLinkMask(Linkify.PHONE_NUMBERS);
    }
}

ERROR/AndroidRuntime(28184): FATAL EXCEPTION: main

...

Caused by: java.lang.NullPointerException at com.example.swubezpieczenia.WypadekInformacjeActivity.onCreate(WypadekInformacjeActivity.java:29)

It happens when when I try to setAutoLinkMask(0). This is line 29: "tv1.setAutoLinkMask(0);". When I comment this line there is no exception.

도움이 되었습니까?

해결책

Looks like your text view does not exist. try wrapping line 29 with an 'if' statement such as this:

if(tv1 != null){
   //original line 29 goes here
}

and run it again. The exception shouldn't happen this time. If it indeed does not happen, I think your best bet would be to recheck the name of your text view, make sure it exits in the same layout xml you are sending to setContentView().

다른 팁

You are referring to an undeterminated index "0", use Linkify to refer to a valid index

Example:

tv1.setAutoLinkMask(Linkify.ALL);
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top