現在のアクティビティから新しいアクティビティを開始しようとすると、リーク エラーが発生しました。現在のアクティビティは、新しいアクティビティを開始する前に正しく閉じられていると思います。コードのどこが間違っているかを特定するのを手伝ってもらえますか?
package com.example.mediastore;
import java.util.ArrayList;
import java.util.List;
import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONException;
import org.json.JSONObject;
import com.example.mediastore.JSONParser;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.text.InputFilter.LengthFilter;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class LoginActivity extends Activity {
Button login;
EditText inputusername;
EditText inputpassword;
private static String url_users = "http://10.0.2.2/mediastore/android/usersLogin.php";
private ProgressDialog pDialog;
JSONParser jsonParser = new JSONParser();
private static final String TAG_SUCCESS = "success";
boolean startActivity;
@Override
public void finish()
{
if (pDialog != null && pDialog.isShowing())
{
pDialog.dismiss();
}
}
@Override
public void onCreate(Bundle savedInstanceState) {
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
login = (Button) findViewById(R.id.loginbtn);
inputusername = (EditText) findViewById(R.id.username);
inputpassword = (EditText) findViewById(R.id.password);
login.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if(v == login) {
login.setBackgroundDrawable(getResources().getDrawable(R.drawable.button2));
}
String u = inputusername.getText().toString();
String p = inputpassword.getText().toString();
if(u.equals("")||p.equals(""))
Toast.makeText(getApplicationContext(), "Please fill these two fields", Toast.LENGTH_SHORT).show();
else{
new userLogin().execute();
}
}
});
}
class userLogin extends AsyncTask<String, String, String> {
/**
* Before starting background thread Show Progress Dialog
* */
@Override
protected void onPreExecute() {
super.onPreExecute();
pDialog = new ProgressDialog(LoginActivity.this);
pDialog.setMessage("Logging user..");
pDialog.setIndeterminate(false);
pDialog.setCancelable(true);
pDialog.show();
}
/**
* Creating product
* */
@SuppressLint("ShowToast")
protected String doInBackground(String... args) {
String username = inputusername.getText().toString();
String password = inputpassword.getText().toString();
// Building Parameters
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("username", username));
params.add(new BasicNameValuePair("password", password));
// getting JSON Object
// Note that create product url accepts POST method
JSONObject json = jsonParser.makeHttpRequest(url_users,
"POST", params);
// check log cat for response
Log.d("Login Response", json.toString());
// check for success tag
try {
int success = json.getInt(TAG_SUCCESS);
if (success == 1) {
// successfully created product
startActivity = true;
// closing this screen
finish();
} else {
// failed to create product
}
} catch (JSONException e) {
e.printStackTrace();
}
return null;
}
/**
* After completing background task Dismiss the progress dialog
* **/
protected void onPostExecute(String file_url) {
// dismiss the dialog once done
pDialog.dismiss();
if(startActivity){
Intent i = new Intent(getApplicationContext(), UserViewActivity.class);
startActivity(i);
}
}
}
}
これは丸太の猫です:
10-04 10:50:27.129: E/WindowManager(1629): Activity com.example.mediastore.LoginActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView{b5596468 V.E..... R.....ID 0,0-456,144} that was originally added here
10-04 10:50:27.129: E/WindowManager(1629): android.view.WindowLeaked: Activity com.example.mediastore.LoginActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView{b5596468 V.E..... R.....ID 0,0-456,144} that was originally added here
10-04 10:50:27.129: E/WindowManager(1629): at android.view.ViewRootImpl.<init>(ViewRootImpl.java:354)
10-04 10:50:27.129: E/WindowManager(1629): at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:216)
10-04 10:50:27.129: E/WindowManager(1629): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:69)
10-04 10:50:27.129: E/WindowManager(1629): at android.app.Dialog.show(Dialog.java:281)
10-04 10:50:27.129: E/WindowManager(1629): at com.example.mediastore.LoginActivity$userLogin.onPreExecute(LoginActivity.java:93)
10-04 10:50:27.129: E/WindowManager(1629): at android.os.AsyncTask.executeOnExecutor(AsyncTask.java:586)
10-04 10:50:27.129: E/WindowManager(1629): at android.os.AsyncTask.execute(AsyncTask.java:534)
10-04 10:50:27.129: E/WindowManager(1629): at com.example.mediastore.LoginActivity$1.onClick(LoginActivity.java:75)
10-04 10:50:27.129: E/WindowManager(1629): at android.view.View.performClick(View.java:4202)
10-04 10:50:27.129: E/WindowManager(1629): at android.view.View$PerformClick.run(View.java:17340)
10-04 10:50:27.129: E/WindowManager(1629): at android.os.Handler.handleCallback(Handler.java:725)
10-04 10:50:27.129: E/WindowManager(1629): at android.os.Handler.dispatchMessage(Handler.java:92)
10-04 10:50:27.129: E/WindowManager(1629): at android.os.Looper.loop(Looper.java:137)
10-04 10:50:27.129: E/WindowManager(1629): at android.app.ActivityThread.main(ActivityThread.java:5039)
10-04 10:50:27.129: E/WindowManager(1629): at java.lang.reflect.Method.invokeNative(Native Method)
10-04 10:50:27.129: E/WindowManager(1629): at java.lang.reflect.Method.invoke(Method.java:511)
10-04 10:50:27.129: E/WindowManager(1629): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
10-04 10:50:27.129: E/WindowManager(1629): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
10-04 10:50:27.129: E/WindowManager(1629): at dalvik.system.NativeStart.main(Native Method)
新しいエラー:
10-04 14:02:14.414: E/JSON Parser(1909): Error parsing data org.json.JSONException: Value <br of type java.lang.String cannot be converted to JSONObject
10-04 14:02:14.434: W/dalvikvm(1909): threadid=13: thread exiting with uncaught exception (group=0xb4d01908)
10-04 14:02:14.494: E/AndroidRuntime(1909): FATAL EXCEPTION: AsyncTask #3
10-04 14:02:14.494: E/AndroidRuntime(1909): java.lang.RuntimeException: An error occured while executing doInBackground()
10-04 14:02:14.494: E/AndroidRuntime(1909): at android.os.AsyncTask$3.done(AsyncTask.java:299)
10-04 14:02:14.494: E/AndroidRuntime(1909): at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:352)
10-04 14:02:14.494: E/AndroidRuntime(1909): at java.util.concurrent.FutureTask.setException(FutureTask.java:219)
10-04 14:02:14.494: E/AndroidRuntime(1909): at java.util.concurrent.FutureTask.run(FutureTask.java:239)
10-04 14:02:14.494: E/AndroidRuntime(1909): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
10-04 14:02:14.494: E/AndroidRuntime(1909): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
10-04 14:02:14.494: E/AndroidRuntime(1909): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
10-04 14:02:14.494: E/AndroidRuntime(1909): at java.lang.Thread.run(Thread.java:856)
10-04 14:02:14.494: E/AndroidRuntime(1909): Caused by: java.lang.NullPointerException
10-04 14:02:14.494: E/AndroidRuntime(1909): at com.example.mediastore.LoginActivity$userLogin.doInBackground(LoginActivity.java:123)
10-04 14:02:14.494: E/AndroidRuntime(1909): at com.example.mediastore.LoginActivity$userLogin.doInBackground(LoginActivity.java:1)
10-04 14:02:14.494: E/AndroidRuntime(1909): at android.os.AsyncTask$2.call(AsyncTask.java:287)
10-04 14:02:14.494: E/AndroidRuntime(1909): at java.util.concurrent.FutureTask.run(FutureTask.java:234)
10-04 14:02:14.494: E/AndroidRuntime(1909): ... 4 more
10-04 14:02:19.734: E/WindowManager(1909): Activity com.example.mediastore.LoginActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView{b55038e8 V.E..... R.....ID 0,0-456,144} that was originally added here
10-04 14:02:19.734: E/WindowManager(1909): android.view.WindowLeaked: Activity com.example.mediastore.LoginActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView{b55038e8 V.E..... R.....ID 0,0-456,144} that was originally added here
10-04 14:02:19.734: E/WindowManager(1909): at android.view.ViewRootImpl.<init>(ViewRootImpl.java:354)
10-04 14:02:19.734: E/WindowManager(1909): at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:216)
10-04 14:02:19.734: E/WindowManager(1909): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:69)
10-04 14:02:19.734: E/WindowManager(1909): at android.app.Dialog.show(Dialog.java:281)
10-04 14:02:19.734: E/WindowManager(1909): at com.example.mediastore.LoginActivity$userLogin$1.run(LoginActivity.java:99)
10-04 14:02:19.734: E/WindowManager(1909): at android.os.Handler.handleCallback(Handler.java:725)
10-04 14:02:19.734: E/WindowManager(1909): at android.os.Handler.dispatchMessage(Handler.java:92)
10-04 14:02:19.734: E/WindowManager(1909): at android.os.Looper.loop(Looper.java:137)
10-04 14:02:19.734: E/WindowManager(1909): at android.app.ActivityThread.main(ActivityThread.java:5039)
10-04 14:02:19.734: E/WindowManager(1909): at java.lang.reflect.Method.invokeNative(Native Method)
10-04 14:02:19.734: E/WindowManager(1909): at java.lang.reflect.Method.invoke(Method.java:511)
10-04 14:02:19.734: E/WindowManager(1909): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
10-04 14:02:19.734: E/WindowManager(1909): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
10-04 14:02:19.734: E/WindowManager(1909): at dalvik.system.NativeStart.main(Native Method)