English 中文(简体)
设置动动画时的分类例外
原标题:ClassCastException when setting an animation

我在开发商的文档中发现了这个错误, 我不知道为什么。 我在这里的几部手机上测试了这个错误, 没有任何问题。

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>
问题回答

我猜可能与行号有些混淆, 您的对象视图Flipper 被定义为 ViewFlipper 视图Flipper, 这在您从 ecm2. android 投出时可能会引起问题 。 ContentViewFlipper 如果它不是降级的话 。

例外情况是,错误发生于弹出 和roid.widget.ViewFlipper , 我很确定 viewFlipper =... 线的两边都有错误的类型。

要么viewFlipper 变量是 android.widget.ViewFlipper , 由布局控制为ecm2.android.ContentViewFlipper ,不能投到android.widget.ViewFlipper ,或者布局中的控制为 android.widget.ViewFlipper ,不能投到ec>em2.android.ContentVipper

在设置 viewFlipper =... 线的断点后以调试模式单步跳过代码时,错误真正发生在哪一行?





相关问题
Android - ListView fling gesture triggers context menu

I m relatively new to Android development. I m developing an app with a ListView. I ve followed the info in #1338475 and have my app recognizing the fling gesture, but after the gesture is complete, ...

AsyncTask and error handling on Android

I m converting my code from using Handler to AsyncTask. The latter is great at what it does - asynchronous updates and handling of results in the main UI thread. What s unclear to me is how to handle ...

Android intent filter for a particular file extension?

I want to be able to download a file with a particular extension from the net, and have it passed to my application to deal with it, but I haven t been able to figure out the intent filter. The ...

Android & Web: What is the equivalent style for the web?

I am quite impressed by the workflow I follow when developing Android applications: Define a layout in an xml file and then write all the code in a code-behind style. Is there an equivalent style for ...

TiledLayer equivalent in Android [duplicate]

To draw landscapes, backgrounds with patterns etc, we used TiledLayer in J2ME. Is there an android counterpart for that. Does android provide an option to set such tiled patterns in the layout XML?

Using Repo with Msysgit

When following the Android Open Source Project instructions on installing repo for use with Git, after running the repo init command, I run into this error: /c/Users/Andrew Rabon/bin/repo: line ...

Android "single top" launch mode and onNewIntent method

I read in the Android documentation that by setting my Activity s launchMode property to singleTop OR by adding the FLAG_ACTIVITY_SINGLE_TOP flag to my Intent, that calling startActivity(intent) would ...

From Web Development to Android Development

I have pretty good skills in PHP , Mysql and Javascript for a junior developer. If I wanted to try my hand as Android Development do you think I might find it tough ? Also what new languages would I ...

热门标签