Cannot convert from int to String from R.java

I have a Dashboard.java file where I use strings.xml parsed in a R.java auto generated file.

When I try to do:

public String BASE_URL = R.string.BASE_URL; 

Naturally say Unable to convert from int to String.

But what will be selected from string.xml for translation.

Is there any way around this?

thanks

+4
source share
2 answers

Use it

 String BASE_URL = getResources().getString(R.string.BASE_URL); 

or you can copy the code:

 getResources().getString(R.string.BASE_URL); 
+10
source
  Resources res = getResources(); String url = res.getString(R.string.hello_world); EditText et=(EditText)findViewById(R.id.editText1); et.setText(url); 
+1
source

Source: https://habr.com/ru/post/1493934/


All Articles