Android can not modify a textview

3

I have a TextView that is not updated at runtime. Said TextView is defined by the following XML code:

<TextView
android:id="@+id/agi_val"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />

In the code of the activity, I access the TextView in this way:

private TextView AGI;
///< Some stuff

 protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_abf__char_gen__basic_info);

        abfToolsSaveData = (ABFToolsSaveData) getIntent().getParcelableExtra("SaveDataClass");

        this.AGI = (TextView) findViewById(R.id.agi_val);
        ///< Some stuff

        if (abfToolsSaveData != null) {
            this.chargeData(true);
        } else {
            Log.d("INFO", "abfToolsSaveData is null");
        }
    }

And in chargeData (boolean):

public void chargeData(boolean firstTime){
        if(firstTime){
            MainCharacteristics mc = abfToolsSaveData.getCharacter().getMainCharacteristics(); ///< We get the main characteristics, auto-generated the first time

            /**
             * Set the Text Views with the default value
             */
            if(AGI != null){    ///< I've done this to check if the text view is null or not
                Log.d("INFO", String.valueOf(AGI));
                AGI.setText(mc.getAGI());
            }
            else
                Log.d("INFO","AGI IS NULL");
            ///< Some stuff
        }
    }

The thing is that "agi_val" finds it, but the AGI TextView of the activity can not access the agi_val resource. The error log is as follows:

///< Esta primera linea es mi salida por pantalla que demuestra que AGI tiene acceso a agi_val:
    09-20 10:07:32.344 1266-1266/com.noeselmastersonlosdados.sliferdragon.penandpapercompanion D/INFO: android.support.v7.widget.AppCompatTextView{b670993 V.ED.... ......ID 0,0-0,0 #7f0d0077 app:id/agi_val}
    09-20 10:07:32.344 1266-1266/com.noeselmastersonlosdados.sliferdragon.penandpapercompanion W/ResourceType: No package identifier when getting value for resource number 0x00000009
    --------- beginning of crash
    09-20 10:07:32.347 1266-1266/com.noeselmastersonlosdados.sliferdragon.penandpapercompanion E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.noeselmastersonlosdados.sliferdragon.penandpapercompanion, PID: 1266
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.noeselmastersonlosdados.sliferdragon.penandpapercompanion/com.noeselmastersonlosdados.sliferdragon.penandpapercompanion.ABF_CharGen_BasicInfo}: android.content.res.Resources$NotFoundException: String resource ID #0x9
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2325)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
    at android.app.ActivityThread.access$800(ActivityThread.java:151)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:135)
    at android.app.ActivityThread.main(ActivityThread.java:5254)
    at java.lang.reflect.Method.invoke(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:372)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
  Caused by: android.content.res.Resources$NotFoundException: String resource ID #0x9
    at android.content.res.Resources.getText(Resources.java:299)
    at android.widget.TextView.setText(TextView.java:4132)
///< Esta linea referencia a la asignación del texto
    at com.noeselmastersonlosdados.sliferdragon.penandpapercompanion.ABF_CharGen_BasicInfo.chargeData(ABF_CharGen_BasicInfo.java:73)
    at com.noeselmastersonlosdados.sliferdragon.penandpapercompanion.ABF_CharGen_BasicInfo.onCreate(ABF_CharGen_BasicInfo.java:54)
    at android.app.Activity.performCreate(Activity.java:5990)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387) 
    at android.app.ActivityThread.access$800(ActivityThread.java:151) 
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303) 
    at android.os.Handler.dispatchMessage(Handler.java:102) 
    at android.os.Looper.loop(Looper.java:135) 
    at android.app.ActivityThread.main(ActivityThread.java:5254) 
    at java.lang.reflect.Method.invoke(Native Method) 
    at java.lang.reflect.Method.invoke(Method.java:372) 
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903) 
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698) 

Does anyone know what is happening? I have tried to do a Clean and Rebuild, to restart the program, and many other things that I have found online, but nothing gives me the solution to the problem.

    
asked by Slifer Dragon 20.09.2017 в 14:23
source

1 answer

4

I'm almost certain that the method mc.getAGI() returns a int so it shows the stacktrace:

android.content.res.Resources$NotFoundException: String resource ID #0x9

What the error means is that you are using the setText(int resourceId) overload that the resource R.string has the id that returns the getAGI() method, and the safest thing is that you want to print the return value, not search for a resource R.string .

Convert the return value to String to make it work:

if(AGI != null){
    ///< I've done this to check if the text view is null or not
    Log.d("INFO", String.valueOf(AGI));
    String agi = String.valueOf(mc.getAGI());
    AGI.setText(agi);
}
    
answered by 20.09.2017 / 14:32
source