Click here to Skip to main content
15,881,757 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to implement a search feature in my app that will be
populated from sqlite db but am having challenges, when i test the
app in the emulator and i implemented the search feature, it crashes
and shows the following in my logcat
"Caused by: java.lang.ClassCastException:
com.akada.gemstouch.searchfeature.SearchableActivity
cannot be cast to android.support.v4.app.LoaderManager$LoaderCallbacks"
see the code below

import android.support.v4.app.LoaderManager;
import android.support.v4.content.CursorLoader;
import android.content.Intent;
import android.support.v4.content.Loader;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.widget.ImageView;
import android.widget.TextView;


/**
* Created by Akinyemi on 5/8/2015.
*/
public class CountryActivity extends FragmentActivity implements LoaderManager.LoaderCallbacks<cursor> {

private Uri mUri;
private ImageView mIvFlag;
private TextView mTvName;
private TextView mTvCurrency;

@Override
protected void onCreate(Bundle arg0) {
super.onCreate(arg0);
setContentView(R.layout.activity_country);

Intent intent = getIntent();
mUri = intent.getData();

mIvFlag = (ImageView) findViewById(R.id.iv_flag);
mTvName = (TextView) findViewById(R.id.tv_name);
mTvCurrency = (TextView) findViewById(R.id.tv_currency);

// Invokes the method onCreateloader() in non-ui thread
getSupportLoaderManager().initLoader(0, null, this);

}

/** Invoked by initLoader() */
@Override
public Loader<cursor> onCreateLoader(int arg0, Bundle arg1) {
return new CursorLoader(getBaseContext(), mUri, null, null , null, null);
}

/** Invoked by onCreateLoader(), will be executed in ui-thread */
@Override
public void onLoadFinished(Loader<cursor> arg0, Cursor cursor) {
if(cursor.moveToFirst()){
mIvFlag.setImageResource(cursor.getInt(cursor.getColumnIndex(cursor.getColumnName(2))));
mTvName.setText("Country: "+cursor.getString(cursor.getColumnIndex(cursor.getColumnName(1))));
mTvCurrency.setText("Currency: "+cursor.getString(cursor.getColumnIndex(cursor.getColumnName(3))));
}
}

@Override
public void onLoaderReset(Loader<cursor> arg0) {
// TODO Auto-generated method stub
}
}
Posted
Comments
Richard MacCutchan 9-May-15 12:41pm    
Please format your code properly and show where the error occurs.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900