应用程式当机'android.content.res.Resources $ NotFoundException'错误

时间:2019-05-12 12:00:55

标签: android android-actionbar navigation-drawer

我最近在我的应用程序中添加了一个导航抽屉(因此实际上添加了几个新文件)这是我第一次使用导航抽屉。但是,不幸的是,当我启动SecondActivity时,该应用程序崩溃了,该链接实际上链接到导航抽屉,从而在手机上显示了报告错误:

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.harjotapp/com.example.harjotapp.SecondActivity}: android.content.res.Resources$NotFoundException: String resource ID #0x31
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2843)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2921)
    at android.app.ActivityThread.-wrap11(Unknown Source:0)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1639)
    at android.os.Handler.dispatchMessage(Handler.java:106)
    at android.os.Looper.loop(Looper.java:176)
    at android.app.ActivityThread.main(ActivityThread.java:6662)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:547)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:873)
Caused by: android.content.res.Resources$NotFoundException: String resource ID #0x31
    at android.content.res.Resources.getText(Resources.java:351)
    at android.content.res.MiuiResources.getText(MiuiResources.java:97)
    at android.content.Context.getText(Context.java:552)
    at android.support.v7.widget.Toolbar.setNavigationContentDescription(Toolbar.java:903)
    at android.support.v7.app.ActionBarDrawerToggle$ToolbarCompatDelegate.setActionBarDescription(ActionBarDrawerToggle.java:608)
    at android.support.v7.app.ActionBarDrawerToggle$ToolbarCompatDelegate.setActionBarUpIndicator(ActionBarDrawerToggle.java:600)
    at android.support.v7.app.ActionBarDrawerToggle.setActionBarUpIndicator(ActionBarDrawerToggle.java:495)
    at android.support.v7.app.ActionBarDrawerToggle.syncState(ActionBarDrawerToggle.java:242)
    at com.example.harjotapp.SecondActivity.onCreate(SecondActivity.java:178)
    at android.app.Activity.performCreate(Activity.java:7074)
    at android.app.Activity.performCreate(Activity.java:7065)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1214)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2796)



…

我知道已经问过这种错误。我曾尝试清洁和建造,但没有任何反应。我认为导航抽屉的实现存在错误。因此,我附上了文件,以防万一有人能够指出错误,我将不胜感激。

activity_main_drawer.xml

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    tools:showIn="navigation_view">

    <group android:checkableBehavior="single">
        <item
            android:id="@+id/nav_camera"

            android:title="Import" />
        <item
            android:id="@+id/nav_gallery"

            android:title="Gallery" />
        <item
            android:id="@+id/nav_slideshow"

            android:title="Slideshow" />
        <item
            android:id="@+id/nav_manage"

            android:title="Tools" />
    </group>

    <item android:title="Communicate">
        <menu>
            <item
                android:id="@+id/nav_share"

                android:title="Share" />
            <item
                android:id="@+id/nav_send"

                android:title="Send" />
        </menu>
    </item>

</menu>

SecondActivity.java

package com.example.harjotapp;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.preference.Preference;
import android.preference.PreferenceManager;
import android.support.v4.view.GravityCompat;
import android.support.v7.app.ActionBar;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.view.Gravity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
import android.support.design.widget.NavigationView;
import android.support.v4.widget.DrawerLayout;


import org.w3c.dom.Text;


public class SecondActivity extends AppCompatActivity implements
        NavigationView.OnNavigationItemSelectedListener{

    private Button mTrueButton;
    private static final String KEY_INDEX="index";
    private static final String CHEAT_VALS="cheat";
    private Button mFalseButton;
    private Button mNextButton;
    private Button mPrevButton;
    private Button mCheatButton;
    private int mAnswered_count=0;
    public static TextView mUserView;
    private TextView mScore;
    private int mScoreval;
    private TextView mAnswered;
    private boolean[] cheatvals={false,false,false,false,false,false};


    @SuppressWarnings("StatementWithEmptyBody")

    @Override
    public boolean onNavigationItemSelected(MenuItem item) {
        int id = item.getItemId();
        // Handle the actions accordingly for all menus
        if (id == R.id.nav_camera) {
        } else if (id == R.id.nav_gallery) {

        } else if (id == R.id.nav_slideshow) {

        } else if (id == R.id.nav_manage) {

        } else if (id == R.id.nav_share) {

        } else if (id == R.id.nav_send) {

        }

        DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
        drawer.closeDrawer(GravityCompat.START);
        return true;
    }


    private int mCurrentIndex=0;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        String recv=getIntent().getStringExtra("game");


        setContentView(R.layout.nav_layout);
        Toolbar toolbar=(Toolbar)findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
        DrawerLayout drawer=(DrawerLayout)findViewById(R.id.drawer_layout);
        ActionBarDrawerToggle toggle=new ActionBarDrawerToggle(this,drawer,toolbar,'1',0);
        drawer.addDrawerListener(toggle);
        toggle.syncState();
        NavigationView navigationView=(NavigationView)findViewById(R.id.nav_view);
        navigationView.setNavigationItemSelectedListener(this);







  #the majority of code was present earlier and was working perfectly fine. I don't think it has something todo with the error







    }
    @Override
    public void onBackPressed()
    {
        DrawerLayout drawer=(DrawerLayout)findViewById(R.id.drawer_layout);
        if(drawer.isDrawerOpen(GravityCompat.START))
        {
            drawer.closeDrawer(GravityCompat.START);
        }
        else{
            super.onBackPressed();
        }
    }



}

