views:

86

answers:

5

I am modifying the source code here: http://thinkandroid.wordpress.com/2009/12/30/getting-response-body-of-httpresponse/

I get this error: non-static method getContentCharSet(org.apache.http.HttpEntity) cannot be referenced from a static context String charset = getContentCharSet(entity);

This error is line 13 on the second box.

Any ideas? I have been really struggling with this code :-(

A: 

set getContentCharSet(org.apache.http.HttpEntity) to "static" ;-)

poeschlorn
yes this is what eclipse suggests ;)
Roflcoptr
but it works ;-) No, seriously, i don't know any other way to do this
poeschlorn
+1  A: 

you' are in a static method and you try to call a instance method. but for calling a instance method you have to use a object to call it. you can't just call a instance method without an object.

as already mentioned you could make the other method also static but if this is inappropriate you have to use an instance of the object in which this method is defined to make that call.

Roflcoptr
A: 

You cannot call a non-static function without creating an instance of it. Try not to get in the habit of converting everything to static, but instead just create an instance of the class, and then call the method.

Theofanis Pantelides
A: 

Yes, either make all the methods static or not, if they call each other.

aniri
i wouldn't recommend that if it is not really necessary
Roflcoptr
A: 

In general you would instanciate the class, then call the method on that instance.

In this case, it looks like the missing static is indeed just a typo.

Fanged