public String clickInfo_Java() { String result = "";
try {
final String SERVER_URL = "http://10.0.2.2:8080/tm/AndroidAction_Android_FindByCarNumber"; // 定义需要获取的内容来源地址
HttpPost request = new HttpPost(SERVER_URL); // 根据内容来源地址创建一个Http请求
request.setHeader("Content-Type", "application/x-www-form-urlencoded");    List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("cardnumber", "123124212536")); // 添加必须的参数
params.add(new BasicNameValuePair("x", Math.random() + "")); // 添加必须的参数
request.setEntity(new UrlEncodedFormEntity(params, HTTP.UTF_8)); // 设置参数的编码
// HttpResponse httpResponse = new
// DefaultHttpClient().execute(request); // 发送请求并获取反馈
HttpClient client = new DefaultHttpClient(); HttpResponse httpResponse = client.execute(request); // 解析返回的内容
if (httpResponse.getStatusLine().getStatusCode() != 404) {
result = EntityUtils.toString(httpResponse.getEntity());
System.out.println(result);
}
} catch (Exception e) {
Toast.makeText(this, e.getMessage().toString(), Toast.LENGTH_LONG)
.show();
e.printStackTrace();
}
return result;
}每次 运行到  HttpResponse httpResponse = client.execute(request);  程序就跳到了 catch  然后 窗口出现   Permission denied(没有权限)。  各位大神,                    在线等, 急 !!!!!!!  

解决方案 »

  1.   

    AndroidManifest.xml中,添加网络访问权限: <uses-permission android:name="android.permission.INTERNET" />
      

  2.   

    兄弟,我跟你一样的情况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>
      

  3.   

    我纠结两天了,我是初学,代码是抄百度上例子的
    运行到HttpResponse response = df.execute(request);,就直接跳到catch (Exception e)