gpt4 book ai didi

java - Android模拟器中的按钮按下

转载 作者:行者123 更新时间:2023-11-30 11:50:36 26 4
gpt4 key购买 nike

我最近开始为 android 编程,但遇到了一个问题,我无法按下按钮来工作,也无法将我转到另一个屏幕。模拟器刚刚崩溃。我认为这是一个非常简单的问题,但我在网上找不到任何东西,也看不出它为什么会崩溃。按下按钮的代码是:

public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

Button directions = (Button)findViewById(R.id.buttonDirections);

directions.setOnClickListener(new View.OnClickListener() {

public void onClick(View v) {
Intent i = new Intent(MainMenu.this, Directions.class);
MainMenu.this.startActivity(i);

}
});
}

10-25 14:54:45.457: DEBUG/dalvikvm(372): Debugger has detached; object registry had 1 entries
10-25 14:54:54.527: DEBUG/dalvikvm(137): GC_EXTERNAL_ALLOC freed 152K, 51% free 2940K/5959K, external 4643K/5293K, paused 88ms
10-25 14:54:57.887: INFO/ActivityManager(69): Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=com.ui.app/.MainMenu } from pid 137
10-25 14:54:58.217: INFO/ActivityManager(69): Start proc com.ui.app for activity com.ui.app/.MainMenu: pid=381 uid=10034 gids={}
10-25 14:54:59.497: INFO/ARMAssembler(69): generated scanline__00000177:03515104_00001002_00000000 [ 87 ipp] (110 ins) at [0x445ed6f0:0x445ed8a8] in 951890 ns
10-25 14:55:00.437: INFO/ActivityManager(69): Displayed com.ui.app/.MainMenu: +2s234ms
10-25 14:55:02.660: INFO/ActivityManager(69): Starting: Intent { cmp=com.ui.app/.Directions } from pid 381
10-25 14:55:02.701: DEBUG/AndroidRuntime(381): Shutting down VM
10-25 14:55:02.701: WARN/dalvikvm(381): threadid=1: thread exiting with uncaught exception (group=0x40015560)
10-25 14:55:02.721: ERROR/AndroidRuntime(381): FATAL EXCEPTION: main
10-25 14:55:02.721: ERROR/AndroidRuntime(381): android.content.ActivityNotFoundException: Unable to find explicit activity class {com.ui.app/com.ui.app.Directions}; have you declared this activity in your AndroidManifest.xml?
10-25 14:55:02.721: ERROR/AndroidRuntime(381): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1405)
10-25 14:55:02.721: ERROR/AndroidRuntime(381): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1379)
10-25 14:55:02.721: ERROR/AndroidRuntime(381): at android.app.Activity.startActivityForResult(Activity.java:2827)
10-25 14:55:02.721: ERROR/AndroidRuntime(381): at android.app.Activity.startActivity(Activity.java:2933)
10-25 14:55:02.721: ERROR/AndroidRuntime(381): at com.ui.app.MainMenu$1.onClick(MainMenu.java:22)
10-25 14:55:02.721: ERROR/AndroidRuntime(381): at android.view.View.performClick(View.java:2485)
10-25 14:55:02.721: ERROR/AndroidRuntime(381): at android.view.View$PerformClick.run(View.java:9080)
10-25 14:55:02.721: ERROR/AndroidRuntime(381): at android.os.Handler.handleCallback(Handler.java:587)
10-25 14:55:02.721: ERROR/AndroidRuntime(381): at android.os.Handler.dispatchMessage(Handler.java:92)
10-25 14:55:02.721: ERROR/AndroidRuntime(381): at android.os.Looper.loop(Looper.java:123)
10-25 14:55:02.721: ERROR/AndroidRuntime(381): at android.app.ActivityThread.main(ActivityThread.java:3683)
10-25 14:55:02.721: ERROR/AndroidRuntime(381): at java.lang.reflect.Method.invokeNative(Native Method)
10-25 14:55:02.721: ERROR/AndroidRuntime(381): at java.lang.reflect.Method.invoke(Method.java:507)
10-25 14:55:02.721: ERROR/AndroidRuntime(381): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
10-25 14:55:02.721: ERROR/AndroidRuntime(381): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
10-25 14:55:02.721: ERROR/AndroidRuntime(381): at dalvik.system.NativeStart.main(Native Method)
10-25 14:55:02.740: WARN/ActivityManager(69): Force finishing activity com.ui.app/.MainMenu
10-25 14:55:03.268: WARN/ActivityManager(69): Activity pause timeout for HistoryRecord{40656c60 com.ui.app/.MainMenu}
10-25 14:55:05.309: INFO/Process(381): Sending signal. PID: 381 SIG: 9

