Note that there are some explanatory texts on larger screens.

plurals
  1. POIllegalStateException when click on button in android hello world program
    primarykey
    data
    text
    <p>I'm new to android and I'm trying to implement MyFirstApp given on android google developers site, So app contains one textbox and button, if you enter any text in textfield and click on button it displays same content on screen, but having problem when i clicked on send button. Please guide me how to solve this problem. </p> <p>Following exceptions:</p> <pre><code>&lt;p&gt;03-15 18:00:03.430: E/AndroidRuntime(592): FATAL EXCEPTION: main&lt;/p&gt; &lt;p&gt;03-15 18:00:03.430: E/AndroidRuntime(592): java.lang.IllegalStateException:Could not find a method MainActivity.sendMessage(View) in the activity class com.example.myfirstapp.DisplayMessageActivity for onClick handler on view class android.widget.Button&lt;/p&gt; &lt;p&gt;03-15 18:00:03.430: E/AndroidRuntime(592): at android.view.View$1.onClick(View.java:3031)&lt;/p&gt; &lt;p&gt;03-15 18:00:03.430: E/AndroidRuntime(592): at android.view.View.performClick(View.java:3511)&lt;/p&gt; </code></pre> <p>Here are two activities:<br> 1.DisplayMessageActivity this is activity mentioned in android manifest file . This implement layout part</p> <pre><code> public class DisplayMessageActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Get the message from the intent Intent intent = getIntent(); String message = intent.getStringExtra(MainActivity.EXTRA_MESSAGE); // 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); setContentView(R.layout.activity_display_message_1); } } </code></pre> <p>2.MainActivity<br> this is activity implement sendmessage function that is called when users clicked on button . </p> <pre><code> public class MainActivity extends Activity { public final static String EXTRA_MESSAGE = "com.example.myfirstapp.MESSAGE"; /** Called when the user clicks the Send button */ public void sendMessage(View view) { // Do something in response to button Intent intent = new Intent(this, DisplayMessageActivity.class); EditText editText = (EditText) findViewById(R.id.edit_message); String message = editText.getText().toString(); intent.putExtra(EXTRA_MESSAGE, message); startActivity(intent); } } </code></pre> <p>Android Manifest xml file:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.myfirstapp" android:versionCode="1" android:versionName="1.0" &gt; &lt;uses-sdk android:minSdkVersion="8" android:targetSdkVersion="11" /&gt; &lt;application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" &gt; &lt;activity android:name="DisplayMessageActivity" android:label="@string/title_activity_display_message"&gt; &lt;intent-filter &gt; &lt;action android:name="android.intent.action.MAIN" /&gt; &lt;category android:name="android.intent.category.LAUNCHER" /&gt; &lt;/intent-filter&gt; &lt;/activity&gt; &lt;/application&gt; &lt;/manifest&gt; </code></pre> <p>And Layout xml file:</p> <pre><code> &lt;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" &gt; &lt;EditText android:id="@+id/edit_message" android:layout_weight="1" android:layout_width="0dp" android:layout_height="wrap_content" android:hint="@string/edit_message" /&gt; &lt;Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/button_send" android:onClick="sendMessage"/&gt; &lt;/LinearLayout&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload