views:

203

answers:

2

I get this error on my Android emulator:

Sorry The application has stopped unexpectedly. Please try again. [Force Close]

I think the code that is creating the error is this: HttpClient client = new HttpClient();

I have imported the following from JARS:

import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.httpclient.methods.PostMethod;

Any idea? Is there a way to get more details on what the error is? The message described above isn't very helpful...

Stacktrace:

I've looked at this and I think this is the problem. (it was too long to post all on here..)

E/dalvikvm( 757): Could not find class 'org.apache.commons.httpclient.HttpClient', referenced from method com.projectNoble.androidClient.serverComms.initCommunication

W/dalvikvm( 757): VFY: unable to resolve new-instance 46 (Lorg/apache/commons/httpclient/HttpClient;) in Lcom/projectNoble/androidClient/serverComms;

W/dalvikvm( 757): VFY: rejecting opcode 0x22 at 0x0000

W/dalvikvm( 757): VFY: rejected Lcom/projectNoble/androidClient/serverComms;.initCommunication ()Ljava/lang/String;

W/dalvikvm( 757): Verifier rejected class Lcom/projectNoble/androidClient/serverComms;

D/AndroidRuntime( 757): Shutting down VM

Source Code

Can be found at bottom of this page: http://hc.apache.org/httpclient-3.x/tutorial.html

A: 

There is no constructor "HttpClient()".

Maybe you want this:

HttpClient client = new DefaultHttpClient();

really, though, if you want to configure it at all, etc, you can't pass an empty constructor. Read the documentation for the different values you can pass.

Also, when you ask a question on stackoverflow, you'll get a lot more help if you post your code, and the full stacktrace of the error you're getting. You can get the stacktrace from adb logcat, or from in eclipse.

synic
I tried "HttpClient client = new DefaultHttpClient();"and netbeans says:Cannot find symbol.
Mith
Then you are missing an import statement. Here is a sample project showing the use of `DefaultHttpClient`: http://github.com/commonsguy/cw-android/tree/master/Service/WeatherPlus/
CommonsWare
His import is wrong because he brought jars from apache directly to the project
Alex Volovoy
+1  A: 

What jars you've imported from ? Apache client is part of android

Correct package

import org.apache.http.client.HttpClient;

Remove your jars and use only libraries from the SDK

Alex Volovoy
I downloaded JAR from apache and imported them.
Mith
thats not necessary. use the approache from Alex
Roflcoptr
Please use base components provided in SDK - full list of packages are herehttp://developer.android.com/reference/org/apache/http/package-summary.html You don't want to bundle something that already provided by OS.
Alex Volovoy
Thanks Alex.I've deleted the JARS I was refering to and I now use:import org.apache.http.client.HttpClient;I'm still getting "Cannot find symbol" though for DefaultHttpClient, which is strange as its mentioned here:http://developer.android.com/reference/org/apache/http/impl/client/DefaultHttpClient.html
Mith
you do have this import right ? import org.apache.http.impl.client.DefaultHttpClient; if so could you update your stack trace in the question ? It seems to be NetBeans is not the best IDE for android development.
Alex Volovoy
I've been having problems with Eclipse, where it kept giving me a runtime error...
Mith