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

  • Home
  • SEARCH
  • 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 8460813
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T13:42:38+00:00 2026-06-10T13:42:38+00:00

I am trying to modify the Android tutorial ( http://developer.android.com/training/basics/firstapp/index.html ) so that instead

  • 0

I am trying to modify the Android tutorial (http://developer.android.com/training/basics/firstapp/index.html) so that instead of displaying the text the user enters the app will load the url they typed and display it in a WebView.

Here is my catlog …

    D/dalvikvm(  401): GC_CONCURRENT freed 431K, 6% free 9693K/10311K, paused 474ms+125ms, total 7912ms
    D/myfirstapp_tag( 1090): Main Line 23
    D/myfirstapp_tag( 1090): Main Line 26
    D/myfirstapp_tag( 1090): Main Line 28
    D/myfirstapp_tag( 1090): Main Line 30
    D/myfirstapp_tag( 1090): Main Line 32
    I/ActivityManager(  150): START {cmp=com.example.myfirstapp/.DisplayMessageActivity (has extras) u=0} from pid 1090
    W/WindowManager(  150): Failure taking screenshot for (246x410) to layer 21015
    I/Choreographer( 1090): Skipped 137 frames!  The application may be doing too much work on its main thread.
    D/myfirstapp_tag( 1090): Line 14
    D/myfirstapp_tag( 1090): Line 16
    D/myfirstapp_tag( 1090): Line 20
    D/myfirstapp_tag( 1090): Line 22
    D/myfirstapp_tag( 1090): Line 32
    D/myfirstapp_tag( 1090): Line 34
    D/AndroidRuntime( 1090): Shutting down VM
    W/dalvikvm( 1090): threadid=1: thread exiting with uncaught exception (group=0x40a13300)
    E/AndroidRuntime( 1090): FATAL EXCEPTION: main
    E/AndroidRuntime( 1090): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.myfirstapp/com.example                                  .myfirstapp.DisplayMessageActivity}: java.lang.NullPointerException
    E/AndroidRuntime( 1090):        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
    E/AndroidRuntime( 1090):        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
    E/AndroidRuntime( 1090):        at android.app.ActivityThread.access$600(ActivityThread.java:130)
    E/AndroidRuntime( 1090):        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
    E/AndroidRuntime( 1090):        at android.os.Handler.dispatchMessage(Handler.java:99)
    E/AndroidRuntime( 1090):        at android.os.Looper.loop(Looper.java:137)
    E/AndroidRuntime( 1090):        at android.app.ActivityThread.main(ActivityThread.java:4745)
    E/AndroidRuntime( 1090):        at java.lang.reflect.Method.invokeNative(Native Method)
    E/AndroidRuntime( 1090):        at java.lang.reflect.Method.invoke(Method.java:511)
    E/AndroidRuntime( 1090):        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
    E/AndroidRuntime( 1090):        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
    E/AndroidRuntime( 1090):        at dalvik.system.NativeStart.main(Native Method)
    E/AndroidRuntime( 1090): Caused by: java.lang.NullPointerException
    E/AndroidRuntime( 1090):        at com.example.myfirstapp.DisplayMessageActivity.onCreate(DisplayMessageActivity.java:36)
    E/AndroidRuntime( 1090):        at android.app.Activity.performCreate(Activity.java:5008)
    E/AndroidRuntime( 1090):        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
    E/AndroidRuntime( 1090):        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
    E/AndroidRuntime( 1090):        ... 11 more
    W/ActivityManager(  150):   Force finishing activity com.example.myfirstapp/.DisplayMessageActivity
    W/ActivityManager(  150):   Force finishing activity com.example.myfirstapp/.MainActivity
    W/ActivityManager(  150): Activity pause timeout for ActivityRecord{415e1cc8 com.example.myfirstapp/.DisplayMessageActivity}

I doing this the command-line way on ubuntu so here’s my ./AndroidManifest.xml

    <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
            package="com.example.myfirstapp"
            android:versionCode="1"
            android:versionName="1.0">
            <uses-permission android:name="android.permission.INTERNET" />
            <application android:label="@string/app_name" android:icon="@drawable/ic_launcher">
              <activity android:name="MainActivity" android:label="@string/app_name">
                <intent-filter>
                 <action android:name="android.intent.action.MAIN" />
                 <category android:name="android.intent.category.LAUNCHER" />
                </intent-filter>
              </activity>
              <activity     android:name=".DisplayMessageActivity" android:label="@string/title_activity_display_message" >
                <meta-data  android:name="android.support.PARENT_ACTIVITY" android:value="com.example.myfirstapp.MainActivity" />
              </activity>
            </application>
    </manifest>

Here’s my res/layout/main.xml …

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
            xmlns:tools="http://schemas.android.com/tools"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="horizontal">
              <EditText android:id="@+id/edit_message"
                android:layout_weight="1"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:hint="@string/edit_message" />
              <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/button_send"
                android:onClick="sendMessage" />
    </LinearLayout>

… and my res/layout/webview.xml file:

    <?xml version="1.0" encoding="utf-8"?>
    <WebView  xmlns:android="http://schemas.android.com/apk/res/android"
            android:id="@+id/webview"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
    />

I have two source files. This one src/com/example/myfirstapp/MainActivity.java

    package com.example.myfirstapp;

    import android.app.Activity;
    import android.view.View;
    import android.content.Intent;
    import android.os.Bundle;
    import android.widget.EditText;
    import android.util.Log;

    public class MainActivity extends Activity {
            public final static String EXTRA_MESSAGE = "com.example.myfirstapp.MESSAGE";

            /** Called when the activity is first created. */
            @Override
            public void onCreate(Bundle savedInstanceState) {
    Log.d ("myfirstapp_tag", "Main Line 15" );
              super.onCreate(savedInstanceState);
    Log.d ("myfirstapp_tag", "Main Line 17" );
              setContentView(R.layout.main);
    Log.d ("myfirstapp_tag", "Main Line 19" );
            }
            /** Called when the user clicks the Send button */
            public void sendMessage(View view) {
    Log.d ("myfirstapp_tag", "Main Line 23" );
              // Do something in response to button
              Intent intent = new Intent(this, com.example.myfirstapp.DisplayMessageActivity.class);
    Log.d ("myfirstapp_tag", "Main Line 26" );
              EditText editText = (EditText) findViewById(R.id.edit_message);
    Log.d ("myfirstapp_tag", "Main Line 28" );
              String message = editText.getText().toString();
    Log.d ("myfirstapp_tag", "Main Line 30" );
              intent.putExtra(EXTRA_MESSAGE, message);
    Log.d ("myfirstapp_tag", "Main Line 32" );
              startActivity(intent);
            }
    }

and this one … src/com/example/myfirstapp/DisplayMessageActivity.java

    package com.example.myfirstapp;
    import android.app.Activity;
    import android.content.Intent;
    import android.widget.TextView;
    import android.view.View;
    import android.webkit.WebView;
    import android.os.Bundle;
    import android.util.Log;


    public class DisplayMessageActivity extends Activity {
            @Override
            public void onCreate(Bundle savedInstanceState) {
    Log.d ("myfirstapp_tag", "Line 14" );
              super.onCreate(savedInstanceState);
    Log.d ("myfirstapp_tag", "Line 16" );

              // Get the message from the intent
              Intent intent = getIntent();
    Log.d ("myfirstapp_tag", "Line 20" );
              String message = intent.getStringExtra(com.example.myfirstapp.MainActivity.EXTRA_MESSAGE);
    Log.d ("myfirstapp_tag", "Line 22" );

              // Create the text view
    //        TextView textView = new TextView(this);
    //        textView.setTextSize(40);
    //        textView.setText(message);

              // Set the text view as the activity layout
    //        setContentView(textView);
              //WebView webView = new WebView(this); //WebView myWebView = (WebView) findViewById(R.id.webview);
    Log.d ("myfirstapp_tag", "Line 32" );
              WebView webView = (WebView) findViewById(R.id.webview); //webView = (WebView) findViewById(R.id.webview);
    Log.d ("myfirstapp_tag", "Line 34" );
              //setContentView(webView);
              webView.loadUrl(message);
    Log.d ("myfirstapp_tag", "Line 37" );
              setContentView(webView);
    Log.d ("myfirstapp_tag", "Line 39" );
            }
    }

I can see from the catlog that the line …

    WebView webView = (WebView) findViewById(R.id.webview);

… is where my app is dying. I just don’t understand why. Can someone help me out 🙂

  • 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-10T13:42:40+00:00Added an answer on June 10, 2026 at 1:42 pm

    You have to call setContentView(R.layout.xmlfile); before calling this line,

     WebView webView = (WebView) findViewById(R.id.webview);
    

    This is because you are trying to refer to a resource which you have allocated in a xml file.

    But Android can’t find the resource without mapping it to the xml file.

    So only when you call the setContentView with your xml file, andorid will try to look into that particular xml file for a WebView with the ID you have specified in the findViewByID(). if not it will return NPException definitely.

    Or if you don’t want to use a xml allocated resource do this,

    WebView webView = new WebView(this);
     webView.loadUrl(message);
     setContentView(webView);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to modify this example: http://developer.android.com/resources/tutorials/views/hello-gridview.html But instead of displaying images that
I am trying to modify the NotePad sample code from the Android developer resources.
I've followed the Android tutorial for TabLayout , and I'm now trying to modify
I am trying to modify the android lvl library and as part of this
I am trying to modify the script below to click a button that looks
I'm trying to use this tutorial on Restlet for Android, and can't get the
In android, I'm trying to create an simple activity allowing me to modify a
I'm trying to make an Android application that will display a map of a
In android, I am trying to implement an application that can play videos. In
I'm currently trying to modify Android 2.2 froyo Home app. To begin, I must

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.