为什么我会得到一个布局膨胀异常?

时间:2016-11-21 10:07:27

标签: android android-layout layout android-appbarlayout

这是我的登录activity.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"
    android:fitsSystemWindows="true"
    tools:context=".view.LoginActivity">

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/AppTheme.AppBarOverlay">

        <android.support.v7.widget.Toolbar
            android:id="@+id/login_screen_toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            app:popupTheme="@style/AppTheme.PopupOverlay" />

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

    <ScrollView
        android:layout_marginTop="?attr/actionBarSize"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <include layout="@layout/content_login" />
    </ScrollView>

这是我得到的例外,我无法理解我哪里出错了

FATAL EXCEPTION: main Process: com.mindtree.vishram, PID: 9699                                                                                                                 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.mindtree.vishram/com.mindtree.vishram.view.LoginActivity}: android.view.InflateException: Binary XML file line #34: Error inflating class EditText
                                                                at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2338)
                                                                at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2390)
                                                                at android.app.ActivityThread.access$800(ActivityThread.java:151)
                                                                at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1321)
                                                                at android.os.Handler.dispatchMessage(Handler.java:110)
                                                                at android.os.Looper.loop(Looper.java:193)
                                                                at android.app.ActivityThread.main(ActivityThread.java:5292)
                                                                at java.lang.reflect.Method.invokeNative(Native Method)
                                                                at java.lang.reflect.Method.invoke(Method.java:515)
                                                                at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:824)
                                                                at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:640)
                                                                at dalvik.system.NativeStart.main(Native Method)
                                                             Caused by: android.view.InflateException: Binary XML file line #34: Error inflating class EditText
                                                                at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:713)
                                                                at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
                                                                at android.view.LayoutInflater.rInflate(LayoutInflater.java:758)
                                                                at android.view.LayoutInflater.parseInclude(LayoutInflater.java:839)
                                                                at android.view.LayoutInflater.rInflate(LayoutInflater.java:745)
                                                                at android.view.LayoutInflater.rInflate(LayoutInflater.java:758)
                                                                at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
                                                                at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
                                                                at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
                                                                at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:284)
                                                                at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
                                                                at com.mindtree.vishram.view.LoginActivity.onCreate(LoginActivity.java:49)
                                                                at android.app.Activity.performCreate(Activity.java:5264)
                                                                at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1088)
                                                                at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2302)
                                                                at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2390) 
                                                                at android.app.ActivityThread.access$800(ActivityThread.java:151) 
                                                                at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1321) 
                                                                at android.os.Handler.dispatchMessage(Handler.java:110) 
                                                                at android.os.Looper.loop(Looper.java:193) 
                                                                at android.app.ActivityThread.main(ActivityThread.java:5292) 
                                                                at java.lang.reflect.Method.invokeNative(Native Method) 
                                                                at java.lang.reflect.Method.invoke(Method.java:515) 
                                                                at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:824) 
                                                                at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:640) 
                                                                at dalvik.system.NativeStart.main(Native Method) 
                                                             Caused by: android.content.res.Resources$NotFoundException: Resource is not a Drawable (color or path): TypedValue{t=0x1/d=0x7f020096 a=-1 r=0x7f020096}
                                                                at android.content.res.Resources.loadDrawable(Resources.java:2124)
                                                                at android.content.res.TypedArray.getDrawable(TypedArray.java:602)
                                                                at android.view.View.<init>(View.java:3579)
                                                                at android.widget.TextView.<init>(TextView.java:642)
                                                                at android.widget.EditText.<init>(EditText.java:60)
                                                                at android.support.v7.widget.AppCompatEditText.<init>(AppCompatEditText.java:59)
                                                                at android.support.v7.widget.AppCompatEditText.<init>(AppCompatEditText.java:55)
                                                                at android.support.v7.app.AppCompatViewInflater.createView(AppCompatViewInflater.java:112)
                                                                at android.support.v7.app.AppCompatDelegateImplV9.createView(AppCompatDelegateImplV9.java:1013)
                                                                at android.support.v7.app.AppCompatDelegateImplV9.onCreateView(AppCompatDelegateImplV9.java:1072)
                                                                at android.support.v4.view.LayoutInflaterCompatHC$FactoryWrapperHC.onCreateView(LayoutInflaterCompatHC.java:44)
                                                                at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:684)
                                                                at android.view.LayoutInflater.rInflate(LayoutInflater.java:755) 
                                                                at android.view.LayoutInflater.rInflate(LayoutInflater.java:758) 
                                                                at android.view.LayoutInflater.parseInclude(LayoutInflater.java:839) 
                                                                at android.view.LayoutInflater.rInflate(LayoutInflater.java:745) 
                                                                at android.view.LayoutInflater.rInflate(LayoutInflater.java:758) 
                                                                at android.view.LayoutInflater.inflate(LayoutInflater.java:492) 
                                                                at android.view.LayoutInflater.inflate(LayoutInflater.java:397) 
                                                                at android.view.LayoutInflater.inflate(LayoutInflater.java:353) 
                                                                at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:284) 
                                                                at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140) 
                                                                at com.mindtree.vishram.view.LoginActivity.onCreate(LoginActivity.java:49) 
                                                                at android.app.Activity.performCreate(Activity.java:5264) 
                                                                at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1088) 
                                                                at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2302) 
                                                                at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2390) 
                                                                at android.app.ActivityThread.access$800(ActivityThread.java:151) 
                                                                at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1321) 
                                                                at android.os.Handler.dispatchMessage(Handler.java:110) 
                                                                at android.os.Looper.loop(Looper.java:193) 
                                                                at android.app.ActivityThread.main(ActivityThread.java:5292) 
                                                                at java.lang.reflect.Method.invokeNative(Native Method) 
                                                                at java.lang.reflect.Method.invoke(Method.java:515) 
                                                                at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:824) 
                                                                at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:640) 
                                                                at dalvik.system.NativeStart.main(Native Method) 

