我知道我可以手动设置它,但我应该可以使用数组,但我一直在崩溃,我认为这是一个简单的问题,我只是找不到问题,一旦按下按钮就会发生崩溃:
<?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>
`公共类菜单扩展活动实现OnClickListener {
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