Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Android

How to retrieve multiple columns data in parse as textView

So, I followed along build self destructing app course. I am trying this new features where a user can create questionnaire send to other user's inbox and as user click on the box the data will be presented in another activity as textView. Basically, I was able to store the data in parse, but retrieving it is becoming a problem even though I did everything was taught in the tutorial. Please, help me to see what am I missing. Code is below for illustration:

VoteActivity where user creates a questionnaire: public class VoteActivity extends Activity {

private Vote vote;
private EditText mainText;
private EditText mTextOne;
private EditText mTextTwo;
private EditText mTextThree;
private String postmaintText;
private String posttextOne;
private String posttextTwo;
private String posttextThree;
private Button mButton;


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_vote);

    Intent intent = this.getIntent();

     mainText = (EditText) findViewById(R.id.questionVote);
     mTextOne = (EditText) findViewById(R.id.choiceOne);
     mTextTwo = (EditText) findViewById(R.id.choiceTwo);
     mTextThree = (EditText) findViewById(R.id.choiceThree);



     mButton =(Button) findViewById(R.id.createQ);
     mButton.setOnClickListener(new View.OnClickListener() {
         @Override
         public void onClick(View v) {

             postmaintText = mainText.getText().toString();
             posttextOne = mTextOne.getText().toString();
             posttextTwo = mTextTwo.getText().toString();
             posttextThree = mTextThree.getText().toString();


             postmaintText.trim();
             posttextOne.trim();
             posttextTwo.trim();
             posttextThree.trim();

             if (postmaintText.isEmpty() || posttextOne.isEmpty() || posttextTwo.isEmpty()|| posttextThree.isEmpty())
             {
                 AlertDialog.Builder builder = new AlertDialog.Builder(VoteActivity.this);
                 builder.setMessage(R.string.voteMessage)
                         .setTitle(R.string.vote_error_title)
                         .setPositiveButton(android.R.string.ok,null);
                 AlertDialog dialog = builder.create();
                 dialog.show();
             }
             else
             {
                 final ParseObject post = new ParseObject("Messages");
                 post.put("questionare", postmaintText);
                 post.put("optionOne", posttextOne);
                 post.put("optionTwo", posttextTwo);
                 post.put("optionThree", posttextThree);
                 post.saveInBackground(new SaveCallback() {
                     @Override
                     public void done(ParseException e) {

                     if (e==null) {
                     // questioner posted successfully
                         Intent intent = new Intent(VoteActivity.this, recipientsActivity.class);
                         vote = new Vote (post.getObjectId(), postmaintText, posttextOne, posttextTwo,posttextThree);
                         String mainTextt = mainText.getText().toString();
                         String optionOnee = mTextOne.getText().toString();
                         String optionTwoo= mTextTwo.getText().toString();
                         String optionThree = mTextThree.getText().toString();
                         // below is the intent where the list of recipents will be displayed for the user, that is where the app crashes
                         intent.putExtra(parseConstants.MAIN_QUESTIONRARE, mainTextt);
                         intent.putExtra(parseConstants.OPTION_ONE, optionOnee);
                         intent.putExtra(parseConstants.OPTION_TWO, optionTwoo);
                         intent.putExtra(parseConstants.OPTION_THREE, optionThree);
                         intent.putExtra(parseConstants.KEY_FILE_TYPE, parseConstants.TYPE_QUESTIONARE);
                         Toast.makeText(getApplication(), "Sent", Toast.LENGTH_SHORT).show();
                         startActivity(intent);

                     }
                     else {

                         Toast.makeText(getApplicationContext(), "Failed to post", Toast.LENGTH_SHORT).show();

                     }


                     }
                 });


             }

         }
     });


}


@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.menu_vote, menu);
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();

    //noinspection SimplifiableIfStatement
    if (id == R.id.action_settings) {
        return true;
    }

    return super.onOptionsItemSelected(item);
}

}

InboxFragment: public class InboxFragment extends ListFragment {

protected List<ParseObject> mMessages;


@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_inbox, container, false);
    return rootView;
}
// we are going to query the new message class that we just created in parse
@Override
public void onResume() {
    super.onResume();

    getActivity().setProgressBarIndeterminate(true);

    ParseQuery<ParseObject> query = new ParseQuery<ParseObject>(parseConstants.CLASS_MESSAGES);
    query.whereEqualTo(parseConstants.KEY_RECIPIENT_IDS, ParseUser.getCurrentUser().getObjectId());
    query.addDescendingOrder(parseConstants.KEY_CREATED_AT);
    query.findInBackground(new FindCallback<ParseObject>() {
        @Override
        public void done(List<ParseObject> messages, ParseException e) {
            getActivity().setProgressBarIndeterminate(false);

            if(e == null) {
                //we found messages!
                mMessages = messages;
                String[] usernames = new String[mMessages.size()];
                int i = 0;
                for (ParseObject message : mMessages) {
                    usernames[i] = message.getString(parseConstants.KEY_SENDER_NAME);
                    i++;
                }
                // check list
               messageAdapter adapter = new messageAdapter(
                       getListView().getContext(),
                       mMessages);
                setListAdapter(adapter);
            }

        }
    });

}

