-1

I am trying to fetch the getcontent() method from model but when i am trying to fetch the method it shows null value .

public class Gettingcomment extends AsyncTask<String,String,List<CommentModel>>{


    @Override
    protected List<CommentModel> doInBackground(String... params) {

        String commenturl = params[0];

        Populatecomments populatecomments =new Populatecomments();
       // populatecomments.getCommentModelList(commenturl+mytrendinid);

        Log.i("mytrendin",commenturl);

        List<CommentModel>  model= populatecomments.getCommentModelList(commenturl);

        return model;
    }

    @Override
    protected void onPostExecute(List<CommentModel> results) {
        super.onPostExecute(results);
        CommentModel commentModel = new CommentModel();
        String content = commentModel.getContent();
        Toast.makeText(getApplicationContext(),content,Toast.LENGTH_LONG).show();


    }
}

2 Answers2

2

Check this

 @Override
protected void onPostExecute(List<CommentModel> results) {
    super.onPostExecute(results);
    if(results.size()>0){
    for(int i=0;i<results.size();i++){
        CommentModel commentModel = results.get(i);
        String content = commentModel.getContent();
        Toast.makeText(getApplicationContext(),content,Toast.LENGTH_LONG).show();
      }
    }
}
Akash
  • 961
  • 6
  • 15
1

Your are trying to getContent from newly created CommentModel instance which doesn't have any content. So please check this from doinBackground result.

public class Gettingcomment extends AsyncTask<String,String,List<CommentModel>>{


@Override
protected List<CommentModel> doInBackground(String... params) {

    String commenturl = params[0];

    Populatecomments populatecomments =new Populatecomments();
   // populatecomments.getCommentModelList(commenturl+mytrendinid);

    Log.i("mytrendin",commenturl);

    List<CommentModel>  model= populatecomments.getCommentModelList(commenturl);

    return model;
}

@Override
protected void onPostExecute(List<CommentModel> results) {
    super.onPostExecute(results);
    if(results!=null && results.size()>0){
    //here i am getting getContent from 0 position of CommentModel list you can loop to get all the model's content
    String content = results.get(0).getContent();
    Toast.makeText(getApplicationContext(),content,Toast.LENGTH_LONG).show();
    }
}

}

Ready Android
  • 3,529
  • 2
  • 26
  • 40