1

我试图运行我的第一个 android 应用程序,但我无法执行它。我从developer.android.com一步一步地按照说明进行操作。我只对代码使用了复制和粘贴。但是当我尝试运行我的应用程序时,AVD 给出错误“不幸的是,我的第一个应用程序已经弯腰。”

屏幕截图在这里: AVD 设置单击 LOG FILE单击

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>

字符串.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);
    
        }
          }
4

1 回答 1

4

按钮单击方法中的拼写错误,s is not small its capital in xml layout file...

public void SendMessage(View view) {
            ^     
于 2012-08-15T13:24:15.693 回答