html - Android webview loaddata giving NullPointerException -


i have used webview named testview load html data in webview. using following code.

testview.loaddata("<html><body>helloindia</body></html>", "text/html", "utf-8");

i have given <uses-permission android:name="android.permission.internet" /> in manifest. above loine of code generating nullpointerexception. can point out problem in code?

as @m0s pointed in comment: make sure textview is initialized:

textview = new webview(this);  // used inside activity 

also, java custom write class names first letter capitalized (webview) , instances first letter in lower-case (textview), distinguished.

update:

if line returns null:

textview = (webview)this.findviewbyid(r.id.testview) 

then forgot call:

setcontentview(r.layout.main); 

in activity.oncreate() method. javadoc of findviewbyid(int) says:

finds view identified id attribute xml  processed in oncreate(bundle). 

that's setcontentview() (processes layout xml):

set activity content layout resource. resource inflated, adding top-level views activity. 

Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -