使用Eclipse-ADT“构建您的第一个应用程序”运行时错误

时间:2014-02-07 22:31:49

标签: eclipse-adt

我在Android的应用创建培训下正在开发“构建您的第一个应用”。我已完成所有步骤,并通过我的Galaxy S4运行应用程序。它将第一页完全加载到用户输入的任何地方,然后将您带到显示用户输入内容的第二页。加载第二页是出错的地方。

    02-07 16:21:06.167: W/dalvikvm(21946): threadid=1: thread exiting with uncaught exception (group=0x417a4898)
    02-07 16:21:06.177: E/AndroidRuntime(21946): FATAL EXCEPTION: main
    02-07 16:21:06.177: E/AndroidRuntime(21946): java.lang.IllegalStateException: Could not find a method sendmessage(View) in the activity class com.example.myfirstapp.MainActivity for onClick handler on view class android.widget.Button
    02-07 16:21:06.177: E/AndroidRuntime(21946):    at android.view.View$1.onClick(View.java:3825)
    02-07 16:21:06.177: E/AndroidRuntime(21946):    at android.view.View.performClick(View.java:4475)
    02-07 16:21:06.177: E/AndroidRuntime(21946):    at android.view.View$PerformClick.run(View.java:18786)
    02-07 16:21:06.177: E/AndroidRuntime(21946):    at android.os.Handler.handleCallback(Handler.java:730)
    02-07 16:21:06.177: E/AndroidRuntime(21946):    at android.os.Handler.dispatchMessage(Handler.java:92)
    02-07 16:21:06.177: E/AndroidRuntime(21946):    at android.os.Looper.loop(Looper.java:137)
    02-07 16:21:06.177: E/AndroidRuntime(21946):    at android.app.ActivityThread.main(ActivityThread.java:5419)
    02-07 16:21:06.177: E/AndroidRuntime(21946):    at java.lang.reflect.Method.invokeNative(Native Method)
    02-07 16:21:06.177: E/AndroidRuntime(21946):    at java.lang.reflect.Method.invoke(Method.java:525)
    02-07 16:21:06.177: E/AndroidRuntime(21946):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1187)
    02-07 16:21:06.177: E/AndroidRuntime(21946):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)
    02-07 16:21:06.177: E/AndroidRuntime(21946):    at dalvik.system.NativeStart.main(Native Method)
    02-07 16:21:06.177: E/AndroidRuntime(21946): Caused by: java.lang.NoSuchMethodException: sendmessage [class android.view.View]
    02-07 16:21:06.177: E/AndroidRuntime(21946):    at java.lang.Class.getConstructorOrMethod(Class.java:423)
    02-07 16:21:06.177: E/AndroidRuntime(21946):    at java.lang.Class.getMethod(Class.java:787)
    02-07 16:21:06.177: E/AndroidRuntime(21946):    at android.view.View$1.onClick(View.java:3818)
    02-07 16:21:06.177: E/AndroidRuntime(21946):    ... 11 more

我有点不知所措,甚至开始缓解这个问题。

active_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"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".DisplayMessageActivity" >

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/hello_world" />

这是DisplayMessageActivity类下的onCreate():

@SuppressLint("NewApi")
@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);

    // Make sure we're running on Honeycomb or higher to use ActionBar APIs
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB){
        // Show the Up button in the action bar.
        getActionBar().setDisplayHomeAsUpEnabled(true);
    } 
}

0 个答案:

没有答案