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 9036799
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T09:05:17+00:00 2026-06-16T09:05:17+00:00

I’ve been following the Android tutorials and created MyFirstApp (see http://developer.android.com/training/basics/firstapp/index.html ) and I

  • 0

I’ve been following the Android tutorials and created MyFirstApp (see http://developer.android.com/training/basics/firstapp/index.html) and I can launch the app ok on the emulator, but upon entering a message and hitting “send” I get an IllegalStateException caused by a NullPointerException at this line in the below code:

String message = editText.getText().toString();

Upon debugging, it is clear that editText is null at this point, but I cannot see why, or anything I’ve missed in the tutorial.

My MainActivity class:

package com.example.myfirstapp;

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


/**
 * <p>Main Activity class for the App</p>
 *
 * @author - thebloodguy
 */
public class MainActivity extends Activity {

    //~ ----------------------------------------------------------------------------------------------------------------
    //~ Static fields/initializers 
    //~ ----------------------------------------------------------------------------------------------------------------

    /** Key to the extra message data in the sendMessage intent */
    public static final String EXTRA_MESSAGE = "com.example.myfirstapp.MESSAGE";

    //~ ----------------------------------------------------------------------------------------------------------------
    //~ Methods 
    //~ ----------------------------------------------------------------------------------------------------------------

    /**
     * {@inheritDoc}
     */
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        /* Inflate the menu; this adds items to the action bar if it is present */
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }

    /**
     * <p>Send a message using the data in the {@link View}</p>
     *
     * @param view - the {@link View} object representing the state of the view when the message is sent
     */
    public void sendMessage(View view) {
        Intent intent = new Intent(this, DisplayMessageActivity.class);
        EditText editText = (EditText) view.findViewById(R.id.edit_message);
        String message = editText.getText().toString(); // This is the guilty line
        intent.putExtra(EXTRA_MESSAGE, message);
        startActivity(intent);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

}

My activity_main.xml:

<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"
    tools:context=".MainActivity"
    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 the LogCat output:

12-21 10:02:32.210: E/Trace(621): error opening trace file: No such file or directory (2)
12-21 10:02:32.250: W/ActivityThread(621): Application com.example.myfirstapp is waiting for the debugger on port 8100...
12-21 10:02:32.270: I/System.out(621): Sending WAIT chunk
12-21 10:02:32.280: I/dalvikvm(621): Debugger is active
12-21 10:02:32.480: I/System.out(621): Debugger has connected
12-21 10:02:32.480: I/System.out(621): waiting for debugger to settle...
12-21 10:02:32.680: I/System.out(621): waiting for debugger to settle...
12-21 10:02:32.889: I/System.out(621): waiting for debugger to settle...
12-21 10:02:33.091: I/System.out(621): waiting for debugger to settle...
12-21 10:02:33.290: I/System.out(621): waiting for debugger to settle...
12-21 10:02:33.534: I/System.out(621): waiting for debugger to settle...
12-21 10:02:33.796: I/System.out(621): waiting for debugger to settle...
12-21 10:02:33.990: I/System.out(621): waiting for debugger to settle...
12-21 10:02:34.204: I/System.out(621): debugger has settled (1353)
12-21 10:02:35.429: D/gralloc_goldfish(621): Emulator without GPU emulation detected.
12-21 10:05:11.510: I/Choreographer(621): Skipped 94 frames!  The application may be doing too much work on its main thread.
12-21 10:05:13.850: I/Choreographer(621): Skipped 35 frames!  The application may be doing too much work on its main thread.
12-21 10:05:15.571: I/Choreographer(621): Skipped 38 frames!  The application may be doing too much work on its main thread.
12-21 10:06:53.724: D/AndroidRuntime(621): Shutting down VM
12-21 10:06:53.724: W/dalvikvm(621): threadid=1: thread exiting with uncaught exception (group=0x40a13300)
12-21 10:06:53.840: E/AndroidRuntime(621): FATAL EXCEPTION: main
12-21 10:06:53.840: E/AndroidRuntime(621): java.lang.IllegalStateException: Could not execute method of the activity
12-21 10:06:53.840: E/AndroidRuntime(621):  at android.view.View$1.onClick(View.java:3591)
12-21 10:06:53.840: E/AndroidRuntime(621):  at android.view.View.performClick(View.java:4084)
12-21 10:06:53.840: E/AndroidRuntime(621):  at android.view.View$PerformClick.run(View.java:16966)
12-21 10:06:53.840: E/AndroidRuntime(621):  at android.os.Handler.handleCallback(Handler.java:615)
12-21 10:06:53.840: E/AndroidRuntime(621):  at android.os.Handler.dispatchMessage(Handler.java:92)
12-21 10:06:53.840: E/AndroidRuntime(621):  at android.os.Looper.loop(Looper.java:137)
12-21 10:06:53.840: E/AndroidRuntime(621):  at android.app.ActivityThread.main(ActivityThread.java:4745)
12-21 10:06:53.840: E/AndroidRuntime(621):  at java.lang.reflect.Method.invokeNative(Native Method)
12-21 10:06:53.840: E/AndroidRuntime(621):  at java.lang.reflect.Method.invoke(Method.java:511)
12-21 10:06:53.840: E/AndroidRuntime(621):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
12-21 10:06:53.840: E/AndroidRuntime(621):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
12-21 10:06:53.840: E/AndroidRuntime(621):  at dalvik.system.NativeStart.main(Native Method)
12-21 10:06:53.840: E/AndroidRuntime(621): Caused by: java.lang.reflect.InvocationTargetException
12-21 10:06:53.840: E/AndroidRuntime(621):  at java.lang.reflect.Method.invokeNative(Native Method)
12-21 10:06:53.840: E/AndroidRuntime(621):  at java.lang.reflect.Method.invoke(Method.java:511)
12-21 10:06:53.840: E/AndroidRuntime(621):  at android.view.View$1.onClick(View.java:3586)
12-21 10:06:53.840: E/AndroidRuntime(621):  ... 11 more
12-21 10:06:53.840: E/AndroidRuntime(621): Caused by: java.lang.NullPointerException
12-21 10:06:53.840: E/AndroidRuntime(621):  at com.example.myfirstapp.MainActivity.sendMessage(MainActivity.java:61)
12-21 10:06:53.840: E/AndroidRuntime(621):  ... 14 more
  • 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-16T09:05:18+00:00Added an answer on June 16, 2026 at 9:05 am

    Change this line

    EditText editText = (EditText) view.findViewById(R.id.edit_message);
    

    to

    EditText editText = (EditText)findViewById(R.id.edit_message);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm not entirely sure how I managed to jack this up. http://pretty-senshi.com If you
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have been unable to fix a problem with Java Unicode and encoding. The
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have an MVC Razor view @{ ViewBag.Title = Index; var c = (char)146;

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.