アプリに問題があります。会社のタイムラインの投稿からコメントを取得しています。投稿にコメントがある場合は魅力的に機能しますが、投稿にコメントがない場合はアプリがクラッシュし、次のエラーが表示されます。
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)
私はほぼ 2 週間前に Android へのプログラミングを開始したので、Java にはかなり慣れていません。私の主な言語は PHP です。
問題を見つけるのを手伝ってくれることを願っています。
コメントを取得するコードはこれです。エラーをキャッチするために「try」を入力しましたが、アプリは停止します。
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();
}
}