Reputation: 85
<activity
android:name=".Fisrt"
android:label="@string/title_activity_first" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".Second"
android:label="@string/title_activity_second" >
<intent-filter>
<action android:name="com.example.MusicTest.First"/>
<category android:name="ANDROID.INTENT.CATEGORY.DEFAULT"/>
</intent-filter>
</activity>
And in my First.java, the code is below.
public final static String MY_ACTION = "com.example.MusicTest.First";
public void change(View view) {
Intent intent = new Intent(First.MY_ACTION);
startActivity(intent);
}
The problem is everytime I call change(), the APP would crash. Any Input will be helpful. Thanks.
/supplement/ The log is below:
08-10 11:59:08.873 17509-17509/com.example.root.musictest W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0x41ffcd58) 08-10 11:59:08.873 17509-17509/com.example.root.musictest E/AndroidRuntime﹕ FATAL EXCEPTION: main Process: com.example.root.musictest, PID: 17509 java.lang.IllegalStateException: Could not execute method of the activity at android.view.View$1.onClick(View.java:3829) at android.view.View.performClick(View.java:4444) at android.view.View$PerformClick.run(View.java:18457) at android.os.Handler.handleCallback(Handler.java:733) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:136) at android.app.ActivityThread.main(ActivityThread.java:5034) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:515) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:807) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:623) at dalvik.system.NativeStart.main(Native Method) Caused by: java.lang.reflect.InvocationTargetException at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:515) at android.view.View$1.onClick(View.java:3824) at android.view.View.performClick(View.java:4444) at android.view.View$PerformClick.run(View.java:18457) at android.os.Handler.handleCallback(Handler.java:733) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:136) at android.app.ActivityThread.main(ActivityThread.java:5034) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:515) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:807) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:623) at dalvik.system.NativeStart.main(Native Method) Caused by: android.content.ActivityNotFoundException: No Activity found to handle Intent { act=com.example.MusicTest.First } at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1632) at android.app.Instrumentation.execStartActivity(Instrumentation.java:1424) at android.app.Activity.startActivityForResult(Activity.java:3439) at android.app.Activity.startActivityForResult(Activity.java:3400) at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:820) at android.app.Activity.startActivity(Activity.java:3642) at android.app.Activity.startActivity(Activity.java:3610) at com.example.root.musictest.First.change(First.java:46) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:515) at android.view.View$1.onClick(View.java:3824) at android.view.View.performClick(View.java:4444) at android.view.View$PerformClick.run(View.java:18457) at android.os.Handler.handleCallback(Handler.java:733) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:136) at android.app.ActivityThread.main(ActivityThread.java:5034) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:515) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:807) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:623) at dalvik.system.NativeStart.main(Native Method)
Upvotes: 1
Views: 2890
Reputation: 161
There is spelling mistake in manifest
<activity
android:name=".Fisrt"
should be
android:name=".First"
because your MY_ACTION string is First
public final static String MY_ACTION = "com.example.MusicTest.First";
Upvotes: 0
Reputation: 296
Please try the below code for setting the action.
Intent intent = new Intent();
intent.setAction(First.MY_ACTION);
startActivity(intent);
Second activity will be launched after that.
And of course, you can also add
intent.addCategory("android.intent.category.DEFAULT");
for setting category which you set for Second activity in AndroidManifest.
Upvotes: 0
Reputation: 4124
Change your manifest file to:
<activity
android:name=".Fisrt"
android:label="@string/title_activity_first" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".Second"
android:label="@string/title_activity_second" >
</activity>
To start Second
Activity, try the follow code:
Intent intent = new Intent(First.this, Second.class);
startActivity(intent);
Upvotes: 0