当我点击发送时该应用停止工作

时间:2016-01-14 07:52:18

标签: android-studio android-asynctask fatal-error

按钮的代码是

   b.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            s = DateEdit.getText().toString();

            new AsyncTaskPayment().execute(s);
        }
    });

异步类是

  private class AsyncTaskPayment extends AsyncTask<String, Void, Void> {

    private final HttpClient Client = new DefaultHttpClient();
    private String Content;
    private String Error = null;
    private final String TAG = null;

    private ProgressDialog Dialog = new ProgressDialog(MainActivity.this);

    @Override
    protected void onPreExecute() {
        Dialog.setMessage("Wait..");
        Dialog.show();
        Log.e(TAG, "------------------------------------- Here");
    }


    protected Void doInBackground(String... urls) {

        try {
            HttpPost httppost = new HttpPost(URL);

            // Field

            JSONObject jObject = new JSONObject();
            jObject.put("classname", s);
            jObject.put("time", s);
            jObject.put("faculty", s);
            jObject.put("message", s);
            MultipartEntityBuilder se = MultipartEntityBuilder.create();

            se.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);
            se.addPart("request", new StringBody(jObject.toString()));
            httppost.setEntity((org.apache.http.HttpEntity) se);

            HttpResponse resp = Client.execute(httppost);

            Content = EntityUtils.toString(resp.getEntity());

            Log.e("Response", "--------------------------------" + Content);

        } catch (JSONException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (UnsupportedEncodingException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (ClientProtocolException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return null;
    }

这是我得到的调试错误

  

01-14 07:33:08.359 2246-2268 / com.push.ra1.cancel E / AndroidRuntime?致命异常:AsyncTask#1       处理:com.push.ra1.cancel,PID:2246       java.lang.RuntimeException:执行doInBackground()时发生错误               在android.os.AsyncTask $ 3.done(AsyncTask.java:304)               在java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:355)               at java.util.concurrent.FutureTask.setException(FutureTask.java:222)               在java.util.concurrent.FutureTask.run(FutureTask.java:242)               在android.os.AsyncTask $ SerialExecutor $ 1.run(AsyncTask.java:231)               at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)               at java.util.concurrent.ThreadPoolExecutor $ Worker.run(ThreadPoolExecutor.java:587)               在java.lang.Thread.run(Thread.java:818)        引起:java.lang.NoClassDefFoundError:解析失败:Lorg / apache / http / Consts;               在org.apache.http.entity.mime.content.StringBody。(StringBody.java:147)               在com.push.ra1.cancel.MainActivity $ AsyncTaskPayment.doInBackground(MainActivity.java:154)               在com.push.ra1.cancel.MainActivity $ AsyncTaskPayment.doInBackground(MainActivity.java:120)               在android.os.AsyncTask $ 2.call(AsyncTask.java:292)               在java.util.concurrent.FutureTask.run(FutureTask.java:237)               在android.os.AsyncTask $ SerialExecutor $ 1.run(AsyncTask.java:231)               at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)               at java.util.concurrent.ThreadPoolExecutor $ Worker.run(ThreadPoolExecutor.java:587)               在java.lang.Thread.run(Thread.java:818)        引起:java.lang.ClassNotFoundException:没找到类&#34; org.apache.http.Consts&#34; on path:DexPathList [[zip file&#34; /data/app/com.push.ra1.cancel-1/base.apk"],nativeLibraryDirectories = [/ vendor / lib,/ system / lib]]               在dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)               at java.lang.ClassLoader.loadClass(ClassLoader.java:511)               at java.lang.ClassLoader.loadClass(ClassLoader.java:469)               在org.apache.http.entity.mime.content.StringBody。(StringBody.java:147)               在com.push.ra1.cancel.MainActivity $ AsyncTaskPayment.doInBackground(MainActivity.java:154)               在com.push.ra1.cancel.MainActivity $ AsyncTaskPayment.doInBackground(MainActivity.java:120)               在android.os.AsyncTask $ 2.call(AsyncTask.java:292)               在java.util.concurrent.FutureTask.run(FutureTask.java:237)               在android.os.AsyncTask $ SerialExecutor $ 1.run(AsyncTask.java:231)               at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)               at java.util.concurrent.ThreadPoolExecutor $ Worker.run(ThreadPoolExecutor.java:587)               在java.lang.Thread.run(Thread.java:818)       抑制:java.lang.ClassNotFoundException:org.apache.http.Consts               at java.lang.Class.classForName(Native Method)               at java.lang.BootClassLoader.findClass(ClassLoader.java:781)               at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)               at java.lang.ClassLoader.loadClass(ClassLoader.java:504)               ......还有10个        引起:java.lang.NoClassDefFoundError:使用引导类加载器找不到类;没有堆栈可用   01-14 07:33:10.669 2246-2246 / com.push.ra1.cancel I / Choreographer?跳过70帧!应用程序可能在其主线程上做了太多工作。   01-14 07:33:17.331 2246-2246 / com.push.ra1.cancel I / Choreographer?跳过80帧!应用程序可能在其主线程上做了太多工作。   01-14 07:33:23.327 2246-2246 / com.push.ra1.cancel E / WindowManager? android.view.WindowLeaked:Activity com.push.ra1.cancel.MainActivity泄露了窗口com.android.internal.policy.impl.PhoneWindow $ DecorView {1586a180 VE .... R ...... D 0,0 -684,232}最初是在这里添加的               在android.view.ViewRootImpl。(ViewRootImpl.java:363)               在android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:271)               在android.view.WindowManagerImpl.addView(WindowManagerImpl.java:85)               在android.app.Dialog.show(Dialog.java:298)               at com.push.ra1.cancel.MainActivity $ AsyncTaskPayment.onPreExecute(MainActivity.java:132)               在android.os.AsyncTask.executeOnExecutor(AsyncTask.java:591)               在android.os.AsyncTask.execute(AsyncTask.java:539)               在com.push.ra1.cancel.MainActivity $ 2.onClick(MainActivity.java:63)               在android.view.View.performClick(View.java:4780)               在android.view.View $ PerformClick.run(View.java:19866)               在android.os.Handler.handleCallback(Handler.java:739)               在android.os.Handler.dispatchMessage(Handler.java:95)               在android.os.Looper.loop(Looper.java:135)               在android.app.ActivityThread.main(ActivityThread.java:5257)               at java.lang.reflect.Method.invoke(Native Method)               在java.lang.reflect.Method.invoke(Method.java:372)               在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:903)               在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)

0 个答案:

没有答案