天天看點

android setcontentview 記憶體溢出,android - Android-v24 API之前的setContentView()崩潰 - 堆棧記憶體溢出...

當我使用27和28版API在模拟器上運作我的應用程式時,一切對我都有效。 但是,當我嘗試使用較低級别的API時,會在自定義Activity.java類中收到有關setContentView()方法的錯誤消息。

這是堆棧跟蹤:

2018-12-06 15:37:59.166 9426-9426/? E/AndroidRuntime: FATAL EXCEPTION: main

Process: com.mplexvr.ribbonracker, PID: 9426

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.mplexvr.ribbonracker/com.mplexvr.ribbonracker.RibbonRackerActivity}: android.content.res.Resources$NotFoundException: Resource ID #0x7f0b0000

at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2646)

at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2707)

at android.app.ActivityThread.-wrap12(ActivityThread.java)

at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1460)

at android.os.Handler.dispatchMessage(Handler.java:102)

at android.os.Looper.loop(Looper.java:154)

at android.app.ActivityThread.main(ActivityThread.java:6077)

at java.lang.reflect.Method.invoke(Native Method)

at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866)

at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:756)

Caused by: android.content.res.Resources$NotFoundException: Resource ID #0x7f0b0000

at android.content.res.ResourcesImpl.getValue(ResourcesImpl.java:190)

at android.content.res.Resources.getDrawable(Resources.java:766)

at android.content.Context.getDrawable(Context.java:525)

at com.android.internal.widget.ToolbarWidgetWrapper.setIcon(ToolbarWidgetWrapper.java:322)

at com.android.internal.widget.ActionBarOverlayLayout.setIcon(ActionBarOverlayLayout.java:737)

at com.android.internal.policy.PhoneWindow.setDefaultIcon(PhoneWindow.java:1737)

at android.app.Activity.initWindowDecorActionBar(Activity.java:2400)

at android.app.Activity.setContentView(Activity.java:2415)

at com.mplexvr.ribbonracker.RibbonRackerActivity.onCreate(RibbonRackerActivity.java:46)

at android.app.Activity.performCreate(Activity.java:6662)

at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)

at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2599)

at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2707)

at android.app.ActivityThread.-wrap12(ActivityThread.java)

at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1460)

at android.os.Handler.dispatchMessage(Handler.java:102)

at android.os.Looper.loop(Looper.java:154)

at android.app.ActivityThread.main(ActivityThread.java:6077)

at java.lang.reflect.Method.invoke(Native Method)

at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866)

at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:756)

我試圖使用版本為24的api在手機和仿真器上都運作此應用程式,但沒有任何效果。 onCreate()方法嘗試調用的我的activity_main.xml僅包含兩個在onCreate()方法中修改的片段。 這是其中的一段代碼:

@Override

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

images = new ArrayList<>();

imageNames = new ArrayList<>();

setContentView(R.layout.activity_main);

Log.v(TAG, "I got in onCreate");

//Create the fragment for the ranking and add it to the current view

// Get references to the TitleFragment and to the QuotesFragment containers

mRibbonFrameLayout = findViewById(R.id.ribbon_fragment_container);

mChecklistFrameLayout = findViewById(R.id.checkbox_fragment_container);

...

}

我嘗試查找此問題,但沒有發現任何解決問題的方法-至少是公開解決的。

UPDATE在5分鐘内解決了問題,當我發現某個檔案夾的版本為26,這将限制使用該版本。