Reputation: 1020
Unfortunately App has crossed is the message I'm getting. I'm using Yamba Application and trying to use ViewBinder to publish status messages in TimelineActivity with relativeTimeSpan. Following is the 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
I notice the error is at Line 42 of TimelineActivity.Java but unable to resolve.
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;
}
};
}
Let me know if any other information is required..
Upvotes: 0
Views: 296
Reputation: 17401
change:
import android.widget.SimpleCursorAdapter.ViewBinder;
to:
import android.support.v4.widget.SimpleCursorAdapter.ViewBinder;
Upvotes: 0
Reputation: 54722
Try using the following
final android.support.v4.widget.SimpleCursorAdapter.ViewBinderVIEW_BINDER = new ViewBinder()
I guess you have imported the wrong viewbinder
Upvotes: 1