尝试建议后的 Logcat

10-25 15:28:44.931: INFO/ActivityManager(69): Starting: Intent { cmp=com.menus.app/.GetDirections } from pid 338
10-25 15:28:44.931: DEBUG/AndroidRuntime(338): Shutting down VM
10-25 15:28:44.939: WARN/dalvikvm(338): threadid=1: thread exiting with uncaught exception (group=0x40015560)
10-25 15:28:44.959: ERROR/AndroidRuntime(338): FATAL EXCEPTION: main
10-25 15:28:44.959: ERROR/AndroidRuntime(338): android.content.ActivityNotFoundException: Unable to find explicit activity class {com.menus.app/com.menus.app.GetDirections}; have you declared this activity in your AndroidManifest.xml?
10-25 15:28:44.959: ERROR/AndroidRuntime(338): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1405)
10-25 15:28:44.959: ERROR/AndroidRuntime(338): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1379)
10-25 15:28:44.959: ERROR/AndroidRuntime(338): at android.app.Activity.startActivityForResult(Activity.java:2827)
10-25 15:28:44.959: ERROR/AndroidRuntime(338): at android.app.Activity.startActivity(Activity.java:2933)
10-25 15:28:44.959: ERROR/AndroidRuntime(338): at com.menus.app.HomeMenu$1.onClick(HomeMenu.java:22)
10-25 15:28:44.959: ERROR/AndroidRuntime(338): at android.view.View.performClick(View.java:2485)
10-25 15:28:44.959: ERROR/AndroidRuntime(338): at android.view.View$PerformClick.run(View.java:9080)
10-25 15:28:44.959: ERROR/AndroidRuntime(338): at android.os.Handler.handleCallback(Handler.java:587)
10-25 15:28:44.959: ERROR/AndroidRuntime(338): at android.os.Handler.dispatchMessage(Handler.java:92)
10-25 15:28:44.959: ERROR/AndroidRuntime(338): at android.os.Looper.loop(Looper.java:123)
10-25 15:28:44.959: ERROR/AndroidRuntime(338): at android.app.ActivityThread.main(ActivityThread.java:3683)
10-25 15:28:44.959: ERROR/AndroidRuntime(338): at java.lang.reflect.Method.invokeNative(Native Method)
10-25 15:28:44.959: ERROR/AndroidRuntime(338): at java.lang.reflect.Method.invoke(Method.java:507)
10-25 15:28:44.959: ERROR/AndroidRuntime(338): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
10-25 15:28:44.959: ERROR/AndroidRuntime(338): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
10-25 15:28:44.959: ERROR/AndroidRuntime(338): at dalvik.system.NativeStart.main(Native Method)
10-25 15:28:44.989: WARN/ActivityManager(69): Force finishing activity com.menus.app/.HomeMenu
10-25 15:28:45.509: WARN/ActivityManager(69): Activity pause timeout for HistoryRecord{40636730 com.menus.app/.HomeMenu}
10-25 15:28:47.379: INFO/Process(338): Sending signal. PID: 338 SIG: 9
10-25 15:28:47.454: INFO/ActivityManager(69): Process com.menus.app (pid 338) has died.
10-25 15:28:47.454: INFO/WindowManager(69): WIN DEATH: Window{4070afd8 com.menus.app/com.menus.app.HomeMenu paused=false}
10-25 15:28:47.659: WARN/InputManagerService(69): Got RemoteException sending setActive(false) notification to pid 338 uid 10034
10-25 15:28:57.269: WARN/ActivityManager(69): Activity destroy timeout for HistoryRecord{40636730 com.menus.app/.HomeMenu}
10-25 15:29:00.150: WARN/ActivityManager(69): finishReceiver called but no pending broadcasts

我也重新制作了这个项目,因为我认为它可能与一个类似名称的项目冲突,所以名称不同。

最佳答案

可能您还没有在 list 中声明您的 Directions 类

将此添加到文件 AndroidManifest.xml

<activity android:name=".Directions" android:label="Directions" />

关于java - Android模拟器中的按钮按下,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7890470/

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