nav_header_main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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="250dp"
    android:background="@color/colorPrimary"
    android:gravity="bottom"
    android:orientation="vertical"
    android:paddingBottom="20dp"
    android:paddingLeft="20dp"
    android:paddingRight="20dp"
    android:paddingTop="20dp"
    android:theme="@style/ThemeOverlay.AppCompat.Dark">

    <ImageView
        android:id="@+id/imageView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:paddingTop="50dp"
        app:srcCompat="@mipmap/ic_launcher_round" />

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:paddingTop="5dp"
        android:text="Geo Quiz"
        android:textColor="#ffff99"
        android:textSize="15dp"
        android:textStyle="bold"
        android:textAppearance="@style/TextAppearance.AppCompat.Body1" />

    <TextView
        android:id="@+id/textView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="harjoting7@gmail.com"
        android:textColor="#ffff99"
        />

</LinearLayout>

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".SecondActivity"
    android:background="#ffff99">
    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/NoActionBar"
        >
      <android.support.v7.widget.Toolbar
          android:layout_width="match_parent"
          android:layout_height="25dp"
          android:id="@+id/toolbar"
          android:background="@color/colorPrimary"
          />

    </android.support.design.widget.AppBarLayout>


<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center_horizontal"
    android:background="@drawable/world_black"
    android:orientation="vertical"
    >

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="end"
        android:layout_marginTop="0dp"
        android:textColor="#ffff99"
        android:paddingTop="5dp"

        android:paddingRight="5dp"
        android:textAlignment="textEnd"
        android:textSize="15dp"
        android:background="#345953"
        android:id="@+id/user_view"
        android:textStyle="bold" />
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        >

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="start"
            android:layout_marginTop="0dp"
            android:textColor="#ffff99"
            android:paddingTop="5dp"
            android:textSize="30dp"
            android:paddingLeft="5dp"
            android:id="@+id/progress_view"
            android:textStyle="bold"
            android:layout_weight="1"
            android:background="#58857e"
            />

        <TextView
            android:id="@+id/score_view"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="end"
            android:layout_marginTop="0dp"
            android:layout_marginRight="0dp"
            android:paddingTop="5dp"
            android:paddingRight="5dp"

            android:textAlignment="viewEnd"
            android:layout_weight="1"
            android:textColor="#ffff99"
            android:textSize="30dp"
            android:textStyle="bold"
            android:background="#58857e"/>
    </LinearLayout>


    <TextView
        android:layout_marginTop="180dp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/question_text_view"
        android:gravity="center_horizontal"

        android:textColor="#ffffff"
        android:textSize="20dp"

        android:padding="24dp"/>
    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal">

        <Button
            android:id="@+id/true_button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"


            android:text="@string/true_button"
            />
        <Button
            android:id="@+id/false_button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/false_button"
            />
    </LinearLayout>
    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/cheat_button"
        android:text="@string/cheat_button"
        android:textColor="#ffff99"
        android:background="@drawable/mybutton"

        />
    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal">


        <Button
            android:id="@+id/previous_button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/previous_button"
            android:drawableLeft="@mipmap/larrow"
            android:padding="4dp"


            />

        <Button
            android:id="@+id/next_button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/next_button"
            android:drawableRight="@mipmap/rarrow"
            android:padding="4dp"
            />
    </LinearLayout>

</LinearLayout>
</android.support.design.widget.CoordinatorLayout>

nav_layout.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
    xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_height="match_parent"
    android:id="@+id/drawer_layout"
    tools:openDrawer="start"
    android:background="#ffff99"
    android:fitsSystemWindows="true">

    <include
        layout="@layout/activity_main"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        />
    <android.support.design.widget.NavigationView
        android:id="@+id/nav_view"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:fitsSystemWindows="true"
        app:headerLayout="@layout/nav_header_main"
        app:menu="@menu/activity_main_drawer"

        />

</android.support.v4.widget.DrawerLayout>

0 个答案:

没有答案