阻止手机

时间:2018-01-28 12:10:10

标签: android android-fragments android-resources

当手机屏幕被阻止时,我在Fragment.onCreateView()中发现了Android资源未找到异常。当我使用应用程序而不阻挡屏幕时,它完美地工作。有什么问题?

错误消息:

  

java.lang.RuntimeException:无法启动活动ComponentInfo {com.example.hmmmk.pizzamania / com.example.hmmmk.pizzamani.mvp.main.MainActivity}:android.content.res.Resources $ NotFoundException:Resource ID #0x7f0b002e                                                          在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2695)                                                          在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2769)                                                          在android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:4378)                                                          在android.app.ActivityThread.access $ 1000(ActivityThread.java:177)                                                          在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1436)                                                          在android.os.Handler.dispatchMessage(Handler.java:102)                                                          在android.os.Looper.loop(Looper.java:135)                                                          在android.app.ActivityThread.main(ActivityThread.java:5910)                                                          at java.lang.reflect.Method.invoke(Native Method)                                                          在java.lang.reflect.Method.invoke(Method.java:372)                                                          在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:1405)                                                          在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1200)                                                       引起:android.content.res.Resources $ NotFoundException:资源ID#0x7f0b002e                                                          在android.content.res.Resources.getValue(Resources.java:1532)                                                          在android.content.res.Resources.loadXmlResourceParser(Resources.java:3102)                                                          在android.content.res.Resources.getLayout(Resources.java:1348)                                                          在android.view.LayoutInflater.inflate(LayoutInflater.java:412)                                                          在com.example.hmmmk.pizzamani.mvp.menurest.MenuFragment.onCreateView(MenuFragment.java:75)                                                          在android.app.Fragment.performCreateView(Fragment.java:2112)                                                          在android.app.FragmentManagerImpl.moveToState(FragmentManager.java:904)                                                          在android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1083)                                                          在android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1065)                                                          在android.app.FragmentManagerImpl.dispatchActivityCreated(FragmentManager.java:1885)                                                          在android.app.Activity.performCreateCommon(Activity.java:6173)                                                          在android.app.Activity.performCreate(Activity.java:6199)                                                          在android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)                                                          在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2648)

来源:

@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_menu_restmenu, container, false);
    init(view);
    presenter.attachView(this);

    //FIXME: убрать эту хйню
    view.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
        @Override
        public void onGlobalLayout() {

            if (!flag) {
                headersList.performItemClick(headersList.getChildAt(0), 0, 0);
                flag = true;
            }
        }
    });

    return view;
}

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <ListView
        android:id="@+id/headers_list"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:background="#fff"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toStartOf="@+id/content_list"
        app:layout_constraintHeight_default="spread"
        app:layout_constraintHorizontal_weight="1"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintWidth_default="spread" />

    <android.support.v7.widget.RecyclerView
        android:id="@+id/content_list"
        android:layout_width="0dp"
        android:layout_height="0dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHeight_default="spread"
        app:layout_constraintHorizontal_weight="2.5"
        app:layout_constraintStart_toEndOf="@+id/headers_list"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintWidth_default="spread" />
</android.support.constraint.ConstraintLayout>

0 个答案:

没有答案