@Override
public void onListItemClick(ListView l, View v, int position, long id) {

    super.onListItemClick(l, v, position, id);
    ParseObject message = mMessages.get(position);
    String messageType = message.getString(parseConstants.KEY_FILE_TYPE);
    String senderName = message.getString(parseConstants.KEY_SENDER_NAME);
    String displayMessage = message.getString(parseConstants.KEY_MESSAGE);
    String createdDate = message.getString(parseConstants.KEY_CREATED_AT);

    ParseFile file = message.getParseFile(parseConstants.KEY_FILE);
    if (messageType.equals(parseConstants.TYPE_IMAGE)) {
        //view the image
        Uri fileUri = Uri.parse(file.getUrl());
        Intent intent = new Intent(getActivity(), ViewImageActivity.class);
        intent.setData(fileUri);
        startActivity(intent);
    }else if (messageType.equals(parseConstants.TYPE_VIDEO)) {
        Uri fileUri = Uri.parse(file.getUrl());
        //view the video
        Intent intent = new Intent(Intent.ACTION_VIEW, fileUri);
        intent.setDataAndType(fileUri, "video/*");
        startActivity(intent);

    }
       else if (messageType.equals(parseConstants.TYPE_QUESTIONARE)) {
      //  AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
        Intent intent = new Intent(getActivity(), VoteAnswer.class);
        startActivity(intent);



    }else if (messageType.equals(parseConstants.TYPE_TEXT)){

        //Toast.makeText(getActivity(),  displayMessage, Toast.LENGTH_LONG).show();
        AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
        builder.setTitle("Message from: " + senderName + ".");
        builder.setMessage(displayMessage);
        builder.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int whichButton) {

            }
        });
        AlertDialog dialog = builder.create();
        dialog.show();
    }


    //delete the message
    List<String> ids = message.getList(parseConstants.KEY_RECIPIENT_IDS);

    if(ids.size() == 1) {
        //last recipient, delete the message
        message.deleteInBackground();

    }else {
        //remove recipients name
        ids.remove(ParseUser.getCurrentUser().getObjectId());

        ArrayList<String> idsToRemove = new ArrayList<String>();
        idsToRemove.add(ParseUser.getCurrentUser().getObjectId());

        message.removeAll(parseConstants.KEY_RECIPIENT_IDS, idsToRemove);
        message.saveInBackground();
    }
}
    }

Finally, Vote Answer: //Here is where I am having problem. What am I missing?

public class VoteAnswer extends ActionBarActivity {

protected TextView questionare ;
protected TextView mOne ;
protected TextView mTwo ;
protected TextView  mThree ;

private String question;
private String mO;
private String mT;
private String mH;
private List<Vote> mVotes;



String obj;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_vote_answer);



    questionare = (TextView) findViewById(R.id.mainQ);
    mOne = (TextView) findViewById(R.id.optionO);
    mTwo = (TextView) findViewById(R.id.optionTW);
    mThree = (TextView) findViewById(R.id.optionTH);

    getDetails();

    Intent i = getIntent();
   // obj = i.getStringExtra("questionare");
 //  getDetails(obj);

}
   private void getDetails () {

       ParseQuery<ParseObject> query = ParseQuery.getQuery("Messages");
       query.whereEqualTo("objectId",ParseUser.getCurrentUser().getObjectId());
       query.findInBackground( new FindCallback<ParseObject>() {
           @Override
           public void done(List<ParseObject> objects, ParseException e) {
               if (e==null) {


                  for (int i = 0; i <objects.size(); i ++)
                  {
                      questionare.setText(objects.get(i).getString("questionare"));
                      mOne.setText(objects.get(i).getString("optionOne"));
                      mTwo.setText(objects.get(i).getString("optionTwo"));
                      mThree.setText(objects.get(i).getString("optionThree"));
                   }



                   //question = objects.toString("questionare");
                   //mO = objects.toString("optionOne");
                  // mT = objects.toString("optionTwo");
                  // mH = objects.toString("optionThree");
                   //addData();

               }
               else
               {
                   e.printStackTrace();

               }
           }
       });

}