AsynTask Force在我的应用程序中关闭

时间:2013-09-25 06:18:51

标签: android

我开发了一个用于将内容更新到数据库的Android应用程序。我在后台使用asyntask执行它。但是我的应用程序被强制关闭请帮帮我。代码是

class Authenticate extends AsyncTask<String, String, String>
{

@Override
protected void onPreExecute() {
    super.onPreExecute();
    pDialog = new ProgressDialog(Welcome.this);
    pDialog.setMessage("Logging in. Please wait...");
    pDialog.setIndeterminate(false);
    pDialog.setCancelable(true);
    pDialog.show();
}
@Override
protected String doInBackground(String...args) {

    List<NameValuePair> params = new ArrayList<NameValuePair>();
    params.add(new BasicNameValuePair("s", s));
    JSONObject json = jsonParser.makeHttpRequest(url_authenticate,"POST", params);
    try {
        int success = json.getInt(TAG_SUCCESS);
        name=json.getString(TAG_NAME);
        phone=json.getString(TAG_PHONE);
        fid=json.getString(TAG_FID);
        if (success == 1) {
            // successfully updated
            Intent i = new Intent("com.example.walcliffbusinesssuite.Redirect");
            startActivity(i);
        } else {
            // failed to update product
        }
    } catch (JSONException e) {
        e.printStackTrace();
    }
    return null;
}

protected void onPostExecute() {
    pDialog.dismiss();
}


}

logcat是

09-25 06:11:27.970: E/AndroidRuntime(929): FATAL EXCEPTION: AsyncTask #5
09-25 06:11:27.970: E/AndroidRuntime(929): java.lang.RuntimeException: An error occured while executing doInBackground()
09-25 06:11:27.970: E/AndroidRuntime(929):  at android.os.AsyncTask$3.done(AsyncTask.java:299)
09-25 06:11:27.970: E/AndroidRuntime(929):  at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:352)
09-25 06:11:27.970: E/AndroidRuntime(929):  at java.util.concurrent.FutureTask.setException(FutureTask.java:219)
09-25 06:11:27.970: E/AndroidRuntime(929):  at java.util.concurrent.FutureTask.run(FutureTask.java:239)
09-25 06:11:27.970: E/AndroidRuntime(929):  at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
09-25 06:11:27.970: E/AndroidRuntime(929):  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
09-25 06:11:27.970: E/AndroidRuntime(929):  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
09-25 06:11:27.970: E/AndroidRuntime(929):  at java.lang.Thread.run(Thread.java:856)
09-25 06:11:27.970: E/AndroidRuntime(929): Caused by: java.lang.SecurityException: Permission denied (missing INTERNET permission?)
09-25 06:11:27.970: E/AndroidRuntime(929):  at java.net.InetAddress.lookupHostByName(InetAddress.java:418)
09-25 06:11:27.970: E/AndroidRuntime(929):  at java.net.InetAddress.getAllByNameImpl(InetAddress.java:236)
09-25 06:11:27.970: E/AndroidRuntime(929):  at java.net.InetAddress.getAllByName(InetAddress.java:214)
09-25 06:11:27.970: E/AndroidRuntime(929):  at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:137)
09-25 06:11:27.970: E/AndroidRuntime(929):  at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164)
09-25 06:11:27.970: E/AndroidRuntime(929):  at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119)
09-25 06:11:27.970: E/AndroidRuntime(929):  at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:360)
09-25 06:11:27.970: E/AndroidRuntime(929):  at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
09-25 06:11:27.970: E/AndroidRuntime(929):  at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
09-25 06:11:27.970: E/AndroidRuntime(929):  at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465)

2 个答案:

答案 0 :(得分:3)

  

引起:java.lang.SecurityException:权限被拒绝(缺失   互联网许可?)

在清单文件中添加

<uses-permission android:name="android.permission.INTERNET"/>

答案 1 :(得分:1)

在manifest.xml文件中添加Internet权限

<uses-permission android:name="android.permission.INTERNET"/>