I have used a webview named Testview
to load html data in the webview. for that I am using the following code.
Testview.loadData("<html><body>helloindia</body></html>", "text/html", "utf-8");
I have given <uses-permission android:name="android.permission.INTERNET" />
in the manifest. But this above loine of code is generating NullPointerException
. Can anyone point out the problem in my code?
As @m0s pointed in comment: make sure Textview is initialized:
Also, it is a Java custom to write class names with first letter capitalized (WebView) and instances with first letter in lower-case (textview), so that they are easily distinguished.
Update:
If this line returns null:
then you most probably forgot to call:
in your
activity.onCreate()
method. The javadoc of findViewById(int) says:That's what
setContentView()
does (processes the layout XML):