-1
我在我的佈局xml中意外地將按鈕的ID設置爲「mybutton-1」。當我在Android Studio中點擊「運行應用程序」,它切換到R.java一個錯誤在Android搞砸了R.java無法找到資源ID#0xffffffff
public static final int mybutton-1=0x7f0b00e1;
和錯誤消息說,有預期的-1後;
。所以我將佈局xml中該按鈕的id更改爲「myButton_a」,然後再次運行應用程序。這一次,我在mainActivity.java在得到了一個錯誤:
ArrayList<View> focusableViews = view.getFocusables(View.FOCUS_FORWARD);
for (int i = 0; i < focusableViews.size(); i++) {
View actualView = focusableViews.get(i);
String actualID = actualView.getResources().getResourceEntryName(actualView.getId()); // here
...
}
我看着R.java和預期 public static final int myButton_a=0x7f0b00e1;
這更新了我的變化是堆棧跟蹤:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: myApp.mainActivity, PID: 31364
java.lang.RuntimeException: Unable to start activity ComponentInfo{myApp.mainActivity/myApp.mainActivity.mainLayout}: android.content.res.Resources$NotFoundException: Unable to find resource ID #0xffffffff
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3254)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3350)
at android.app.ActivityThread.access$1100(ActivityThread.java:222)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1795)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:158)
at android.app.ActivityThread.main(ActivityThread.java:7229)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
Caused by: android.content.res.Resources$NotFoundException: Unable to find resource ID #0xffffffff
at android.content.res.Resources.getResourceEntryName(Resources.java:3738)
at android.support.v7.widget.ResourcesWrapper.getResourceEntryName(ResourcesWrapper.java:264)
at myApp.mainActivity.doStuff(mainActivity.java:341)
at myApp.mainActivity.onCreate(mainActivity.java:71)
at android.app.Activity.performCreate(Activity.java:6876)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1135)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3207)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3350)
at android.app.ActivityThread.access$1100(ActivityThread.java:222)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1795)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:158)
at android.app.ActivityThread.main(ActivityThread.java:7229)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
我該如何解決這個問題?我讀過,我必須手動設置ID,但有另一種方法嗎?我不想再混淆ID了
'actualView.getId()'輸出的是什麼? – Turtle
Error說'actualView.getId()'的值是'0xffffffff'。所以你的一個ID是-1。 –
清理項目並重建它 –