这是我的登录活动

    public class LoginActivity extends AppCompatActivity implements LoginContract.View, RestManager.OnDataReceived {

    private static final String TAG = "LoginActivity";
    LoginContract.Presenter mLoginPresenter;
    LoginPresenter mPresenter;
    Button bt_register, bt_login;
    TextView tv_forgotpass;
    EditText et_useranme, et_password;
    CheckBox checkBox;
    ProgressDialog mLoginDialog;
    ProgressDialog mForgotPassDialog;
    Toolbar toolbar;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);
        toolbar = (Toolbar) findViewById(R.id.login_screen_toolbar);
        toolbar.setTitle("Login");
        mLoginDialog = new ProgressDialog(this);
        mForgotPassDialog = new ProgressDialog(this);
        bt_register = (Button) findViewById(R.id.bt_login_screen_register);
        bt_login = (Button) findViewById(R.id.bt_login_screen_login);
        mPresenter = new LoginPresenter(this);
        tv_forgotpass = (TextView) findViewById(R.id.tv_login_screen_forgot_password);
        et_useranme = (EditText) findViewById(R.id.et_login_screen_user_id);
        et_password = (EditText) findViewById(R.id.et_login_screen_user_pass);
        bt_register.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mPresenter.registerButtonClick(getApplicationContext());
            }
        });
        checkBox = (CheckBox) findViewById(R.id.cb_login_screen_show_pass);
        checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (isChecked) {
                    et_password.setInputType(InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD);
                } else {
                    et_password.setInputType(InputType.TYPE_TEXT_VARIATION_PASSWORD | InputType.TYPE_CLASS_TEXT);
                }

            }
        });
        bt_login.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                DisplayUtils.showProgressDialog(mLoginDialog, "Logging In...");
                // TODO: 9/8/2016 do the validations here    
                mLoginPresenter.onLoginClicked(LoginActivity.this, LoginActivity.this, et_useranme.getText().toString(), et_password.getText().toString());
                //change the vals
                //startActivity(new Intent(LoginActivity.this,DashboardActivity.class));
            }
        });
        tv_forgotpass.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                // check the username if exists on database..then make the
                //following call
                DisplayUtils.showProgressDialog(mForgotPassDialog, "Fetching your details...");
                mPresenter.forgotPasswordClick(LoginActivity.this, LoginActivity.this, et_useranme.getText().toString());
            }
        });

    }

    @Override
    public void removeLoginDialog() {
        DisplayUtils.dismissProgress(mLoginDialog);
    }

    @Override
    public void startDashActivity() {
        Intent i = new Intent(this, DashboardActivity.class);
        i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(i);
    }

    @Override
    public void startForgotPasswordActivity(UserInfo userInfo) {
        Intent i = new Intent(this, ForgotPasswordActivity.class);
        /*Toast.makeText(this, "email: " + userInfo.getEMailId().toString(), Toast.LENGTH_SHORT).show();
        Toast.makeText(this, "mobile: " + userInfo.getMobileNo().toString(), Toast.LENGTH_SHORT).show();
        Toast.makeText(this, "name: " + userInfo.getUserName().toString(), Toast.LENGTH_SHORT).show();*/
    //    Toast.makeText(this, userInfo.toString(), Toast.LENGTH_SHORT).show();
        i.putExtra("name",userInfo.getUserName());
       // i.putExtra("name",userInfo.getUserId());
        i.putExtra("email",userInfo.getEMailId());
        i.putExtra("mobile",userInfo.getMobileNo());
  //      Toast.makeText(this, "All put", Toast.LENGTH_SHORT).show();
//        Toast.makeText(this, userInfo.getUserId().toString(), Toast.LENGTH_SHORT).show();
        i.putExtra("id",userInfo.getUserId().toString());
        i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(i);
    }

    @Override
    public void setPresenter(LoginContract.Presenter presenter) {
        mLoginPresenter = checkNotNull(presenter);
    }

    @Override
    public void onResume() {
        super.onResume();
        // TODO: Call below method on click of login button
        mLoginPresenter.start();
    }

    @Override
    public void onDataSuccess(Object object, int type) {
        if (type == AppConstants.Extras.FOR_LOGIN) {
            DisplayUtils.dismissProgress(mLoginDialog);
            if (object instanceof UserInfo) {
                UserInfo userInfo = (UserInfo) object;
                //Log.d(TAG, "onDataSuccess: " + userInfo.toString());

               // Toast.makeText(this, userInfo.getUserName(), Toast.LENGTH_SHORT).show();
                // TODO: save the userInfo object in db
                // to save it in DB
                // ToDO: write below code in proper function (written in View interface)
                //startActivity(new Intent(this, LoginActivity.class));
                //save to shared preffs
                PreferencesHelper.writeToPreferences(getApplicationContext(),userInfo);
              //      Toast.makeText(this,PreferencesHelper.getUser(getApplicationContext()).toString(), Toast.LENGTH_SHORT).show();
                startDashActivity();
                finish();
            }
        } else if (type == AppConstants.Extras.FOR_FORGOTPASS) {
            DisplayUtils.dismissProgress(mForgotPassDialog);
      //      Toast.makeText(this, "inSide Success",      Toast.LENGTH_SHORT).show();
            if (object instanceof UserInfo) {
                UserInfo userInfo = (UserInfo) object;
        //        Toast.makeText(this, userInfo.getUserName(), Toast.LENGTH_SHORT).show();
                startForgotPasswordActivity(userInfo);
            }
        }
    }

    @Override
    public void onDataFailure(String error, int type) {
        if (type == AppConstants.Extras.FOR_LOGIN) {
            DisplayUtils.dismissProgress(mLoginDialog);
            Toast.makeText(this, error, Toast.LENGTH_SHORT).show();
        } else if (type == AppConstants.Extras.FOR_FORGOTPASS) {
            DisplayUtils.dismissProgress(mForgotPassDialog);
            Toast.makeText(this, error, Toast.LENGTH_SHORT).show();
        }
    }

    @Override
    public void removeForgotDialog() {
        DisplayUtils.dismissProgress(mForgotPassDialog);
    }
}

