Reputation: 49
I know I could Just manually set this up but I should be able to use a array, but I keep getting a crash, I am thinking it is something simple nut I just cannot find the issue, the crash occurs once a button is pressed :
<?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>
`public class Menu extends Activity implements 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>
Ok logcat:
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
Upvotes: 1
Views: 143
Reputation: 40193
I can only guess without seeing the logcat, but probably the exception you're getting is an ActivityNotFoundException
. In your manifest, your Activities
respond to actions whose names start with "android.intent.action"
, and in code you're initiating actions with names starting with "com.eric.theworks."
. I'd recommend you changing actions described in manifest to the "com.eric.theworks."
variant, cause using default Android naming for custom actions is not a good thing to do. Hope this solves your problem.
Upvotes: 1
Reputation: 1804
Most probably its the code in your activities rather than the manifest or layouts. Check your logcat logs and the exception that is crashing your app is shown and will give you information what is wrong.
Upvotes: 0