I have a method written like this...
public void getRequest(String Url) {
runOnUiThread(new Runnable() {
public void run() {
// TODO Auto-generated method stub
HttpClient client = new DefaultHttpClient();
HttpGet request = new HttpGet(url);
try {
HttpResponse response = client.execute(request);
Toast.makeText(MenuUtama.this, request(response) ,Toast.LENGTH_SHORT).show();
} catch (Exception ex) {
ex.printStackTrace();
}
}
});
}
I need to be able to access the local variable request
in another method, so that I can call request.response
. How am I able to access this local method from a totally different method?
I think what you're looking for is something along these lines:
Obviously change
Object
to whatever classrequest(response)
works out to be, renamemyRequest
, and preferrably use accessors on a private instance variable rather than making it protected and assigning directly, but you get the point, hopefully, that you need an instance variable to hold the value of your method callrequest(response)
.Increase the scope of variables of response and and request,I mean declare these variable at class level not in method level.
You cannot call any variable declare as a local variable inside any function. you can do that in a way as follows
If you want to access those from outside the class, then you have to create an object of class A and then call as follows
But remember the variables access specifiers should allow you to do this.
you should declare your
response
variable in a class-level scope. here's your code.