0

Good morning. I want to send get request and show response in TextView.

public class MyHttpClient {

private static final String BASE_URL = "http://pgu.com";

private static AsyncHttpClient client = new AsyncHttpClient();

 public static void get(String url, RequestParams params, AsyncHttpResponseHandler responseHandler) {
      client.get(getAbsoluteUrl(url), params, responseHandler);
 }   
 private static String getAbsoluteUrl(String relativeUrl) {
      return BASE_URL + relativeUrl;
  }}

I'm calling get from this class

public class MyHttpClientUsage {

Handler h;

public MyHttpClientUsage(Handler h){
    this.h = h;
}

public void getInfoAbout() throws HttpException{

    RequestParams params = new RequestParams();
    params.put("a", "Static");
    params.put("content", "47");

    MyHttpClient.get("", params, new AsyncHttpResponseHandler(){
         @Override
            public void onSuccess(String response) {
                  System.out.println(response);
                              //Simplify sending int to TextView
                  MyHttpClientUsage.this.h.sendEmptyMessage(678); 
                         }
    });
}}

In activity I have a Handler to obtain a message and set TextView

public class MainActivity extends Activity {

Handler h;
TextView largeText;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    largeText = (TextView) findViewById(R.id.textView1);

    h = new Handler(){

        public void handleMessage(android.os.Message msg){
            largeText.setText(msg.what);
        }

    };

    MyHttpClientUsage connect = new MyHttpClientUsage(h);
    try {
        connect.getInfoAbout();
    } catch (HttpException e) {
        e.printStackTrace();
    }

}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.activity_main, menu);
    return true;
}}

In LogCat I have this warning

02-06 14:30:51.783: W/dalvikvm(546): threadid=1: thread exiting with uncaught exception (group=0x409961f8)

and error

02-06 14:30:51.833: E/AndroidRuntime(546): android.content.res.Resources$NotFoundException:   String resource ID #0x2a6
3
  • 1
    Are you sure you've declared all of your views? Commented Feb 6, 2013 at 15:20
  • The error is telling us that some requested resource was not found. Double-check your xml layouts and clean/rebuild your project. Commented Feb 6, 2013 at 15:34
  • 1
    Thanks, now it's working! I hoped that autoboxing int to Integer and calling toString() are working. Commented Feb 6, 2013 at 15:49

1 Answer 1

1

as you can see here Message. what is an int.you are passing int to setText method of TextView which take CharSequence as parameter . change your your code as :

largeText.setText(String.valueOf(msg.what));

OR

largeText.setText(msg.what.toString());
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.