gpt4 book ai didi

Android - 当我以影响 Intent 调用 startActivity() 时,应用程序崩溃

转载 作者:行者123 更新时间:2023-12-02 07:10:08 25 4
gpt4 key购买 nike

<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>

在我的 First.java 中,代码如下。

public final static String MY_ACTION = "com.example.MusicTest.First";

public void change(View view) {
Intent intent = new Intent(First.MY_ACTION);
startActivity(intent);
}

问题是每次我调用change()时,应用程序都会崩溃。任何输入都会有帮助。谢谢。

/补充/日志如下:

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)

最佳答案

将 list 文件更改为:

<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>

要启动第二个 Activity,请尝试以下代码:

Intent intent = new Intent(First.this, Second.class);
startActivity(intent);

关于Android - 当我以影响 Intent 调用 startActivity() 时,应用程序崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31911190/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com