0

When I try to run my app I get the following error:

  java.lang.ClassCastException: com.protogeo.moves.demos.apps.MainActivity$6 cannot be cast to android.content.Context
            at com.protogeo.moves.demos.apps.StorylineAdapter.<init>(StorylineAdapter.java:28)
            at com.protogeo.moves.demos.apps.MainActivity$6.run(MainActivity.java:285)

My Main activity code looks like this:

public class MainActivity extends FragmentActivity implements OnClickListener{
...
    public void updateResponse(final String message) {
        runOnUiThread(new Runnable() {

    @Override
    public void run() {
        //mEditTextResponse.setText(message);
        StorylineAdapter adapter = new StorylineAdapter(this, R.layout.item_storyline, summary);
       // mEditTextResponse.setAdapter(adapter);
        mEditTextResponse.setAdapter(adapter);

...

My ArrayAdapter code looks like this:

 public class StorylineAdapter extends ArrayAdapter<SummaryData>{
    private Context context;
    private ArrayList<SummaryData> summary;

    public StorylineAdapter(Context context, int item_storyline, ArrayList<SummaryData> objects) {
        super( context, item_storyline, objects);
        this.context = context;
        this.runnable = runnable;
        this.summary = objects;

    }



    @Override
    public View getView(int position, View convertView, ViewGroup parent){

        LayoutInflater inflater = ((Activity) context).getLayoutInflater();
        View view = inflater.inflate(R.layout.item_storyline, parent, false);


           summary = summary.get(position);
        TextView tv = (TextView) view.findViewById(R.id.textView1);
        tv.setText(summary.getActivity());

        return view;
    }
}
Jonathan Hall
  • 75,165
  • 16
  • 143
  • 189
dbo
  • 161
  • 1
  • 10
  • what is the use of passing R.layout.item_storyline, – DKV Jul 14 '15 at 10:22
  • As I am new to android I found an example in which the code was written this way and worked. Is there a suggestion you can offer of how to improve it or get the code working please? – dbo Jul 14 '15 at 11:10
  • Thanks @ user3676184 I have made the changes you suggested but this just gives me errors in the code so the app no longer runs. I wondered if the problems are due to my MainActivity extending FragmentActivity and implementing OnClickListener, so updated the MainActivity & ArrayAdapter above to reflect that and the changes you suggested that are not working. – dbo Jul 14 '15 at 11:20
  • 1
    StorylineAdapter adapter = new StorylineAdapter(MainActivity.this, summary); this is enough. Just debug your code. – DKV Jul 14 '15 at 11:32

0 Answers0