我的应用程序在Android L上崩溃,但它适用于android kitkat。此外,布局上没有RippleDrawable。这是异常和布局;
Xml布局:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/page_background">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"
android:inputType="textEmailAddress"
android:ems="10"
android:id="@+id/usernameET"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="100dp"
android:hint="@string/username_hint" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"
android:inputType="textPassword"
android:ems="10"
android:id="@+id/passwordET"
android:layout_below="@+id/usernameET"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp"
android:hint="@string/password_hint" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="60dp"
android:layout_marginRight="60dp"
android:text="@string/login_text"
android:id="@+id/loginBtn"
android:background="@drawable/positive_button_selector"
android:textColor="#fff"
android:layout_below="@+id/passwordET"
android:layout_centerHorizontal="true"
android:layout_marginTop="40dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/register_text"
android:id="@+id/registerText"
android:layout_below="@+id/loginBtn"
android:layout_marginLeft="50dp"
android:layout_marginTop="40dp"
android:textColor="@color/accent_color"
android:textSize="16sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/forget_password"
android:id="@+id/forgetText"
android:layout_below="@+id/registerText"
android:layout_marginLeft="50dp"
android:layout_marginTop="20dp"
android:textColor="@color/accent_color"
android:textSize="16sp" />
</RelativeLayout>
Drawable xml&#39; positive_button_selector&#39; :
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="false">
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<solid android:color="@color/accent_color" />
<corners android:radius="4dp" />
</shape>
</item>
<item android:state_pressed="true">
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<solid android:color="@color/teal_light" />
<corners android:radius="4dp" />
</shape>
</item>
</selector>
例外:
> java.lang.NullPointerException: Attempt to invoke virtual method 'int android.content.res.ColorStateList.getColorForState(int[], int)' on a null object reference
at android.graphics.drawable.RippleDrawable.activateHotspot(RippleDrawable.java:413)
at android.graphics.drawable.RippleDrawable.setActive(RippleDrawable.java:229)
at android.graphics.drawable.RippleDrawable.onStateChange(RippleDrawable.java:207)
at android.graphics.drawable.Drawable.setState(Drawable.java:566)
at android.view.View.drawableStateChanged(View.java:15576)
at android.widget.TextView.drawableStateChanged(TextView.java:3477)
at android.view.View.refreshDrawableState(View.java:15594)
at android.view.View.handleFocusGainInternal(View.java:4779)
at android.view.View.requestFocusNoSearch(View.java:7335)
at android.view.View.requestFocus(View.java:7314)
at android.view.ViewGroup.onRequestFocusInDescendants(ViewGroup.java:2492)
at android.view.ViewGroup.requestFocus(ViewGroup.java:2448)
at android.view.ViewGroup.onRequestFocusInDescendants(ViewGroup.java:2492)
at android.view.ViewGroup.requestFocus(ViewGroup.java:2448)
at android.view.ViewGroup.onRequestFocusInDescendants(ViewGroup.java:2492)
at android.view.ViewGroup.requestFocus(ViewGroup.java:2448)
at android.view.ViewGroup.onRequestFocusInDescendants(ViewGroup.java:2492)
at android.view.ViewGroup.requestFocus(ViewGroup.java:2448)
at android.view.ViewGroup.onRequestFocusInDescendants(ViewGroup.java:2492)
at android.view.ViewGroup.requestFocus(ViewGroup.java:2448)
at android.view.ViewGroup.onRequestFocusInDescendants(ViewGroup.java:2492)
at android.view.ViewGroup.requestFocus(ViewGroup.java:2448)
at android.view.ViewGroup.onRequestFocusInDescendants(ViewGroup.java:2492)
at android.view.ViewGroup.requestFocus(ViewGroup.java:2448)
at android.view.ViewGroup.onRequestFocusInDescendants(ViewGroup.java:2492)
at android.view.ViewGroup.requestFocus(ViewGroup.java:2448)
at android.view.ViewGroup.onRequestFocusInDescendants(ViewGroup.java:2492)
at android.view.ViewGroup.requestFocus(ViewGroup.java:2451)
at android.view.View.requestFocus(View.java:7281)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1898)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1044)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5749)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:767)
at android.view.Choreographer.doCallbacks(Choreographer.java:580)
at android.view.Choreographer.doFrame(Choreographer.java:550)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:753)
at android.os.Handler.handleCallback(Handler.java:738)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5070)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:836)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:631)
答案 0 :(得分:3)
此问题是由旧版Lollipop引起的。如果您将设备更新到最新的预览版本,则不会再看到此崩溃。
评论中提到崩溃发生在2014年7月发布的LPV81C版本中。截至2014年10月27日的最新预览版本是LPX13D,没有此问题。