致命异常:main:java.lang.RuntimeException:

时间:2014-01-17 17:09:22

标签: android

不幸的是,App已经越过了我得到的信息。我正在使用Yamba应用程序并尝试使用ViewBinder在RelativelineActivity中使用relativeTimeSpan发布状态消息。以下是LogCat:

01-17 16:57:11.064: W/EGL_genymotion(1260): eglSurfaceAttrib not implemented
01-17 16:57:12.528: D/dalvikvm(1260): GC_FOR_ALLOC freed 132K, 12% free 2766K/3124K, paused 2ms, total 2ms
01-17 16:57:12.528: I/dalvikvm-heap(1260): Grow heap (frag case) to 3.994MB for 1127532-byte allocation
01-17 16:57:12.532: D/dalvikvm(1260): GC_FOR_ALLOC freed 4K, 9% free 3863K/4228K, paused 3ms, total 3ms
01-17 16:57:12.568: D/AndroidRuntime(1260): Shutting down VM
01-17 16:57:12.568: W/dalvikvm(1260): threadid=1: thread exiting with uncaught exception (group=0xa4bdf648)
01-17 16:57:12.568: E/AndroidRuntime(1260): FATAL EXCEPTION: main
01-17 16:57:12.568: E/AndroidRuntime(1260): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.yamba/com.example.yamba.TimelineActivity}: java.lang.ClassCastException: com.example.yamba.TimelineActivity$1 cannot be cast to android.support.v4.widget.SimpleCursorAdapter$ViewBinder
01-17 16:57:12.568: E/AndroidRuntime(1260):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2211)
01-17 16:57:12.568: E/AndroidRuntime(1260):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
01-17 16:57:12.568: E/AndroidRuntime(1260):     at android.app.ActivityThread.access$600(ActivityThread.java:141)
01-17 16:57:12.568: E/AndroidRuntime(1260):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
01-17 16:57:12.568: E/AndroidRuntime(1260):     at android.os.Handler.dispatchMessage(Handler.java:99)
01-17 16:57:12.568: E/AndroidRuntime(1260):     at android.os.Looper.loop(Looper.java:137)
01-17 16:57:12.568: E/AndroidRuntime(1260):     at android.app.ActivityThread.main(ActivityThread.java:5103)
01-17 16:57:12.568: E/AndroidRuntime(1260):     at java.lang.reflect.Method.invokeNative(Native Method)
01-17 16:57:12.568: E/AndroidRuntime(1260):     at java.lang.reflect.Method.invoke(Method.java:525)
01-17 16:57:12.568: E/AndroidRuntime(1260):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
01-17 16:57:12.568: E/AndroidRuntime(1260):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
01-17 16:57:12.568: E/AndroidRuntime(1260):     at dalvik.system.NativeStart.main(Native Method)
01-17 16:57:12.568: E/AndroidRuntime(1260): Caused by: java.lang.ClassCastException: com.example.yamba.TimelineActivity$1 cannot be cast to android.support.v4.widget.SimpleCursorAdapter$ViewBinder
01-17 16:57:12.568: E/AndroidRuntime(1260):     at com.example.yamba.TimelineActivity.onCreate(TimelineActivity.java:42)
01-17 16:57:12.568: E/AndroidRuntime(1260):     at android.app.Activity.performCreate(Activity.java:5133)
01-17 16:57:12.568: E/AndroidRuntime(1260):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
01-17 16:57:12.568: E/AndroidRuntime(1260):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2175)
01-17 16:57:12.568: E/AndroidRuntime(1260):     ... 11 more

我注意到错误发生在TimelineActivity.Java的第42行,但无法解决。

    import android.app.ListActivity;
    import android.database.Cursor;
    import android.os.Bundle;
    import android.support.v4.widget.SimpleCursorAdapter;
    import android.text.format.DateUtils;
    import android.view.View;
    import android.widget.SimpleCursorAdapter.ViewBinder;
    import android.widget.TextView;

public class TimelineActivity extends Activity {
        static final String[] FROM = { StatusData.C_USER, StatusData.C_CREATED_AT,
                StatusData.C_TEXT };
        static final int[] TO = { R.id.text_user, R.id.text_created_at,
                R.id.text_text };

        SimpleCursorAdapter adapter;
        Cursor cursor;

        @SuppressWarnings("deprecation")
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.timeline);

            cursor = ((YambaApp) getApplication()).statusData.Query();

    //Line 42   adapter = new SimpleCursorAdapter(this, R.layout.row, cursor, FROM, TO); 
            adapter.setViewBinder((android.support.v4.widget.SimpleCursorAdapter.ViewBinder) VIEW_BINDER);
            list.setAdapter(adapter);

        }

        static final ViewBinder VIEW_BINDER = new ViewBinder() {

            @Override
            public boolean setViewValue(View view, Cursor cursor, int columnIndex) {
                if (view.getId() != R.id.text_created_at)
                    return false;

                long time = cursor.getColumnIndex(StatusData.C_CREATED_AT);
                CharSequence relativeTime = DateUtils
                        .getRelativeTimeSpanString(time);
                ((TextView) view).setText(relativeTime);

                return true;
            }

        };

    }

如果需要任何其他信息,请告诉我。

2 个答案:

答案 0 :(得分:1)

尝试使用以下

final android.support.v4.widget.SimpleCursorAdapter.ViewBinderVIEW_BINDER = new ViewBinder()

我猜您导入了错误的viewbinder

答案 1 :(得分:0)

变化:

import android.widget.SimpleCursorAdapter.ViewBinder;

为:

import android.support.v4.widget.SimpleCursorAdapter.ViewBinder;