Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8503889
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T01:52:44+00:00 2026-06-11T01:52:44+00:00

I am trying to create my first android+html 5 application.. My Activity code is

  • 0

I am trying to create my first android+html 5 application..
My Activity code is :

import android.os.Bundle;
import android.app.Activity;
import android.webkit.WebView;


public class MainActivity extends Activity {

    WebView webView;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        webView = new WebView(this);        
        String summary = "<html><body>HTML 5 Test</body></html>";
        webView = (WebView)findViewById(R.id.webView);
        webView.loadData( summary, "text/html; character=UTF-8", null);        
        setContentView(webView);
    }
}

When I run above code, It gives Null Pointer Exception…

09-08 09:27:21.393: D/AndroidRuntime(562): Shutting down VM
09-08 09:27:21.393: W/dalvikvm(562): threadid=1: thread exiting with uncaught exception (group=0x409c01f8)
09-08 09:27:21.530: E/AndroidRuntime(562): FATAL EXCEPTION: main
09-08 09:27:21.530: E/AndroidRuntime(562): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.rightquery.test/com.rightquery.test.MainActivity}: java.lang.NullPointerException
09-08 09:27:21.530: E/AndroidRuntime(562):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956)
09-08 09:27:21.530: E/AndroidRuntime(562):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
09-08 09:27:21.530: E/AndroidRuntime(562):  at android.app.ActivityThread.access$600(ActivityThread.java:123)
09-08 09:27:21.530: E/AndroidRuntime(562):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
09-08 09:27:21.530: E/AndroidRuntime(562):  at android.os.Handler.dispatchMessage(Handler.java:99)
09-08 09:27:21.530: E/AndroidRuntime(562):  at android.os.Looper.loop(Looper.java:137)
09-08 09:27:21.530: E/AndroidRuntime(562):  at android.app.ActivityThread.main(ActivityThread.java:4424)
09-08 09:27:21.530: E/AndroidRuntime(562):  at java.lang.reflect.Method.invokeNative(Native Method)
09-08 09:27:21.530: E/AndroidRuntime(562):  at java.lang.reflect.Method.invoke(Method.java:511)
09-08 09:27:21.530: E/AndroidRuntime(562):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
09-08 09:27:21.530: E/AndroidRuntime(562):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
09-08 09:27:21.530: E/AndroidRuntime(562):  at dalvik.system.NativeStart.main(Native Method)
09-08 09:27:21.530: E/AndroidRuntime(562): Caused by: java.lang.NullPointerException
09-08 09:27:21.530: E/AndroidRuntime(562):  at com.rightquery.test.MainActivity.onCreate(MainActivity.java:19)
09-08 09:27:21.530: E/AndroidRuntime(562):  at android.app.Activity.performCreate(Activity.java:4465)
09-08 09:27:21.530: E/AndroidRuntime(562):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
09-08 09:27:21.530: E/AndroidRuntime(562):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
09-08 09:27:21.530: E/AndroidRuntime(562):  ... 11 more

EDIT: Layout

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"    
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <WebView
        android:id="@+id/webView"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:layout_marginBottom="2dp"
        android:layout_marginLeft="2dp" />

</RelativeLayout>

What is wrong ?

The Solution:

import android.os.Bundle;
import android.app.Activity;
import android.webkit.WebView;


public class MainActivity extends Activity {

    WebView webView;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        webView = new WebView(this); 
        setContentView(R.layout.main);
        String summary = "<html><body>HTML 5 Test</body></html>";

        webView = new WebView(this);
        webView.loadData( summary, "text/html; character=UTF-8", null);        
        setContentView(webView);
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T01:52:45+00:00Added an answer on June 11, 2026 at 1:52 am

    You need to do setContentView(R.layout.youView); before calling

    webView = (WebView)findViewById(R.id.webView);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create a setup activity for my Android application which my users
I am trying to create my first Android app and need some help. Basically
I am trying to create an Activity for an Android app with two imageViews
I'm trying to create a simple list application for my first app. I have
I am trying to create my first Android app. I am using Eclipse. I
This is my first android project so please help I am trying to create
I'm trying to create my first app with AngularJS. It looks neat, but there's
I am trying to create my first GUI application using (Java + Eclipse +
I'm trying to create an app (my first) that generates invoices for me. Originally
I am trying to develop my first Android app through the ADT plugins for

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.