这是我的content_login.xml

    <?xml version="1.0" encoding="utf-8"?>

<RelativeLayout 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"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:context=".view.LoginActivity"
    tools:showIn="@layout/activity_login"
    android:background="@android:color/white">


    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:id="@+id/activity_main"
        android:layout_width="match_parent"
        android:background="@color/colorPrimaryLight"
        android:layout_height="wrap_content"
        android:paddingBottom="@dimen/activity_vertical_margin"
        android:paddingLeft="@dimen/activity_horizontal_margin"
        android:paddingRight="@dimen/activity_horizontal_margin"
        android:paddingTop="@dimen/activity_vertical_margin">

        <TextView
            android:text="PHONE NUMBER / EMAIL ID"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true"
            android:id="@+id/textView" />

        <EditText
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:inputType="textPersonName"
            android:ems="10"
            android:layout_below="@+id/textView"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true"
            android:id="@+id/et_login_screen_user_id"
            android:layout_alignParentRight="true"
            android:layout_alignParentEnd="true"
            android:background="@drawable/rounded_edittext"
            android:padding="20dp"
            android:layout_marginTop="4dp" />

        <TextView
            android:text="PASSWORD"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/et_login_screen_user_id"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true"
            android:layout_marginTop="16dp"
            android:id="@+id/textView2" />

        <EditText
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:inputType="textPassword"
            android:ems="10"
            android:layout_below="@+id/textView2"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true"
            android:id="@+id/et_login_screen_user_pass"
            android:layout_alignParentRight="true"
            android:layout_alignParentEnd="true"
            android:padding="20dp"
            android:background="@drawable/rounded_edittext"
            android:layout_marginTop="4dp" />

        <CheckBox
            android:text="Show Password"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/et_login_screen_user_pass"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true"
            android:id="@+id/cb_login_screen_show_pass"
            android:textColor="?android:attr/textColorTertiary" />

        <TextView
            android:layout_marginRight="8dp"
            android:textColor="@color/colorAccent"
            android:text="Forgot Password"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/tv_login_screen_forgot_password"
            android:layout_alignBaseline="@+id/cb_login_screen_show_pass"
            android:layout_alignBottom="@+id/cb_login_screen_show_pass"
            android:layout_alignParentRight="true"
            android:layout_alignParentEnd="true" />

    </RelativeLayout>

    <LinearLayout

        android:padding="20dp"
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/activity_main"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true">

        <Button
            android:id="@+id/bt_login_screen_login"
            android:layout_width="0dp"
            android:layout_weight="1"
            android:layout_height="wrap_content"
            android:layout_gravity="center_horizontal"
            android:layout_margin="20dp"
            android:background="@drawable/rounded_button"
            android:paddingBottom="20dp"
            android:paddingLeft="10dp"
            android:paddingRight="10dp"
            android:paddingTop="20dp"
            android:text="LOGIN"
            android:textColor="@color/colorPrimaryLight" />

        <Button
            android:layout_weight="1"
            android:id="@+id/bt_login_screen_register"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_gravity="center_horizontal"
            android:layout_margin="20dp"
            android:paddingTop="20dp"
            android:paddingBottom="20dp"
            android:background="@drawable/rounded_button"
            android:text="Register"
            android:textColor="@color/colorPrimaryLight" />


    </LinearLayout>


</RelativeLayout>

1 个答案:

答案 0 :(得分:1)

您的问题似乎是android:background="@drawable/rounded_edittext"中的ÈditText

正如您在堆栈跟踪中看到的那样,您可以进一步提示:

Caused by: android.content.res.Resources$NotFoundException: Resource is not a Drawable (color or path): TypedValue{t=0x1/d=0x7f020096 a=-1 r=0x7f020096}

在您的xml布局中,您拥有EditText

<EditText
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:inputType="textPersonName"
     android:ems="10"
     android:layout_below="@+id/textView"
     android:layout_alignParentLeft="true"
     android:layout_alignParentStart="true"
     android:id="@+id/et_login_screen_user_id"
     android:layout_alignParentRight="true"
     android:layout_alignParentEnd="true"
     android:background="@drawable/rounded_edittext" <-----------
     android:padding="20dp"
     android:layout_marginTop="4dp" />

看看那个drawable是不是问题。

编辑:

确保资源文件放在正确的资源文件夹中。例如,它应位于drawable中,而不是drawable-21中的