簡體   English   中英

安卓工作室 | 不再調用資源的錯誤“找不到資源”

[英]Android Studio | Error "resource not found" for no longer called resource

關閉所有代碼:以下行在我的 MainActivity.java 中

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();

    View view = findViewById(R.id.action_item_two);

    //noinspection SimplifiableIfStatement
    if (id == R.id.action_item_one) {
        // Do thing one
        return true;
    }
    if (id == R.id.action_item_two) {
        // Do thing two
        return true;
    }

    return super.onOptionsItemSelected(item);
}

我的菜單有文件 res/menu/main.xml,如下所示:

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto">
    <item
        android:id="@+id/action_item_one"
        android:icon="@drawable/ic_help"
        app:showAsAction="always"
        android:title="Hilfe">
    </item>
    <item
        android:id="@+id/action_item_two"
        android:icon="@drawable/ic_forward_30_48px"
        app:showAsAction="always"
        android:title="Sekunden">
    </item>

</menu>

在舊版本的主菜單中,我使用 drawable/ic_baseline_pause_24 作為圖標源來測試菜單並且它有效。

在此之后,我將圖標源更改為最終的,但圖標仍然是舊的。

我刪除了舊的圖標源(drawable/ic_baseline_pause_24,從現在開始,嘗試啟動應用程序時出現以下錯誤:[datafile to the app]\app\src\main\res\menu\main.xml:4: AAPT :錯誤:找不到資源drawable/ic_baseline_pause_24(又名[...]:drawable/ic_baseline_pause_24)。

在舊菜單版本的第 4 行中,有舊的圖標源,但現在它無處可去,我不知道如何解決這個錯誤。

我嘗試重新啟動所有內容,包括(使緩存無效並重新啟動 Android Studio)

我希望有人能幫忙! 謝謝

好的,我找到了解決問題的方法...

這是我在 main.xml 中的語法錯誤

它一定要是:

<item
    android:id="@+id/action_item_one"
    android:icon="@drawable/ic_help"
    app:showAsAction="always"
    android:title="Hilfe"/>
<item
    android:id="@+id/action_item_two"
    android:icon="@drawable/ic_forward_30_48px"
    app:showAsAction="always"
    android:title="Sekunden">
</item>

導致這個錯誤菜單沒有更新

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM