java - I've got a very strange crash during Android TextAdventure development -


http://scr.hu/0eug/7vny2

the situation:

i press button should launch part of code (work in progress on this, it's not complete yet):

public void playerattack1(view view){         setcontentview(r.layout.activity_fight_defense);         displaystats();         int attacktype = 1;         int dmgminimum = 10;         int dmgmaximum = 15;         random rn = new random();         int range = dmgmaximum - dmgminimum + 1;         int damage = rn.nextint(range) + dmgminimum;         fight_p_attack(damage, attacktype);         sb.insert(0,"attack!\n");         textview = (textview) findviewbyid(r.id.teststring);         textview.settext(sb);   public void fight_p_attack(int damage, int attacktype){         setcontentview(r.layout.activity_fight_defense);         int k9minimum = 1;         int k9maximum = 9;         random rn = new random();         int range = k9maximum - k9minimum + 1;         int k9 = rn.nextint(range) + k9minimum;          switch (attacktype){         case 1:             switch (k9){             case 1: damage *= 2;             enemyhealth -= damage;             case 4: enemyhealth -= damage;             case 7: enemyhealth -= damage;             }         case 2:             switch (k9){             case 2: enemyhealth -= damage;             case 5: damage *= 2;             enemyhealth -= damage;             case 8: enemyhealth -= damage;             }         case 3:             switch (k9){             case 3: enemyhealth -= damage;             case 6: enemyhealth -= damage;             case 9: damage *= 2;             enemyhealth -= damage;             }         }         fight_update();     }      public void fight_update(){         textview = (textview) findviewbyid(r.id.health);         textview.settext("health: "+health+" ");         textview = (textview) findviewbyid(r.id.mana);         textview.settext("mana: "+mana+" ");         textview = (textview) findviewbyid(r.id.gold);         textview.settext("gold: "+gold+" ");         textview = (textview) findviewbyid(r.id.respect);         textview.settext("respect: "+respect);         textview = (textview) findviewbyid(r.id.enemyhealthview);         textview.settext(enemyhealth);     } 

i've tested bit , seems if remove part trying settext textview inside table view:

    textview = (textview) findviewbyid(r.id.enemyhealthview);     textview.settext(enemyhealth); 

it's no longer crashing (but table empty , that's not want!

question: how write such table:

http://scr.hu/0eug/zzqz1

<?xml version="1.0" encoding="utf-8"?> <scrollview xmlns:android="http://schemas.android.com/apk/res/android"     android:layout_width="match_parent"     android:layout_height="match_parent"     android:background="@drawable/papier_1" >    <linearlayout         android:layout_width="match_parent"         android:layout_height="wrap_content"         android:orientation="vertical"         android:layout_gravity="top" >              <linearlayout android:layout_width="match_parent"         android:layout_height="wrap_content"         android:orientation="horizontal" >                 <textview android:id="@+id/health"             android:layout_width="wrap_content"             android:layout_height="wrap_content" />                                 <textview android:id="@+id/mana"             android:layout_width="wrap_content"             android:layout_height="wrap_content" />                                                 <textview android:id="@+id/gold"             android:layout_width="wrap_content"             android:layout_height="wrap_content" />                                                         <textview android:id="@+id/respect"             android:layout_width="wrap_content"             android:layout_height="wrap_content" />             </linearlayout>      <linearlayout   android:orientation="vertical"   android:layout_width="match_parent"   android:layout_height="match_parent"   android:gravity="center">             <tablerow android:id="@+id/tabla_cabecera" android:layout_width="wrap_content" android:layout_height="match_parent"></tablerow>             <tablelayout android:id="@+id/tabla_cuerpo" android:layout_height="match_parent" android:layout_width="wrap_content">                 <tablerow android:id="@+id/tablerow1" android:layout_width="match_parent" android:layout_height="wrap_content">                  <textview android:background="@drawable/cell_shape" android:padding="5dp" android:id="@+id/fightview" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textappearance="?android:attr/textappearancelarge" android:text="@string/enemyname"></textview>                  </tablerow>                 <tablerow android:id="@+id/tablerow2" android:layout_width="match_parent" android:layout_height="wrap_content">                      <textview android:background="@drawable/cell_shape" android:padding="5dp" android:id="@+id/fightview1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textappearance="?android:attr/textappearancemedium" android:text="@string/health"></textview>                     <textview android:background="@drawable/cell_shape" android:padding="5dp" android:id="@+id/enemyhealthview" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textappearance="?android:attr/textappearancemedium" ></textview>                  </tablerow>                 <tablerow android:id="@+id/tablerow3" android:layout_width="match_parent" android:layout_height="wrap_content">                                          <textview android:background="@drawable/cell_shape" android:padding="5dp" android:id="@+id/fightview2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textappearance="?android:attr/textappearancemedium" android:text="@string/attack"></textview>                     <textview android:background="@drawable/cell_shape" android:padding="5dp" android:id="@+id/fightview3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textappearance="?android:attr/textappearancemedium" ></textview></tablerow>                  <tablerow android:id="@+id/tablerow4" android:layout_width="match_parent" android:layout_height="wrap_content">                                          <textview  android:background="@drawable/cell_shape" android:padding="5dp" android:id="@+id/fightview4" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textappearance="?android:attr/textappearancemedium" android:text="@string/defense"></textview>                     <textview android:background="@drawable/cell_shape" android:padding="5dp" android:id="@+id/fightview5" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textappearance="?android:attr/textappearancemedium" ></textview>                  </tablerow>             </tablelayout>   </linearlayout>                                          <button             android:layout_width="fill_parent"             android:layout_height="wrap_content"             android:onclick="playerattack1"             android:text="@string/playerattack1" />                                         <button             android:layout_width="fill_parent"             android:layout_height="wrap_content"             android:onclick="playerattack2"             android:text="@string/playerattack2" />                                         <button             android:layout_width="fill_parent"             android:layout_height="wrap_content"             android:onclick="playerattack3"             android:text="@string/playerattack3" />                                                                          <textview android:id="@+id/teststring"                                     android:background="@drawable/cell_shape"             android:layout_width="fill_parent"             android:layout_height="wrap_content" />    </linearlayout>  </scrollview> 

based on stack trace image

android.content.res.resources$notfoundexception: string resource id #0x7b

you exception, when tring set int value textview, or edittext or button, toast etc views.

when set int value views, consider them string resources, try search string resource specified id, , throw resources$notfoundexception

change

textview.settext(enemyhealth); 

to

textview.settext(string.valueof(enemyhealth)); 

Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -