2012-05-11 111 views
2

所以我一直有問題得到這個運行。這是一個直接從android基礎訓練中拉出的教程。我得到以下錯誤消息:Android模擬器停止

05-11 06:59:39.457:W/dalvikvm(623):線程ID = 1:螺紋與未捕獲的異常(組= 0x409c01f8) 05-11 6點五十九離開:39.617:E/AndroidRuntime(623):致命例外:main 05-11 06:59:39.617:E/AndroidRuntime(623):java.lang.IllegalStateException:無法執行活動的方法 05-11 06: 59/39.617:E/AndroidRuntime(623):在android.view.View $ 1.onClick(View.java:3044) 05-11 06:59:39.617:E/AndroidRuntime(623):at android.view.View .performClick(View.java:3511) 05-11 06:59:39.617:E/AndroidRuntime(623):at android.view.View $ PerformClick.run(View.java:14105) 05-11 06:59 :39.617:E/A ndroidRuntime(623):在android.os.Handler.handleCallback(Handler.java:605) 05-11 06:59:39.617:E/AndroidRuntime(623):at android.os.Handler.dispatchMessage(Handler.java: 92) 05-11 06:59:39.617:E/AndroidRuntime(623):at android.os.Looper.loop(Looper.java:137) 05-11 06:59:39.617:E/AndroidRuntime(623) :at android.app.ActivityThread.main(ActivityThread.java:4424) 05-11 06:59:39.617:E/AndroidRuntime(623):at java.lang.reflect.Method.invokeNative(Native Method) 05- 11 06:59:39.617:E/AndroidRuntime(623):在java.lang.reflect.Method.invoke(Method.java:511) 05-11 06:59:39.617:E/AndroidRuntime(623):at com .android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:784) 05-11 06:59:39.617:E/AndroidRuntime(623):at com.android.internal.os.ZygoteInit.main(ZygoteI nit.java:551) 05-11 06:59:39.617:E/AndroidRuntime(623):at dalvik.system.NativeStart.main(Native Method) 05-11 06:59:39.617:E/AndroidRuntime(623) ):引發:java.lang.reflect.InvocationTargetException 05-11 06:59:39.617:E/AndroidRuntime(623):at java.lang.reflect.Method.invokeNative(Native Method) 05-11 06:59 :39.617:E/AndroidRuntime(623):在java.lang.reflect.Method.invoke(Method.java:511) 05-11 06:59:39.617:E/AndroidRuntime(623):at android.view.View $ 1.onClick(View.java:3039) 05-11 06:59:39.617:E/AndroidRuntime(623):... 11更多 05-11 06:59:39.617:E/AndroidRuntime(623):引起通過:android.content.ActivityNotFoundException:無法找到顯式活動類{com.example.namespace/com.example.namespace.DisplayMessageActivity};你有沒有在你的AndroidManifest.xml中聲明這個活動? E/AndroidRuntime(623):at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1508) 05-11 06:59:39.617:E/AndroidRuntime(623):at android.app.Instrumentation.execStartActivity(Instrumentation.java:1384) 05-11 06:59:39.617:E/AndroidRuntime(623):at android.app.Activity.startActivityForResult(Activity.java:3190) 05-11 06:59:39.617:E/AndroidRuntime(623):at android.app.Activity.startActivity(Activity.java:3297) 05-11 06:59:39.617:E/AndroidRuntime(623):at com.example。 namespace.MyFirstAppActivity.sendMessage(MyFirstAppActivity.java:25) 6月5日至11日:59:39.617:E/AndroidRuntime(623):14 ...更多 6月5日至11日:59:40.477:I/dalvikvm(623) :threadid = 3:對信號3起作用

這裏是我的兩個java文件,

package com.example.namespace; 

    import android.app.Activity; 
    import android.content.Intent; 
    import android.os.Bundle; 
    import android.widget.TextView; 

    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(MyFirstAppActivity.EXTRA_MESSAGE); 

    // Create the text view 
    TextView textView = new TextView(this); 
    textView.setTextSize(40); 
    textView.setText(message); 

    setContentView(textView); 
} 
} 

package com.example.namespace; 

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

public class MyFirstAppActivity extends Activity { 
public final static String EXTRA_MESSAGE = "com.example.myapp.MESSAGE"; 
/** Called when the activity is first created. */ 
@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main); 
} 


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

這裏是我的androidmanifest。XML

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
package="com.example.namespace" 
android:versionCode="1" 
android:versionName="1.0" > 

<uses-sdk android:minSdkVersion="15" /> 

<application 
    android:icon="@drawable/ic_launcher" 
    android:label="@string/app_name" > 
    <activity android:name="com.example.myapp.DisplayMessageActivity" /> 
    <activity 
     android:name=".MyFirstAppActivity" 
     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> 

和我的main.xml:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="fill_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:id="@+id/button_send" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="@string/button_send" 
    android:onClick="sendMessage"/> 
</LinearLayout> 

每次我運行此,分 「的sendMessage」 之稱,我得到 「不幸的是,myFirstApp已經停止。」有什麼建議?

回答

1

我想這應該是

android:name="com.example.myapp.DisplayMessageActivity" 

改爲

android:name="com.example.namespace.DisplayMessageActivity" 

因爲沒有包裝com.example.myapp

+0

感謝,完美地工作! – user1388795

1

在日誌中的答案。 「你有沒有在你的AndroidManifest.xml中聲明這個活動?」

添加活性DisplayMessageActivity到AndroidManifest.xml中

<activity android:name=".DisplayMessageActivity" /> 
+0

謝謝,這工作! – user1388795

相關問題