0

I'm doing the application fetches the data from the database and displayed in Listview

and Must be all the Classes be a Fragment so I can put it in tabs

The error is:

  this.getlistdata.setAdapter(new GetAllSongs(jsonArray,this));

Exactly ... (jsonArray,this)

Full code.

public class GetListData extends Fragment
{
    ListView getlistdata;

    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        this.getActivity().setContentView(R.layout.activity_main2);

        this.getlistdata =  (ListView)this.getActivity().findViewById(R.id.listgetdata);

        new GetAllCustomerTask().execute(new ApiConnector());
    }

    public  void setListAdapter (JSONArray jsonArray)
    {
        this.getlistdata.setAdapter(new GetAllSongs(jsonArray,this));
    }

    private class GetAllCustomerTask extends AsyncTask<ApiConnector,Long,JSONArray>
    {
        @Override
        protected JSONArray doInBackground(ApiConnector... params)
        {
            return params[0].GetAllCustomers();
        }

        @Override
        protected void onPostExecute(JSONArray jsonArray)
        {
            setListAdapter(jsonArray);
        }
    }

The error is ::

can't cast Fragment To Activity

How can I fix it?

Clashsoft
  • 11,553
  • 5
  • 40
  • 79
  • Can you post the full error? `this.getlistdata.setAdapter(new GetAllSongs(jsonArray,this));` doesn't look like an error message, and neither does `this.getlistdata.setAdapter(new GetAllSongs(jsonArray,this));` – WhiteViking Sep 16 '15 at 21:28
  • the error is can't cast Fragment To Activity @WhiteViking – Obaida Al Housrya Sep 16 '15 at 22:05

1 Answers1

0

GetAllSongs() is expecting an Activity as the second argument, but you are passing a Fragment.

The following statement should eliminate the exception:

this.getlistdata.setAdapter(new GetAllSongs(jsonArray, getActivity()))
cybersam
  • 63,203
  • 6
  • 53
  • 76