天天看点

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,这将限制使用该版本。