当我在Android模拟器中运行我的项目时,active_main.xml界面会正确弹出 按下发送按钮后,必须切换到activity_Display_Message界面 但它在模拟器上给我错误
应用程序第一个应用程序(进程com.helloworld.myfisrtapp)意外停止了。请再试一次。
这些是错误:
06-04 16:32:04.648: D/dalvikvm(276): VFY: dead code 0x008e-0092 in Landroid/support/v7/internal/widget/ActionBarView;.<init> (Landroid/content/Context;Landroid/util/AttributeSet;)V
06-04 16:32:04.648: D/dalvikvm(276): VFY: dead code 0x009c-00a0 in Landroid/support/v7/internal/widget/ActionBarView;.<init> (Landroid/content/Context;Landroid/util/AttributeSet;)V
06-04 16:32:17.908: D/AndroidRuntime(276): Shutting down VM
06-04 16:32:17.908: W/dalvikvm(276): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
06-04 16:32:18.028: D/dalvikvm(276): GC_FOR_MALLOC freed 4899 objects / 284512 bytes in 105ms
06-04 16:32:18.048: E/AndroidRuntime(276): FATAL EXCEPTION: main
06-04 16:32:18.048: E/AndroidRuntime(276): java.lang.IllegalStateException: Could not find a method SendMessage(View) in the activity class com.helloworld.myfirstapp.MainActivity for onClick handler on view class android.widget.Button
06-04 16:32:18.048: E/AndroidRuntime(276): at android.view.View$1.onClick(View.java:2059)
06-04 16:32:18.048: E/AndroidRuntime(276): at android.view.View.performClick(View.java:2408)
06-04 16:32:18.048: E/AndroidRuntime(276): at android.view.View$PerformClick.run(View.java:8816)
06-04 16:32:18.048: E/AndroidRuntime(276): at android.os.Handler.handleCallback(Handler.java:587)
06-04 16:32:18.048: E/AndroidRuntime(276): at android.os.Handler.dispatchMessage(Handler.java:92)
06-04 16:32:18.048: E/AndroidRuntime(276): at android.os.Looper.loop(Looper.java:123)
06-04 16:32:18.048: E/AndroidRuntime(276): at android.app.ActivityThread.main(ActivityThread.java:4627)
06-04 16:32:18.048: E/AndroidRuntime(276): at java.lang.reflect.Method.invokeNative(Native Method)
06-04 16:32:18.048: E/AndroidRuntime(276): at java.lang.reflect.Method.invoke(Method.java:521)
06-04 16:32:18.048: E/AndroidRuntime(276): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
06-04 16:32:18.048: E/AndroidRuntime(276): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
06-04 16:32:18.048: E/AndroidRuntime(276): at dalvik.system.NativeStart.main(Native Method)
06-04 16:32:18.048: E/AndroidRuntime(276): Caused by: java.lang.NoSuchMethodException: SendMessage
06-04 16:32:18.048: E/AndroidRuntime(276): at java.lang.ClassCache.findMethodByName(ClassCache.java:308)
06-04 16:32:18.048: E/AndroidRuntime(276): at java.lang.Class.getMethod(Class.java:985)
06-04 16:32:18.048: E/AndroidRuntime(276): at android.view.View$1.onClick(View.java:2052)
06-04 16:32:18.048: E/AndroidRuntime(276): ... 11 more
我的清单文件:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.helloworld.myfirstapp"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="19" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.helloworld.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>
<activity
android:name="com.helloworld.myfirstapp.DisplayMessageActivity"
android:label="@string/title_activity_display_message"
android:parentActivityName="com.helloworld.myfirstapp.MainActivity" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.helloworld.myfirstapp.MainActivity" />
</activity>
</application>
我没有任何线索如何修复它我是android开发的新手 以及stackoverflow 谢谢你的帮助
答案 0 :(得分:4)
java.lang.IllegalStateException:无法在视图类android.widget.Button上的onClick处理程序的活动类com.helloworld.myfirstapp.MainActivity中找到方法SendMessage(View)
您有一个XML格式为android:onClick="SendMessage"
的按钮,而您的活动没有SendMessage(View)
方法。从XML中删除onClick
或在活动中添加方法。
答案 1 :(得分:0)
请提供您在其中加载的Activity和xml的代码。看来你在xml和onClick参数函数中有一个按钮,你没有把它放在你的活动中......