0

我的应用程序有问题。我正在为我的公司从时间线上的帖子中检索评论。当帖子有评论时,它就像一个魅力,但是当帖子没有评论时,应用程序崩溃并给我这个错误:

10-11 02:01:06.055: E/WindowManager(931): Activity com.gettford.community.SingleItemView has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@41767060 that was originally added here
10-11 02:01:06.055: E/WindowManager(931): android.view.WindowLeaked: Activity com.gettford.community.SingleItemView has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@41767060 that was originally added here
10-11 02:01:06.055: E/WindowManager(931):   at android.view.ViewRootImpl.<init>(ViewRootImpl.java:344)
10-11 02:01:06.055: E/WindowManager(931):   at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:267)
10-11 02:01:06.055: E/WindowManager(931):   at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:215)
10-11 02:01:06.055: E/WindowManager(931):   at android.view.WindowManagerImpl$CompatModeWrapper.addView(WindowManagerImpl.java:140)
10-11 02:01:06.055: E/WindowManager(931):   at android.view.Window$LocalWindowManager.addView(Window.java:537)
10-11 02:01:06.055: E/WindowManager(931):   at android.app.Dialog.show(Dialog.java:278)
10-11 02:01:06.055: E/WindowManager(931):   at com.gettford.community.SingleItemView$DownloadJSON.onPreExecute(SingleItemView.java:113)
10-11 02:01:06.055: E/WindowManager(931):   at android.os.AsyncTask.executeOnExecutor(AsyncTask.java:561)
10-11 02:01:06.055: E/WindowManager(931):   at android.os.AsyncTask.execute(AsyncTask.java:511)
10-11 02:01:06.055: E/WindowManager(931):   at com.gettford.community.SingleItemView.onCreate(SingleItemView.java:70)
10-11 02:01:06.055: E/WindowManager(931):   at android.app.Activity.performCreate(Activity.java:4465)
10-11 02:01:06.055: E/WindowManager(931):   at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
10-11 02:01:06.055: E/WindowManager(931):   at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
10-11 02:01:06.055: E/WindowManager(931):   at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
10-11 02:01:06.055: E/WindowManager(931):   at android.app.ActivityThread.access$600(ActivityThread.java:123)
10-11 02:01:06.055: E/WindowManager(931):   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
10-11 02:01:06.055: E/WindowManager(931):   at android.os.Handler.dispatchMessage(Handler.java:99)
10-11 02:01:06.055: E/WindowManager(931):   at android.os.Looper.loop(Looper.java:137)
10-11 02:01:06.055: E/WindowManager(931):   at android.app.ActivityThread.main(ActivityThread.java:4424)
10-11 02:01:06.055: E/WindowManager(931):   at java.lang.reflect.Method.invokeNative(Native Method)
10-11 02:01:06.055: E/WindowManager(931):   at java.lang.reflect.Method.invoke(Method.java:511)
10-11 02:01:06.055: E/WindowManager(931):   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
10-11 02:01:06.055: E/WindowManager(931):   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
10-11 02:01:06.055: E/WindowManager(931):   at dalvik.system.NativeStart.main(Native Method)

大约两周前我已经开始对 Android 进行编程,所以我对 Java 还是很陌生,我的主要语言是 PHP。

我希望你能帮我找到问题。

检索评论的代码是这样的,我放了一个“尝试”来捕捉错误,但应用程序就死了。

public class DownloadJSON extends AsyncTask<Void, Void, Void> {

    @Override
    protected void onPreExecute() {
        super.onPreExecute();
        // Create a progressdialog
        mProgressDialog = new ProgressDialog(SingleItemView.this);
        // Set progressdialog title
        mProgressDialog.setTitle("Comentarios del post");
        // Set progressdialog message
        mProgressDialog.setMessage("Cargando...");
        mProgressDialog.setIndeterminate(false);
        // Show progressdialog
        mProgressDialog.show();
    }

    @Override
    protected Void doInBackground(Void... params) {
        // Create an array
        arraylist2 = new ArrayList<HashMap<String, String>>();
        // Retrieve JSON Objects from the given URL address
        jsonobject1 = JSONfunctions
                .getJSONfromURL("http://server.net/file.php?userID="+usuarioID+"&idpost="+idpost+"");

        try {
            // Locate the array name in JSON
            jsonarray1 = jsonobject1.getJSONArray("comentarios");

            for (int i = 0; i < jsonarray1.length(); i++) {
                HashMap<String, String> maps = new HashMap<String, String>();
                jsonobject1 = jsonarray1.getJSONObject(i);
                // Retrive JSON Objects

                maps.put("quiencom", jsonobject1.getString("quien"));
                maps.put("imagencom", jsonobject1.getString("imagen"));
                maps.put("comentario", jsonobject1.getString("comentario"));
                maps.put("fechacom", jsonobject1.getString("fecha"));
                // Set the JSON Objects into the array
                arraylist2.add(maps);
            }
        } catch (JSONException e) {
            Log.e("Error", e.getMessage());
            e.printStackTrace();
        }
        return null;
    }

    @Override
    protected void onPostExecute(Void args) {
        // Locate the listview in listview_main.xml
        listview = (ListView) findViewById(R.id.listcoments);
        // Pass the results into ListViewAdapter.java
        adapter = new ListComentAdapter(SingleItemView.this, arraylist2);
        // Set the adapter to the ListView
        listview.setAdapter(adapter);
        // Close the progressdialog
        mProgressDialog.dismiss();
    }
}
4

0 回答 0