java - Why isn't this View.setText function call not working -


this question has answer here:

the above code executed without problem.but when added "mquestiontextview.settext(question);" app crashes on startup.i guess,syntactically instruction correct.need help

public class mainactivity extends actionbaractivity { private textview mquestiontextview; private truefalse[] mquestionbank = {         new truefalse(r.string.question_africa,false),         new truefalse(r.string.question_americas,true),         new truefalse(r.string.question_asia,true),         new truefalse(r.string.question_mideast,false),         new truefalse(r.string.question_oceans,true) }; private int mcurrentindex = 0; @override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.activity_main);     mquestiontextview = (textview) findviewbyid(r.id.question_tv);     int question = mquestionbank[mcurrentindex].getquestion();     mquestiontextview.settext(question);      ...} 

the activity_main.xml file :

<linearlayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:gravity="center" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:paddingbottom="@dimen/activity_vertical_margin" android:paddingleft="@dimen/activity_horizontal_margin" android:paddingright="@dimen/activity_horizontal_margin" android:paddingtop="@dimen/activity_vertical_margin" tools:context="com.example.geopquiz1.mainactivity$placeholderfragment" >  <textview     android:id="@+id/question_tv"     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:padding="24dp"/>  <linearlayout     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:orientation="horizontal" >      <button         android:onclick="true_onclick"          android:id = "@+id/true_button"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:text="@string/true_button_text"/>     <button          android:onclick="false_onclick"         android:id = "@+id/false_button"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:text="@string/false_button_text"/>    <button        android:id="@+id/next_button"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:text="@string/next_btn_text"/> </linearlayout>  </linearlayout> 

truefalse.java file:

package com.example.geopquiz1;  public class truefalse { private int mquestion; private boolean mtruequestion; public truefalse(int question,boolean truequestion){     mquestion = question;     truequestion = mtruequestion; } public int getquestion() {     return mquestion; } public void setquestion(int question) {     mquestion = question; } public boolean istruequestion() {     return mtruequestion; } public void settruequestion(boolean truequestion) {     mtruequestion = truequestion; } } 

from can understand question int value. textview.settext() accept string values only. have try this

mquestiontextview.settext(question+""); 

Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -