gpt4 book ai didi

android - 使用操作栏时应用程序崩溃,这是怎么回事?

转载 作者:行者123 更新时间:2023-12-02 19:31:03 25 4
gpt4 key购买 nike

所以我正在学习制作 Android 应用程序的基础知识,现在我正在尝试操作栏。它没有给出任何错误,但是当我在手机上运行该应用程序时,它崩溃了。这是操作栏:

<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<!-- Search, should appear as action button -->
<item android:id="@+id/action_search"
android:icon="@drawable/ic_action_settings"
android:title="@string/action_settings"
android:showAsAction="ifRoom" />
<!-- Settings, should always be in the overflow -->
<item android:id="@+id/action_settings"
android:title="@string/action_settings"
android:icon="@drawable/ic_action_search"
android:showAsAction="always" />

和主要 Activity java:

    @Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle presses on the action bar items
switch (item.getItemId()) {
case R.id.action_search:
startActivity(new Intent(this, Hallo.class));
return true;
case R.id.action_settings:
return true;
default:
return super.onOptionsItemSelected(item);
}

这是 Hallo.class

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

<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="@string/hallo" />

和hallo.java:

package com.example.myfirstapp;

public class Hallo extends MainActivity{
protected void onCreate() {
setContentView(R.layout.hallo);
}
}

这就是我所拥有的。怎么了?谢谢你的回答。现在我无论如何都在这里,“这个”的 Intent 是什么?再次感谢。

编辑我认为这是堆栈跟踪

Thread [<1> main] (Suspended (exception ActivityNotFoundException)) 
<VM does not provide monitor information>
Instrumentation.checkStartActivityResult(int, Object) line: 1556
Instrumentation.execStartActivity(Context, IBinder, IBinder, Activity, Intent, int, Bundle) line: 1431
MainActivity(Activity).startActivityForResult(Intent, int, Bundle) line: 3390
MainActivity(Activity).startActivityForResult(Intent, int) line: 3351
MainActivity(Activity).startActivity(Intent, Bundle) line: 3561
MainActivity(Activity).startActivity(Intent) line: 3529
MainActivity.onOptionsItemSelected(MenuItem) line: 35
MainActivity(Activity).onMenuItemSelected(int, MenuItem) line: 2573
PhoneWindow.onMenuItemSelected(MenuBuilder, MenuItem) line: 1059
MenuBuilder.dispatchMenuItemSelected(MenuBuilder, MenuItem) line: 735
MenuItemImpl.invoke() line: 149
MenuBuilder.performItemAction(MenuItem, int) line: 874
ActionMenuView.invokeItem(MenuItemImpl) line: 603
ActionMenuItemView.onClick(View) line: 148
ActionMenuItemView(View).performClick() line: 4162
View$PerformClick.run() line: 17082
Handler.handleCallback(Message) line: 615
ViewRootImpl$ViewRootHandler(Handler).dispatchMessage(Message) line: 92
Looper.loop() line: 137
ActivityThread.main(String[]) line: 4856
Method.invokeNative(Object, Object[], Class, Class[], Class, int, boolean) line: not available [native method]
Method.invoke(Object, Object...) line: 511
ZygoteInit$MethodAndArgsCaller.run() line: 1007
ZygoteInit.main(String[]) line: 774
NativeStart.main(String[]) line: not available [native method]

最佳答案

我猜您尚未在 list 文件中添加 Mainactivity 或 Hallo。请发布您的 androidManifest.xml

关于android - 使用操作栏时应用程序崩溃,这是怎么回事?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18578330/

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