My First android app crashing and clicking a button

misguided

I am learning android from official android website. It was wokring fine before when I used to eneter data in text box and click on a button aand the data used to get printed in a different screen.

But after I tried to customize the code, to add menu options. The functionality is no longer working. When I click on the button , the app crashes now. Can anyone advise where I am going wrong?

My MainActivity.java file is as below.

package com.example.myfirstapp;

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

public class MainActivity extends Activity {

    public final static String EXTRA_MESSAGE = "com.example.myfirstapp.MESSAGE";

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


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        MenuInflater inflater = getMenuInflater();  
        inflater.inflate(R.menu.main_activity_actions, menu);  
        return super.onCreateOptionsMenu(menu); 
    }

    /** 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);
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle presses on the action bar items
        switch (item.getItemId()) {
            case R.id.action_search:
                openSearch(); 
                return true;
            case R.id.action_settings:
                openSettings();
                return true; 
            default: 
                return super.onOptionsItemSelected(item); 
        }
    }

    private void openSettings() {
        // Later
    }
    private void openSearch() {
        // Later
   }
}

When I am trying to run the application on a tab , I am getting the following error

09-12 14:57:58.702: D/libEGL(5349): loaded /system/lib/egl/libGLES_android.so
09-12 14:57:58.712: D/libEGL(5349): loaded /system/lib/egl/libEGL_tegra.so
09-12 14:57:58.722: D/libEGL(5349): loaded /system/lib/egl/libGLESv1_CM_tegra.so
09-12 14:57:58.732: D/libEGL(5349): loaded /system/lib/egl/libGLESv2_tegra.so
09-12 14:57:58.782: D/OpenGLRenderer(5349): Enabling debug mode 0
09-12 14:58:07.662: D/AndroidRuntime(5349): Shutting down VM
09-12 14:58:07.662: W/dalvikvm(5349): threadid=1: thread exiting with uncaught exception (group=0x40a3e1f8)
09-12 14:58:07.672: E/AndroidRuntime(5349): FATAL EXCEPTION: main
09-12 14:58:07.672: E/AndroidRuntime(5349): java.lang.IllegalStateException: Could not execute method of the activity
09-12 14:58:07.672: E/AndroidRuntime(5349):     at android.view.View$1.onClick(View.java:3044)
09-12 14:58:07.672: E/AndroidRuntime(5349):     at android.view.View.performClick(View.java:3511)
09-12 14:58:07.672: E/AndroidRuntime(5349):     at android.view.View$PerformClick.run(View.java:14105)
09-12 14:58:07.672: E/AndroidRuntime(5349):     at android.os.Handler.handleCallback(Handler.java:605)
09-12 14:58:07.672: E/AndroidRuntime(5349):     at android.os.Handler.dispatchMessage(Handler.java:92)
09-12 14:58:07.672: E/AndroidRuntime(5349):     at android.os.Looper.loop(Looper.java:137)
09-12 14:58:07.672: E/AndroidRuntime(5349):     at android.app.ActivityThread.main(ActivityThread.java:4446)
09-12 14:58:07.672: E/AndroidRuntime(5349):     at java.lang.reflect.Method.invokeNative(Native Method)
09-12 14:58:07.672: E/AndroidRuntime(5349):     at java.lang.reflect.Method.invoke(Method.java:511)
09-12 14:58:07.672: E/AndroidRuntime(5349):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
09-12 14:58:07.672: E/AndroidRuntime(5349):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
09-12 14:58:07.672: E/AndroidRuntime(5349):     at dalvik.system.NativeStart.main(Native Method)
09-12 14:58:07.672: E/AndroidRuntime(5349): Caused by: java.lang.reflect.InvocationTargetException
09-12 14:58:07.672: E/AndroidRuntime(5349):     at java.lang.reflect.Method.invokeNative(Native Method)
09-12 14:58:07.672: E/AndroidRuntime(5349):     at java.lang.reflect.Method.invoke(Method.java:511)
09-12 14:58:07.672: E/AndroidRuntime(5349):     at android.view.View$1.onClick(View.java:3039)
09-12 14:58:07.672: E/AndroidRuntime(5349):     ... 11 more
09-12 14:58:07.672: E/AndroidRuntime(5349): Caused by: android.content.ActivityNotFoundException: Unable to find explicit activity class {com.example.myfirstapp/com.example.myfirstapp.DisplayMessageActivity}; have you declared this activity in your AndroidManifest.xml?
09-12 14:58:07.672: E/AndroidRuntime(5349):     at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1508)
09-12 14:58:07.672: E/AndroidRuntime(5349):     at android.app.Instrumentation.execStartActivity(Instrumentation.java:1384)
09-12 14:58:07.672: E/AndroidRuntime(5349):     at android.app.Activity.startActivityForResult(Activity.java:3190)
09-12 14:58:07.672: E/AndroidRuntime(5349):     at android.app.Activity.startActivity(Activity.java:3297)
09-12 14:58:07.672: E/AndroidRuntime(5349):     at com.example.myfirstapp.MainActivity.sendMessage(MainActivity.java:38)
09-12 14:58:07.672: E/AndroidRuntime(5349):     ... 14 more
09-12 15:03:07.712: I/Process(5349): Sending signal. PID: 5349 SIG: 9

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"
    android:orientation="horizontal"> 

    <EditText android:id="@+id/edit_message" 
          android:layout_width="0dp"  
          android:layout_height="wrap_content"  
          android:hint="@string/edit_message" 
          android:layout_weight="1"/>

    <Button 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/button_send"
        android:onClick="sendMessage" />

</LinearLayout>

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-sdk
        android:minSdkVersion="11"
        android:targetSdkVersion="17" />

    <application
        android:allowBackup="true"
        android:debuggable="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@android:style/Theme.Holo" >
        <activity
            android:name="com.example.myfirstapp.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>
    </application>

</manifest>
Biraj Zalavadia

Add this to your manifest

<activity
            android:name="com.example.myfirstapp.DisplayMessageActivity" />

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

how to avoid crashing of android app due to clicking on button?

From Dev

My First App keeps crashing

From Dev

My app is crashing on button click

From Dev

Why is my button crashing my app?

From Dev

My android app keeps on crashing

From Dev

android button - my first app error

From Dev

Android - App keeps crashing after adding button

From Dev

Android app crashing when i hit a button

From Dev

Android: app crashing after button click

From Dev

Android app crashing when implementing button listener

From Dev

App Crashing when Adding a Button- Android

From Dev

android app crashing while clicking on Cast Mini Controller

From Dev

My app keeps crashing in Android Studio

From Dev

My google map android app keeps crashing

From Dev

My app keeps crashing in Android Studio

From Dev

Why my android app is crashing periodically?

From Dev

Android MonkeyRunner - app closes when clicking on button

From Dev

Android App gets crashed on clicking button

From Dev

Clicking button causes app to crash Android Studio

From Dev

My app keeps on crashing

From Dev

My app is opened when clicking on a URL in Android

From Dev

App is crashing while clicking on app icon

From Dev

DisplayMessageActivity back button keeps crashing my android application

From Dev

DisplayMessageActivity back button keeps crashing my android application

From Dev

Android Studio app keeps crashing after button click

From Dev

Android App crashing as i click button, issue with onClickListener

From Dev

Ubuntu crashing after clicking "Show Applications" button

From Dev

Why is my Android app showing up blank and then crashing?

From Dev

How do I stop my android app from crashing in the emulator?

Related Related

HotTag

Archive