How to create a string resource from an external source?


I'm trying to access a .php file in the localhost:

        Thread thread = new Thread(new Runnable() {

            public void run() {
                try  {
                    System.err.println("It's working ok?");
                    String url = "";
                    String charset = "UTF-8";  // Or in Java 7 and later, use the constant:
                    String param1 = "value1";
                    String param2 = "value2";
                    String query = "";

                    try {
                        query = String.format("param1=%s&param2=%s",
                                URLEncoder.encode(param1, charset),
                                URLEncoder.encode(param2, charset));
                    } catch (UnsupportedEncodingException e) {

                    URLConnection connection = null;
                    try {
                        connection = new URL(url + "?" + query).openConnection();
                        connection.setRequestProperty("Accept-Charset", charset);
                        InputStream response = connection.getInputStream();
                    } catch (IOException e) {
                        Toast.makeText(mainContext, e.toString(),
                } catch (Exception e) {


When I run it, I get the following error:

W/System.err: android.content.res.Resources$NotFoundException: String resource ID #0x22

How am I supposed to previously define a string inside the XML file, if I'm retrieving it from an external source / a webserver?

Full log:

W/System.err: 123
W/ResourceType: No package identifier when getting value for resource number 0x00000022
W/System.err: android.content.res.Resources$NotFoundException: String resource ID #0x22
W/System.err:     at android.content.res.Resources.getText(
W/System.err:     at android.widget.Toast.makeText(
W/System.err:     at com.hlsystems.ericsonwillians.saltodepirapora.MainActivity$
W/System.err:     at
asked on Stack Overflow Apr 3, 2018 by Ericson Willians • edited Apr 3, 2018 by Phantômaxx

1 Answer

2 returns an int, a single byte of the response.

You need to convert the stream response to a full String before you Toast it.

The makeText method is overloaded to accept R.string resource IDs as a second parameter, which are read only assets, and you cannot create at runtime

If you only care about that one byte, see

Displaying integer on toast

answered on Stack Overflow Apr 3, 2018 by OneCricketeer • edited Apr 3, 2018 by OneCricketeer

User contributions licensed under CC BY-SA 3.0