我是初学,代码也是抄百度的例子,但是执行到HttpResponse response = df.execute(request);的时候就直至跳到catch (Exception e),我加了权限,模拟器也换过了几个了,一直都是异常,求大神解答
public class PostActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button b = (Button) findViewById(R.id.button1);
b.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
HttpGet request = new HttpGet("http://10.0.2.2/android.php?name=Neeke");
try {
DefaultHttpClient df=new DefaultHttpClient();
df.getParams().setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, 10000);
df.getParams().setParameter(CoreConnectionPNames.SO_TIMEOUT, 10000);
request.addHeader("Accept-Language", "en");
HttpResponse response = df.execute(request);
/*if(response.getStatusLine().getStatusCode() == 200){
String result = EntityUtils.toString(response.getEntity());
Toast.makeText(PostActivity.this, result, Toast.LENGTH_LONG).show();
}*/
} catch (Exception e) {
Toast.makeText(PostActivity.this, "error", Toast.LENGTH_LONG).show();
e.printStackTrace();
}
}
});
}
}
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="podt.pack"
android:versionCode="1"
android:versionName="1.0" >
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"></uses-permission>
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<uses-sdk android:minSdkVersion="15" />
<application
android:permission="android.permission.INTERNET"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity
android:name=".PostActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
------解决方案--------------------
你不是说直接跳到catch (Exception e)吗 把这个异常信息贴出来啊