从抽屉

时间:2018-05-20 21:42:29

标签: android android-activity

我是Android开发的新手 当我从MainActivity调用Governance活动时,我的应用程序因调用特定活动而崩溃。(" GovernanaceActivity"是活动的名称)我的应用程序崩溃了,而其他菜单只对此活动有效。

这是MainActivity



package com.iridh.collegeapp;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.view.View;
import android.support.design.widget.NavigationView;
import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Button;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity
        implements NavigationView.OnNavigationItemSelectedListener {
    private static long back_pressed;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
        Button more1=(Button)findViewById(R.id.btn_more);
        more1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent= new Intent(MainActivity.this,GovernanceActivity.class);
                startActivity(intent);
            }
        });

        Button more2=(Button)findViewById(R.id.btn_more2);

        FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
        fab.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
                        .setAction("Action", null).show();
            }
        });

        DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
        ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
                this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
        drawer.addDrawerListener(toggle);
        toggle.syncState();

        NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
        navigationView.setNavigationItemSelectedListener(this);
    }

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

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }

    @SuppressWarnings("StatementWithEmptyBody")
    @Override
    public boolean onNavigationItemSelected(MenuItem item) {
        // Handle navigation view item clicks here.

        int id = item.getItemId();
        Intent showIntent = new Intent();

        if (id == R.id.nav_home) {
            // Handle the camera action
        } else if (id == R.id.nav_governance) {


>  //problem getting here

            showIntent = new Intent(MainActivity.this, GovernanceActivity.class);
            startActivity(showIntent);
            overridePendingTransition(R.anim.slide_in_up, R.anim.slide_out_up);

        } else if (id == R.id.nav_Campus) {
            showIntent = new Intent(MainActivity.this, CampusActivity.class);
            startActivity(showIntent);
            overridePendingTransition(R.anim.slide_in_up, R.anim.slide_out_up);

        } else if (id == R.id.nav_department) {
            showIntent = new Intent(MainActivity.this, DepartmentsActivity.class);
            startActivity(showIntent);
            overridePendingTransition(R.anim.slide_in_up, R.anim.slide_out_up);

        } else if (id == R.id.nav_admission) {
            showIntent = new Intent(MainActivity.this, AdmissionActivity.class);
            startActivity(showIntent);
            overridePendingTransition(R.anim.slide_in_up, R.anim.slide_out_up);

        } else if (id == R.id.nav_facilities) {
            showIntent = new Intent(MainActivity.this, FacilitiesActivity.class);
            startActivity(showIntent);
            overridePendingTransition(R.anim.slide_in_up, R.anim.slide_out_up);

        } else if (id == R.id.nav_gallery) {
            showIntent = new Intent(MainActivity.this, GalleryActivity.class);
            startActivity(showIntent);
            overridePendingTransition(R.anim.slide_in_up, R.anim.slide_out_up);

        } else if (id == R.id.nav_placement) {
            showIntent = new Intent(MainActivity.this, PlacementActivity.class);
            startActivity(showIntent);
            overridePendingTransition(R.anim.slide_in_up, R.anim.slide_out_up);

        } else if (id == R.id.nav_contact) {
            showIntent = new Intent(MainActivity.this, ContactActivity.class);
            startActivity(showIntent);
            overridePendingTransition(R.anim.slide_in_up, R.anim.slide_out_up);

        }

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

}




这就是所谓的GovernanceActivity



package com.iridh.collegeapp;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

public class GovernanceActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_governance);
    }
}




**所有其他活动正在运行这项活动只有问题

这是我的清单**



