1

i tried to run my first android application but i could not execute it. i followed instructions step by step from developer.android.com . I used only Copy and Paste for codes. But when i try to run my app AVD is giving error "Unfortunately, My First App has stooped."

Screen Captures are here : AVD Settings : Click LOG FILE:Click

AndroidManifest.xml

<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="8"
            android:targetSdkVersion="15" />
    
        <application
            android:icon="@drawable/ic_launcher"
            android:label="@string/app_name"
            android:theme="@style/AppTheme" >
            
            <activity
                android:name=".MainActivity"
                android:label="@string/title_activity_main" >
                <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>

activity_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>

activity_display_message.xml

<RelativeLayout 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" >
    
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:layout_centerVertical="true"
            android:text="@string/hello_world"
            tools:context=".DisplayMessageActivity" />
    
    </RelativeLayout>

strings.xml

<resources>
    
        <string name="app_name">My First App</string>
        <string name="menu_settings">Settings</string>
        <string name="title_activity_main">MainActivity</string>
        <string name="edit_message">Bir şeyler yaz</string>
        <string name="button_send">Send</string>
        <string name="hello_world">Hello world!</string>
        <string name="title_activity_display_message">My Message</string>
    
    </resources>

DisplayMessageActivity.java

package com.example.myfirstapp;
        import android.app.Activity;
        import android.content.Intent;
        import android.os.Bundle;
        import android.widget.*;
    
        public class DisplayMessageActivity extends Activity {
        @Override
        public 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);
        }
         }

MainActivity.java

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.*;
    
            public class MainActivity extends Activity {
    
         public final static String EXTRA_MESSAGE = "com.example.myfirstapp.MESSAGE";
    
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
        }
    
        @Override
        public boolean onCreateOptionsMenu(Menu menu) {
            getMenuInflater().inflate(R.menu.activity_main, menu);
            return true;
    
        }
    
        public void sendMessage(View view) {
            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);
    
        }
          }
Community
  • 1
  • 1
hakiko
  • 23
  • 2
  • 5
  • 1
    It looks like you are using Eclipse, so could you go to Window > Show view > Other, Android > Logcat and show that window? It gives you the debug output of your android device, and will provide more information on what went wrong. – WouterH Aug 15 '12 at 13:22
  • post the log. On Eclipse there's a window called 'Logcat' there should be a message in red color the moment your app crashes. That log is important to find the root of it as I don't think no one will be reading all this code. – Budius Aug 15 '12 at 13:22

1 Answers1

4

typo mistake in Button click method,s is not small its capital in xml layout file...

public void SendMessage(View view) {
            ^     
Samir Mangroliya
  • 39,918
  • 16
  • 117
  • 134
  • Thank you much. only letter 's' took from me about 3 hours. I can not believe it. Also Eclipse IDE did not give an error. Now it is working like Messi :) – hakiko Aug 15 '12 at 13:38