我在开发商的文档中发现了这个错误, 我不知道为什么。 我在这里的几部手机上测试了这个错误, 没有任何问题。
private Animation slideLeftIn;
private Animation slideLeftOut;
private Animation slideRightIn;
private Animation slideRightOut;
private void swipeInit() {
viewFlipper = (ecm2.android.ContentViewFlipper) findViewById(R.id.statusFlipper);
slideLeftIn = AnimationUtils.loadAnimation(this, R.anim.slide_left_in);
// line 2366 slideLeftOut = AnimationUtils.loadAnimation(this, R.anim.slide_left_out); //error
slideRightIn = AnimationUtils.loadAnimation(this, R.anim.slide_right_in);
slideRightOut = AnimationUtils.loadAnimation(this, R.anim.slide_right_out);
}
日志错误
java.lang.RuntimeException: Unable to start activity ComponentInfo{ecm2.android/ecm2.android.MainActivity}: java.lang.ClassCastException: android.widget.ViewFlipper
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1833)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1854)
at android.app.ActivityThread.access$1500(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1041)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:150)
at android.app.ActivityThread.main(ActivityThread.java:4333)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassCastException: android.widget.ViewFlipper
at ecm2.android.MainActivity.swipeInit(MainActivity.java:2366)
at ecm2.android.MainActivity.onCreate(MainActivity.java:837)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1072)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1797)
日志在第2366行写着它的位置, 这条线设置了动画中的动画之一, 但它做了之前的罚款, 所以我不确定这里有什么问题
动画 xml
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate android:fromXDelta="0" android:toXDelta="-100%p" android:duration="300"/>
这一切都从我换成自定义的查看滑动器以绕过一个机器人错误时开始。 我其实不做任何事情, 除了试图在 on Detached FromWindow
中捕捉一个例外, 它通常会做它通常会做的一切, 因为我在使用的一切中都叫超级
编辑:
内容视图翻翻类
public class ContentViewFlipper extends ViewFlipper {
//class is used to try to prevent force closes on certain phone where the onDetachFromWindow would be
//called when its not suppose to, this is an android bug
public ContentViewFlipper(Context context) {
super(context);
}
public ContentViewFlipper( Context context, AttributeSet attrs ) {
super( context, attrs );
}
@Override
protected void onDetachedFromWindow() {
try {
super.onDetachedFromWindow();
}
catch( Exception e ) {
stopFlipping();
}
}
}
视图声明翻页
private ContentViewFlipper viewFlipper;
XML 数字
<ecm2.android.ContentViewFlipper
android:id="@+id/statusFlipper"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:id="@+id/incLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="40dp"
android:orientation="vertical" >
<ListView
android:id="@+id/lvIncidents"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="50dp"
android:divider="@drawable/divider"
android:dividerHeight="2dip"
android:visibility="visible" >
</ListView>
</LinearLayout>
<LinearLayout
android:id="@+id/statusLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" android:layout_marginBottom="40dp">
<ListView
android:id="@+id/lvStatus"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:choiceMode="singleChoice"
android:divider="@drawable/divider"
android:dividerHeight="2dip"
android:visibility="visible" android:layout_marginTop="50dp">
</ListView>
</LinearLayout>
<LinearLayout
android:id="@+id/dlLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" android:layout_marginBottom="40dp">
<ListView
android:id="@+id/lvDistList"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:divider="@drawable/divider"
android:dividerHeight="2dip"
android:visibility="visible" android:layout_marginTop="50dp">
</ListView>
</LinearLayout>
<LinearLayout
android:id="@+id/emNotesLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" android:layout_marginBottom="40dp">
<ListView
android:id="@+id/lvEmNotes"
android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_marginTop="50dp">
</ListView>
</LinearLayout>
<LinearLayout
android:id="@+id/stCalenLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" android:layout_marginBottom="40dp">
<ListView
android:id="@+id/lvStCalendar"
android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_marginTop="50dp">
</ListView>
</LinearLayout>
</ecm2.android.ContentViewFlipper>