<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.iridh.collegeapp">

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity
            android:name=".MainActivity"
            android:label="@string/app_name"
            android:theme="@style/AppTheme.NoActionBar">
            <intent-filter>




















                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name=".GovernanceActivity"
            android:parentActivityName=".MainActivity" />

        <activity android:name=".CampusActivity"
            android:parentActivityName=".MainActivity"/>
        <activity android:name=".DepartmentsActivity"
            android:parentActivityName=".MainActivity"/>
        <activity android:name=".AdmissionActivity"
            android:parentActivityName=".MainActivity"/>
        <activity android:name=".FacilitiesActivity"
            android:parentActivityName=".MainActivity"/>
        <activity android:name=".GalleryActivity"
            android:parentActivityName=".MainActivity"/>
        <activity android:name=".DownloadActivity"
            android:parentActivityName=".MainActivity"/>
        <activity android:name=".PlacementActivity"
            android:parentActivityName=".MainActivity"/>
        <activity android:name=".ContactActivity"
            android:parentActivityName=".MainActivity">

        </activity>
    </application>

</manifest>
&#13;
&#13;
&#13;

我正在附加日志

  

块引用   05-21 03:09:53.747 1823-1823 / com.iridh.collegeapp D / AndroidRuntime:关闭VM   05-21 03:09:53.752 1823-1823 / com.iridh.collegeapp E / AndroidRuntime:FATAL EXCEPTION:main       过程:com.iridh.collegeapp,PID:1823       java.lang.RuntimeException:无法启动活动ComponentInfo {com.iridh.collegeapp / com.iridh.collegeapp.GovernanceActivity}:android.view.InflateException:二进制XML文件行#288:二进制XML文件行#288:错误膨胀类的TextView           在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3194)           在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3302)           在android.app.ActivityThread.-wrap12(未知来源:0)           在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1891)           在android.os.Handler.dispatchMessage(Handler.java:108)           在android.os.Looper.loop(Looper.java:166)           在android.app.ActivityThread.main(ActivityThread.java:7425)           at java.lang.reflect.Method.invoke(Native Method)           在com.android.internal.os.Zygote $ MethodAndArgsCaller.run(Zygote.java:245)           在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:921)        引起:android.view.InflateException:二进制XML文件行#288:二进制XML文件行#288:错误膨胀类TextView        引起:android.view.InflateException:二进制XML文件行#288:错误膨胀类TextView        引起:android.content.res.Resources $ NotFoundException:文件res / drawable / black.jpg来自可绘制资源ID#0x7f08005c:.xml扩展名需要           在android.content.res.ResourcesImpl.loadComplexColorForCookie(ResourcesImpl.java:1371)           在android.content.res.ResourcesImpl.loadComplexColorFromName(ResourcesImpl.java:1190)           在android.content.res.ResourcesImpl.loadColorStateList(ResourcesImpl.java:1271)           在android.content.res.Resources.loadColorStateList(Resources.java:1180)           在android.content.res.HwResources.loadColorStateList(HwResources.java:289)           在android.content.res.TypedArray.getColorStateList(TypedArray.java:572)           在android.widget.TextView。(TextView.java:1291)           在android.widget.TextView。(TextView.java:872)           在android.support.v7.widget.AppCompatTextView。(AppCompatTextView.java:76)           在android.support.v7.widget.AppCompatTextView。(AppCompatTextView.java:72)           在android.support.v7.app.AppCompatViewInflater.createTextView(AppCompatViewInflater.java:176)           在android.support.v7.app.AppCompatViewInflater.createView(AppCompatViewInflater.java:101)           在android.support.v7.app.AppCompatDelegateImplV9.createView(AppCompatDelegateImplV9.java:1035)           在android.support.v7.app.AppCompatDelegateImplV9.onCreateView(AppCompatDelegateImplV9.java:1092)           在android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:783)           在android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:741)           在android.view.LayoutInflater.rInflate(LayoutInflater.java:874)           在android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:835)           在android.view.LayoutInflater.rInflate(LayoutInflater.java:877)           在android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:835)           在android.view.LayoutInflater.rInflate(LayoutInflater.java:877)           在android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:835)           在android.view.LayoutInflater.rInflate(LayoutInflater.java:877)           在android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:835)           在android.view.LayoutInflater.inflate(LayoutInflater.java:515)           在android.view.LayoutInflater.inflate(LayoutInflater.java:423)           在android.view.LayoutInflater.inflate(LayoutInflater.java:374)           在android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:287)           在android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139)           在com.iridh.collegeapp.GovernanceActivity.onCreate(GovernanceActivity.java:11)           在android.app.Activity.performCreate(Activity.java:7372)           在android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1218)           在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3147)           在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3302)           在android.app.ActivityThread.-wrap12(未知来源:0)           在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1891)           在android.os.Handler.dispatchMessage(Handler.java:108)           在android.os.Looper.loop(Looper.java:166)           在android.app.ActivityThread.main(ActivityThread.java:7425)           at java.lang.reflect.Method.invoke(Native Method)           在com.android.internal.os.Zygote $ MethodAndArgsCaller.run(Zygote.java:245)           在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:921)

