Android 选择活动时应用程序崩溃
我知道我可以手动设置,但我应该能够使用数组,但我不断遇到崩溃,我认为这是一个简单的问题,我就是找不到问题,一旦按下按钮,崩溃就会发生:Android 选择活动时应用程序崩溃,android,Android,我知道我可以手动设置,但我应该能够使用数组,但我不断遇到崩溃,我认为这是一个简单的问题,我就是找不到问题,一旦按下按钮,崩溃就会发生: <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.eric.theworks" android:versionCode="1" android:versi
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.eric.theworks"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.eric.theworks.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.ST" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name="Numbers"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.NUMBERS" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name="Settings"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.SETTINGS" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name="InternalStore"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.INTERNALSTORE" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name="Reading"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.READING" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name="Menu"
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>
</manifest>
很可能是活动中的代码,而不是清单或布局。检查您的logcat日志,会显示导致应用程序崩溃的异常,并向您提供错误信息。很可能是活动中的代码,而不是清单或布局。检查您的logcat日志,会显示导致应用程序崩溃的异常,并将为您提供错误信息。我只能猜测,但没有看到logcat,但您可能会遇到异常,即
ActivityNotFoundException
。在您的清单中,您的活动
响应名称以“android.intent.action”
开头的操作,而在代码中,您启动的操作名称以“com.eric.theworks.”
开头。我建议您将清单中描述的操作更改为“com.eric.theworks.”
变体,因为对自定义操作使用默认Android命名不是一件好事。希望这能解决您的问题。我只能猜测而没有看到logcat,但您可能得到的异常是ActivityNotFoundException
。在您的清单中,您的活动
响应名称以“android.intent.action”
开头的操作,而在代码中,您启动的操作名称以“com.eric.theworks.”
开头。我建议您将清单中描述的操作更改为“com.eric.theworks.”
变体,因为对自定义操作使用默认Android命名不是一件好事。希望这能解决您的问题。我知道,奇怪的是,当我编辑代码时,我看到我的代码丢失了,但由于某种原因它没有显示出来,我知道,奇怪的是,当我编辑我的代码时,我看到我的代码丢失了,但出于某种原因,它没有显示。支持的是菜单。java idk为什么它不会显示:从logcat:03-17 05:10:32.300:E/AndroidRuntime(19878):由:java.lang.reflect.invocationTargetExceptions引起,可能会显示完整的堆栈跟踪。这很清楚<代码>原因:android.content.ActivityNotFoundException:找不到处理意图的活动{act=com.eric.theworks.ST}这里是menu.java idk为什么它不会出现:从logcat:03-17 05:10:32.300:E/AndroidRuntime(19878):原因:java.lang.reflect.invocationTargetExceptions可能会发布完整堆栈跟踪这很清楚<代码>由以下原因引起:android.content.ActivityNotFoundException:找不到处理意图的活动{act=com.eric.theworks.ST}@EricMiller,具体是什么?现在只有阅读活动失败了。:03-17 05:50:32.519:E/AndroidRuntime(20957):java.lang.RuntimeException:无法启动活动组件信息{com.eric.theworks/com.eric.theworks.Reading}:java.lang.ClassCastException:android.widget.Button无法转换为android.widget.SpinnerWell我想这是一个不同的问题:)事实上它被转换为一个微调器,这就是为什么你不在早上6点不睡觉的情况下编码。@EricMiller,到底是什么?现在只有阅读活动失败了。:03-17 05:50:32.519:E/AndroidRuntime(20957):java.lang.RuntimeException:无法启动activity ComponentInfo{com.eric.theworks/com.eric.theworks.Reading}:java.lang.ClassCastException:android.widget.Button无法转换为android.widget.SpinnerWell我想这是另一个问题:)事实上它被转换为微调器,这就是为什么你不在早上6点不睡觉的情况下编码。
String activities[] = { "ST", "SETTINGS", "INTERNALSTORE", "READING" };
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.menu);
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
int id = v.getId();
for (int i = 0; i < activities.length; i++) {
if (id == getResources().getIdentifier("b" + i, "id",
"com.eric.theworks")) {
Intent intent = new Intent("com.eric.theworks." + activities[i]);
startActivity(intent);
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<Button
android:id="@+id/b0"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Passing Data"
android:onClick="onClick"/>
<Button
android:id="@+id/b1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Settings"
android:onClick="onClick" />
<Button
android:id="@+id/b2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Internal Storage"
android:onClick="onClick" />
<Button
android:id="@+id/b3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Reading Data"
android:onClick="onClick" />
</LinearLayout>
03-17 05:36:20.542: D/libEGL(20653): loaded /vendor/lib/egl/libEGL_POWERVR_SGX540_120.so
03-17 05:36:20.550: D/libEGL(20653): loaded /vendor/lib/egl/libGLESv1_CM_POWERVR_SGX540_120.so
03-17 05:36:20.558: D/libEGL(20653): loaded /vendor/lib/egl/libGLESv2_POWERVR_SGX540_120.so
03-17 05:36:20.652: D/OpenGLRenderer(20653): Enabling debug mode 0
03-17 05:36:23.987: D/AndroidRuntime(20653): Shutting down VM
03-17 05:36:23.987: W/dalvikvm(20653): threadid=1: thread exiting with uncaught exception (group=0x40fb4300)
03-17 05:36:23.995: E/AndroidRuntime(20653): FATAL EXCEPTION: main
03-17 05:36:23.995: E/AndroidRuntime(20653): java.lang.IllegalStateException: Could not execute method of the activity
03-17 05:36:23.995: E/AndroidRuntime(20653): at android.view.View$1.onClick(View.java:3591)
03-17 05:36:23.995: E/AndroidRuntime(20653): at android.view.View.performClick(View.java:4084)
03-17 05:36:23.995: E/AndroidRuntime(20653): at android.view.View$PerformClick.run(View.java:16966)
03-17 05:36:23.995: E/AndroidRuntime(20653): at android.os.Handler.handleCallback(Handler.java:615)
03-17 05:36:23.995: E/AndroidRuntime(20653): at android.os.Handler.dispatchMessage(Handler.java:92)
03-17 05:36:23.995: E/AndroidRuntime(20653): at android.os.Looper.loop(Looper.java:137)
03-17 05:36:23.995: E/AndroidRuntime(20653): at android.app.ActivityThread.main(ActivityThread.java:4745)
03-17 05:36:23.995: E/AndroidRuntime(20653): at java.lang.reflect.Method.invokeNative(Native Method)
03-17 05:36:23.995: E/AndroidRuntime(20653): at java.lang.reflect.Method.invoke(Method.java:511)
03-17 05:36:23.995: E/AndroidRuntime(20653): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
03-17 05:36:23.995: E/AndroidRuntime(20653): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
03-17 05:36:23.995: E/AndroidRuntime(20653): at dalvik.system.NativeStart.main(Native Method)
03-17 05:36:23.995: E/AndroidRuntime(20653): Caused by: java.lang.reflect.InvocationTargetException
03-17 05:36:23.995: E/AndroidRuntime(20653): at java.lang.reflect.Method.invokeNative(Native Method)
03-17 05:36:23.995: E/AndroidRuntime(20653): at java.lang.reflect.Method.invoke(Method.java:511)
03-17 05:36:23.995: E/AndroidRuntime(20653): at android.view.View$1.onClick(View.java:3586)
03-17 05:36:23.995: E/AndroidRuntime(20653): ... 11 more
03-17 05:36:23.995: E/AndroidRuntime(20653): Caused by: android.content.ActivityNotFoundException: No Activity found to handle Intent { act=com.eric.theworks.ST }
03-17 05:36:23.995: E/AndroidRuntime(20653): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1545)
03-17 05:36:23.995: E/AndroidRuntime(20653): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1416)
03-17 05:36:23.995: E/AndroidRuntime(20653): at android.app.Activity.startActivityForResult(Activity.java:3351)
03-17 05:36:23.995: E/AndroidRuntime(20653): at android.app.Activity.startActivityForResult(Activity.java:3312)
03-17 05:36:23.995: E/AndroidRuntime(20653): at android.app.Activity.startActivity(Activity.java:3522)
03-17 05:36:23.995: E/AndroidRuntime(20653): at android.app.Activity.startActivity(Activity.java:3490)
03-17 05:36:23.995: E/AndroidRuntime(20653): at com.eric.theworks.Menu.onClick(Menu.java:28)
03-17 05:36:23.995: E/AndroidRuntime(20653): ... 14 more
03-17 05:36:25.519: I/Process(20653): Sending signal. PID: 20653 SIG: 9