在那里发生了什么我无法调试它 在此先感谢。

此My GovernanceActivity附加布局 activity_governance

&#13;
&#13;
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
    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">
    <android.support.v7.widget.LinearLayoutCompat
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:padding="16dp"
        android:id="@+id/governance_lyt"
        android:background="@drawable/ic_menu_header_background">

        <android.support.v7.widget.CardView
            android:layout_width="match_parent"
            android:layout_height="50dp"
            android:elevation="100dp"
            android:layout_gravity="center_horizontal"
            android:layout_marginTop="20dp">

            <RelativeLayout
                android:id="@+id/title_lyt"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="#FF941020">

                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_alignParentStart="true"
                    android:layout_alignParentTop="true"
                    android:gravity="center"
                    android:textColor="#FFFFFF"
                    android:text="GOVERNANACE"
                    android:textSize="25dp"
                    android:textStyle="bold"
                    app:fontFamily="@font/android"
                    android:layout_alignParentLeft="true" />
            </RelativeLayout>


        </android.support.v7.widget.CardView>
        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="     "
                android:textSize="15dp" />

        </RelativeLayout>
        <View
            android:layout_width="match_parent"
            android:layout_height="1dp"
            android:paddingTop="20dp"
            android:background="@android:color/darker_gray">

        </View>

        <android.support.v7.widget.CardView
            android:layout_width="100dp"
            android:layout_height="100dp"
            android:elevation="12dp"
            android:shape="ring"
            android:innerRadius="0dp"
            android:layout_gravity="center"
            android:thicknessRatio="1.9"
            android:layout_centerHorizontal="true">

            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

                <ImageView
                    android:layout_width="match_parent"
                    android:layout_height="100dp"
                    android:layout_centerHorizontal="true"
                    android:layout_centerVertical="true"
                    android:src="@drawable/ic_president" />
            </RelativeLayout>



        </android.support.v7.widget.CardView>
        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:gravity="center"
                android:text="Shree Shankarprasad Agnihotri"
                android:textSize="22dp"
                android:textStyle="bold"
                android:textColor="#263238"/>
        </RelativeLayout>
        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:gravity="center"
                android:text="President"
                android:textSize="17dp"
                android:textStyle="bold"
                android:textColor="#666666"/>
        </RelativeLayout>
        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="     "
                android:textSize="15dp" />

        </RelativeLayout>


        <android.support.v7.widget.CardView
            android:layout_width="match_parent"
            android:layout_height="25dp"
            android:layout_gravity="center_horizontal"
            android:layout_marginTop="10dp"
            android:elevation="100dp">

            <RelativeLayout
                android:id="@+id/title_lyt3"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="#00e676">

                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_alignParentStart="true"
                    android:layout_alignParentTop="true"
                    android:gravity="center"
                    android:text="Message"
                    android:textColor="#000000"
                    android:textSize="20dp"
                    android:textStyle="bold"
                    app:fontFamily="@font/android"
                    android:layout_alignParentLeft="true" />
            </RelativeLayout>




        </android.support.v7.widget.CardView>
        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <TextView
                android:layout_width="349dp"
                android:layout_height="match_parent"
                android:layout_alignParentEnd="true"
                android:layout_alignParentRight="true"
                android:layout_centerVertical="true"
                android:layout_marginTop="20dp"
                android:gravity="center"
                android:text="@string/president"
                android:textSize="17dp" />
        </RelativeLayout>

        <View
            android:layout_width="match_parent"
            android:layout_height="1dp"
            android:paddingTop="20dp"
            android:background="@android:color/darker_gray">

        </View>

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">
            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="     "/>

        </RelativeLayout>

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">
            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="     "/>

        </RelativeLayout>
        <View
            android:layout_width="match_parent"
            android:layout_height="1dp"
            android:paddingTop="20dp"
            android:background="@android:color/darker_gray">

        </View>

        <android.support.v7.widget.CardView
            android:layout_width="100dp"
            android:layout_height="100dp"
            android:elevation="12dp"
            android:shape="ring"
            android:innerRadius="0dp"
            android:layout_gravity="center"
            android:thicknessRatio="1.9"
            android:layout_centerHorizontal="true">

            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

                <ImageView
                    android:layout_width="match_parent"
                    android:layout_height="100dp"
                    android:layout_centerHorizontal="true"
                    android:layout_centerVertical="true"
                    android:src="@drawable/ic_secretary" />
            </RelativeLayout>



        </android.support.v7.widget.CardView>
        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:gravity="center"
                android:text="Sachin S. Agnihotri"
                android:textSize="22dp"
                android:textStyle="bold"
                android:textColor="#263238"/>
        </RelativeLayout>
        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:gravity="center"
                android:text="Secretary"
                android:textSize="17dp"
                android:textStyle="bold"
                android:textColor="#666666"/>
        </RelativeLayout>
        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="     "
                android:textSize="15dp" />

        </RelativeLayout>


        <android.support.v7.widget.CardView
            android:layout_width="match_parent"
            android:layout_height="25dp"
            android:layout_gravity="center_horizontal"
            android:layout_marginTop="10dp"
            android:elevation="100dp"
            >

            <RelativeLayout
                android:id="@+id/title_lyt2"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background=" #00e676">

                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_alignParentStart="true"
                    android:layout_alignParentTop="true"
                    android:gravity="center"
                    android:text="Message"
                    android:textSize="20dp"
                    android:textColor="@drawable/black"
                    android:textStyle="bold"
                    app:fontFamily="@font/android"
                    android:layout_alignParentLeft="true" />
            </RelativeLayout>




        </android.support.v7.widget.CardView>
        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <TextView
                android:layout_width="349dp"
                android:layout_height="match_parent"
                android:layout_alignParentEnd="true"
                android:layout_alignParentRight="true"
                android:layout_centerVertical="true"
                android:layout_marginTop="20dp"
                android:gravity="center"
                android:text="@string/secretary"
                android:textSize="17dp" />
        </RelativeLayout>
        <View
            android:layout_width="match_parent"
            android:layout_height="1dp"
            android:paddingTop="20dp"
            android:background="@android:color/darker_gray">

        </View>
    </android.support.v7.widget.LinearLayoutCompat>

</ScrollView>
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:0)

您必须将文件black.jpg重命名为black.xml,假设它是XML资源(如形状或选择器),或者black.png,以防它是图像。

这是你的错误:

  

错误膨胀类TextView引起:android.view.InflateException:二进制XML文件行#288:错误膨胀类TextView引起:android.content.res.Resources $ NotFoundException:来自drawable的文件res / drawable / black.jpg资源ID#0x7f08005c.xml扩展名

编辑:

这是您的错误:

           <TextView
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_alignParentStart="true"
                android:layout_alignParentTop="true"
                android:gravity="center"
                android:text="Message"
                android:textSize="20dp"
                android:textColor="@drawable/black" <-- ERROR HERE
                android:textStyle="bold"
                app:fontFamily="@font/android"
                android:layout_alignParentLeft="true" />

您在textColor设置drawable,并且应该是color资源。可以是@color/black(黑色应该在colors.xml中定义为<color name="black">#000000</color>,或者可以是文字(android:textColor="#000000")。