こんにちは、ログインページがある新しいAndroidアプリを開発しています。ユーザーがユーザー名を入力すると、ユーザー名がテーブルにあるユーザー名でチェックされます...存在する場合は、「ユーザー名」が存在するようにメッセージが表示されます別のユーザー名を使用してください...そのために1つのphpファイルを作成し、アクティビティにコードを追加しました...そして、メッセージを表示するユーザー名が登録されていない場合、Androidにトーストメッセージを追加しました..しかし、そのメッセージを追加すると、アプリケーションはcrashibngになります「残念ながらアプリケーションは閉じられました」それを削除すると..アプリケーションはクラッシュしませんが、ページに残ります..PHPコードとアクティビティコードを追加しています..誰かが助けてくれるかどうかを確認してください...
アクティビティ
/**
* Background Async Task to Create new product
* */
class CreateNewProduct extends AsyncTask<String, String, String> {
/**
* Before starting background thread Show Progress Dialog
* */
@Override
protected void onPreExecute() {
super.onPreExecute();
pDialog = new ProgressDialog(SignUpActivity.this);
pDialog.setMessage("Creating a new account..");
pDialog.setIndeterminate(false);
pDialog.setCancelable(true);
pDialog.show();
}
/**
* Creating product
* */
protected String doInBackground(String... args) {
String name = editTextUserName.getText().toString();
String password = editTextPassword.getText().toString();
String mobile = editMobileNumber.getText().toString();
String sms = Integer.toString(number);
// Building Parameters
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("name", name));
params.add(new BasicNameValuePair("password", password));
params.add(new BasicNameValuePair("mobile", mobile));
// getting JSON Object
// Note that create product url accepts POST method
JSONObject json = jsonParser.makeHttpRequest(url_create_data,
"POST", params);
// check log cat fro response
Log.d("Create Response", json.toString());
// check for success tag
try {
int success = json.getInt(TAG_SUCCESS);
if (success == 1) {
// successfully created product
Intent i = new Intent(SignUpActivity.this, RegisterActivity.class);
i.putExtra("number", sms + "");
startActivity(i);
//closing this screen
//finish();
} else {
// failed to create product
return "false";
}
protected void onPostExecute(String result)
{
// TODO Auto-generated method stub
super.onPostExecute(result);
if (result == "false")
Toast.makeText(SignUpActivity.this, "User Name already exists. Please choose another user name ", Toast.LENGTH_LONG).show();
}
} 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();
}
}
}
PHP コード
<?php
// array for JSON response
$response = array();
// check for required fields
if (isset($_POST['name']) && isset($_POST['password']) && isset($_POST['mobile'])) {
$name = $_POST['name'];
$password = $_POST['password'];
$mobile = $_POST['mobile'];
// include db connect class
require_once __DIR__ . '/db_connect.php';
// connecting to db
$db = new DB_CONNECT();
$result1 = mysql_query("SELECT name FROM numerol WHERE name = '$name'");
if (!mysql_num_rows($result1))
{
// mysql inserting a new row
$result = mysql_query("INSERT INTO numerol(name, password, mobile) VALUES('$name', '$password',
'$mobile')");
// check if row inserted or not
if ($result) {
// successfully inserted into database
$response["success"] = 1;
$response["message"] = "Product successfully created.";
// echoing JSON response
echo json_encode($response);
} else {
// failed to insert row
$response["success"] = 0;
$response["message"] = "Oops! An error occurred.";
// echoing JSON response
echo json_encode($response);
}
} else {
// required field is missing
$response["success"] = 0;
$response["message"] = "Required field(s) is missing";
// echoing JSON response
echo json_encode($response);
}
}
else
{
echo 'User Name already exists, Please choose another username';
}
?>
ログキャット
11-09 06:12:48.081: I/Choreographer(1792): Skipped 33 frames! The application may be doing too much work on its main thread.
11-09 06:12:49.091: I/Choreographer(1792): Skipped 30 frames! The application may be doing too much work on its main thread.
11-09 06:12:49.561: I/Choreographer(1792): Skipped 36 frames! The application may be doing too much work on its main thread.
11-09 06:12:50.512: I/Choreographer(1792): Skipped 49 frames! The application may be doing too much work on its main thread.
11-09 06:12:50.660: I/Choreographer(1792): Skipped 34 frames! The application may be doing too much work on its main thread.
11-09 06:12:51.220: I/Choreographer(1792): Skipped 50 frames! The application may be doing too much work on its main thread.
11-09 06:12:51.841: I/Choreographer(1792): Skipped 45 frames! The application may be doing too much work on its main thread.
11-09 06:12:52.561: I/Choreographer(1792): Skipped 78 frames! The application may be doing too much work on its main thread.
11-09 06:12:52.731: I/Choreographer(1792): Skipped 44 frames! The application may be doing too much work on its main thread.
11-09 06:12:54.050: I/Choreographer(1792): Skipped 340 frames! The application may be doing too much work on its main thread.
11-09 06:12:54.230: I/Choreographer(1792): Skipped 47 frames! The application may be doing too much work on its main thread.
11-09 06:12:54.570: I/Choreographer(1792): Skipped 76 frames! The application may be doing too much work on its main thread.
11-09 06:12:56.263: I/Choreographer(1792): Skipped 438 frames! The application may be doing too much work on its main thread.
11-09 06:12:56.570: I/Choreographer(1792): Skipped 70 frames! The application may be doing too much work on its main thread.
11-09 06:12:57.830: E/WindowManager(1792): Activity com.example.numero.SignUpActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView{40e2e678 V.E..... R.....ID 0,0-456,144} that was originally added here
11-09 06:12:57.830: E/WindowManager(1792): android.view.WindowLeaked: Activity com.example.numero.SignUpActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView{40e2e678 V.E..... R.....ID 0,0-456,144} that was originally added here
11-09 06:12:57.830: E/WindowManager(1792): at android.view.ViewRootImpl.<init>(ViewRootImpl.java:354)
11-09 06:12:57.830: E/WindowManager(1792): at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:216)
11-09 06:12:57.830: E/WindowManager(1792): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:69)
11-09 06:12:57.830: E/WindowManager(1792): at android.app.Dialog.show(Dialog.java:281)
11-09 06:12:57.830: E/WindowManager(1792): at com.example.numero.SignUpActivity$CreateNewProduct.onPreExecute(SignUpActivity.java:295)
11-09 06:12:57.830: E/WindowManager(1792): at android.os.AsyncTask.executeOnExecutor(AsyncTask.java:586)
11-09 06:12:57.830: E/WindowManager(1792): at android.os.AsyncTask.execute(AsyncTask.java:534)
11-09 06:12:57.830: E/WindowManager(1792): at com.example.numero.SignUpActivity$1.onClick(SignUpActivity.java:163)
11-09 06:12:57.830: E/WindowManager(1792): at android.view.View.performClick(View.java:4204)
11-09 06:12:57.830: E/WindowManager(1792): at android.view.View$PerformClick.run(View.java:17355)
11-09 06:12:57.830: E/WindowManager(1792): at android.os.Handler.handleCallback(Handler.java:725)
11-09 06:12:57.830: E/WindowManager(1792): at android.os.Handler.dispatchMessage(Handler.java:92)
11-09 06:12:57.830: E/WindowManager(1792): at android.os.Looper.loop(Looper.java:137)
11-09 06:12:57.830: E/WindowManager(1792): at android.app.ActivityThread.main(ActivityThread.java:5041)
11-09 06:12:57.830: E/WindowManager(1792): at java.lang.reflect.Method.invokeNative(Native Method)
11-09 06:12:57.830: E/WindowManager(1792): at java.lang.reflect.Method.invoke(Method.java:511)
11-09 06:12:57.830: E/WindowManager(1792): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
11-09 06:12:57.830: E/WindowManager(1792): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
11-09 06:12:57.830: E/WindowManager(1792): at dalvik.system.NativeStart.main(Native Method)
11-09 06:12:57.861: I/Choreographer(1792): Skipped 92 frames! The application may be doing too much work on its main thread.
11-09 06:12:58.062: E/ActivityThread(1792): Activity com.example.numero.SignUpActivity has leaked IntentReceiver com.example.numero.SignUpActivity$2@40d4eed0 that was originally registered here. Are you missing a call to unregisterReceiver()?
11-09 06:12:58.062: E/ActivityThread(1792): android.app.IntentReceiverLeaked: Activity com.example.numero.SignUpActivity has leaked IntentReceiver com.example.numero.SignUpActivity$2@40d4eed0 that was originally registered here. Are you missing a call to unregisterReceiver()?
11-09 06:12:58.062: E/ActivityThread(1792): at android.app.LoadedApk$ReceiverDispatcher.<init>(LoadedApk.java:795)
11-09 06:12:58.062: E/ActivityThread(1792): at android.app.LoadedApk.getReceiverDispatcher(LoadedApk.java:596)
11-09 06:12:58.062: E/ActivityThread(1792): at android.app.ContextImpl.registerReceiverInternal(ContextImpl.java:1316)
11-09 06:12:58.062: E/ActivityThread(1792): at android.app.ContextImpl.registerReceiver(ContextImpl.java:1296)
11-09 06:12:58.062: E/ActivityThread(1792): at android.app.ContextImpl.registerReceiver(ContextImpl.java:1290)
11-09 06:12:58.062: E/ActivityThread(1792): at android.content.ContextWrapper.registerReceiver(ContextWrapper.java:423)
11-09 06:12:58.062: E/ActivityThread(1792): at com.example.numero.SignUpActivity.sendSMS(SignUpActivity.java:205)
11-09 06:12:58.062: E/ActivityThread(1792): at com.example.numero.SignUpActivity.access$3(SignUpActivity.java:193)
11-09 06:12:58.062: E/ActivityThread(1792): at com.example.numero.SignUpActivity$1.onClick(SignUpActivity.java:117)
11-09 06:12:58.062: E/ActivityThread(1792): at android.view.View.performClick(View.java:4204)
11-09 06:12:58.062: E/ActivityThread(1792): at android.view.View$PerformClick.run(View.java:17355)
11-09 06:12:58.062: E/ActivityThread(1792): at android.os.Handler.handleCallback(Handler.java:725)
11-09 06:12:58.062: E/ActivityThread(1792): at android.os.Handler.dispatchMessage(Handler.java:92)
11-09 06:12:58.062: E/ActivityThread(1792): at android.os.Looper.loop(Looper.java:137)
11-09 06:12:58.062: E/ActivityThread(1792): at android.app.ActivityThread.main(ActivityThread.java:5041)
11-09 06:12:58.062: E/ActivityThread(1792): at java.lang.reflect.Method.invokeNative(Native Method)
11-09 06:12:58.062: E/ActivityThread(1792): at java.lang.reflect.Method.invoke(Method.java:511)
11-09 06:12:58.062: E/ActivityThread(1792): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
11-09 06:12:58.062: E/ActivityThread(1792): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
11-09 06:12:58.062: E/ActivityThread(1792): at dalvik.system.NativeStart.main(Native Method)
11-09 06:12:58.140: E/ActivityThread(1792): Activity com.example.numero.SignUpActivity has leaked IntentReceiver com.example.numero.SignUpActivity$3@40e35ab0 that was originally registered here. Are you missing a call to unregisterReceiver()?
11-09 06:12:58.140: E/ActivityThread(1792): android.app.IntentReceiverLeaked: Activity com.example.numero.SignUpActivity has leaked IntentReceiver com.example.numero.SignUpActivity$3@40e35ab0 that was originally registered here. Are you missing a call to unregisterReceiver()?
11-09 06:12:58.140: E/ActivityThread(1792): at android.app.LoadedApk$ReceiverDispatcher.<init>(LoadedApk.java:795)
11-09 06:12:58.140: E/ActivityThread(1792): at android.app.LoadedApk.getReceiverDispatcher(LoadedApk.java:596)
11-09 06:12:58.140: E/ActivityThread(1792): at android.app.ContextImpl.registerReceiverInternal(ContextImpl.java:1316)
11-09 06:12:58.140: E/ActivityThread(1792): at android.app.ContextImpl.registerReceiver(ContextImpl.java:1296)
11-09 06:12:58.140: E/ActivityThread(1792): at android.app.ContextImpl.registerReceiver(ContextImpl.java:1290)
11-09 06:12:58.140: E/ActivityThread(1792): at android.content.ContextWrapper.registerReceiver(ContextWrapper.java:423)
11-09 06:12:58.140: E/ActivityThread(1792): at com.example.numero.SignUpActivity.sendSMS(SignUpActivity.java:235)
11-09 06:12:58.140: E/ActivityThread(1792): at com.example.numero.SignUpActivity.access$3(SignUpActivity.java:193)
11-09 06:12:58.140: E/ActivityThread(1792): at com.example.numero.SignUpActivity$1.onClick(SignUpActivity.java:117)
11-09 06:12:58.140: E/ActivityThread(1792): at android.view.View.performClick(View.java:4204)
11-09 06:12:58.140: E/ActivityThread(1792): at android.view.View$PerformClick.run(View.java:17355)
11-09 06:12:58.140: E/ActivityThread(1792): at android.os.Handler.handleCallback(Handler.java:725)
11-09 06:12:58.140: E/ActivityThread(1792): at android.os.Handler.dispatchMessage(Handler.java:92)
11-09 06:12:58.140: E/ActivityThread(1792): at android.os.Looper.loop(Looper.java:137)
11-09 06:12:58.140: E/ActivityThread(1792): at android.app.ActivityThread.main(ActivityThread.java:5041)
11-09 06:12:58.140: E/ActivityThread(1792): at java.lang.reflect.Method.invokeNative(Native Method)
11-09 06:12:58.140: E/ActivityThread(1792): at java.lang.reflect.Method.invoke(Method.java:511)
11-09 06:12:58.140: E/ActivityThread(1792): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
11-09 06:12:58.140: E/ActivityThread(1792): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
11-09 06:12:58.140: E/ActivityThread(1792): at dalvik.system.NativeStart.main(Native Method)
11-09 06:12:58.291: E/ActivityThread(1792): Activity com.example.numero.SignUpActivity has leaked IntentReceiver com.example.numero.SignUpActivity$2@40e357c0 that was originally registered here. Are you missing a call to unregisterReceiver()?
11-09 06:12:58.291: E/ActivityThread(1792): android.app.IntentReceiverLeaked: Activity com.example.numero.SignUpActivity has leaked IntentReceiver com.example.numero.SignUpActivity$2@40e357c0 that was originally registered here. Are you missing a call to unregisterReceiver()?
11-09 06:12:58.291: E/ActivityThread(1792): at android.app.LoadedApk$ReceiverDispatcher.<init>(LoadedApk.java:795)
11-09 06:12:58.291: E/ActivityThread(1792): at android.app.LoadedApk.getReceiverDispatcher(LoadedApk.java:596)
11-09 06:12:58.291: E/ActivityThread(1792): at android.app.ContextImpl.registerReceiverInternal(ContextImpl.java:1316)
11-09 06:12:58.291: E/ActivityThread(1792): at android.app.ContextImpl.registerReceiver(ContextImpl.java:1296)
11-09 06:12:58.291: E/ActivityThread(1792): at android.app.ContextImpl.registerReceiver(ContextImpl.java:1290)
11-09 06:12:58.291: E/ActivityThread(1792): at android.content.ContextWrapper.registerReceiver(ContextWrapper.java:423)
11-09 06:12:58.291: E/ActivityThread(1792): at com.example.numero.SignUpActivity.sendSMS(SignUpActivity.java:205)
11-09 06:12:58.291: E/ActivityThread(1792): at com.example.numero.SignUpActivity.access$3(SignUpActivity.java:193)
11-09 06:12:58.291: E/ActivityThread(1792): at com.example.numero.SignUpActivity$1.onClick(SignUpActivity.java:117)
11-09 06:12:58.291: E/ActivityThread(1792): at android.view.View.performClick(View.java:4204)
11-09 06:12:58.291: E/ActivityThread(1792): at android.view.View$PerformClick.run(View.java:17355)
11-09 06:12:58.291: E/ActivityThread(1792): at android.os.Handler.handleCallback(Handler.java:725)
11-09 06:12:58.291: E/ActivityThread(1792): at android.os.Handler.dispatchMessage(Handler.java:92)
11-09 06:12:58.291: E/ActivityThread(1792): at android.os.Looper.loop(Looper.java:137)
11-09 06:12:58.291: E/ActivityThread(1792): at android.app.ActivityThread.main(ActivityThread.java:5041)
11-09 06:12:58.291: E/ActivityThread(1792): at java.lang.reflect.Method.invokeNative(Native Method)
11-09 06:12:58.291: E/ActivityThread(1792): at java.lang.reflect.Method.invoke(Method.java:511)
11-09 06:12:58.291: E/ActivityThread(1792): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
11-09 06:12:58.291: E/ActivityThread(1792): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
11-09 06:12:58.291: E/ActivityThread(1792): at dalvik.system.NativeStart.main(Native Method)
11-09 06:12:58.350: D/dalvikvm(1792): GC_CONCURRENT freed 480K, 14% free 3822K/4412K, paused 77ms+114ms, total 413ms
11-09 06:12:58.400: E/ActivityThread(1792): Activity com.example.numero.SignUpActivity has leaked IntentReceiver com.example.numero.SignUpActivity$3@40d4f558 that was originally registered here. Are you missing a call to unregisterReceiver()?
11-09 06:12:58.400: E/ActivityThread(1792): android.app.IntentReceiverLeaked: Activity com.example.numero.SignUpActivity has leaked IntentReceiver com.example.numero.SignUpActivity$3@40d4f558 that was originally registered here. Are you missing a call to unregisterReceiver()?
11-09 06:12:58.400: E/ActivityThread(1792): at android.app.LoadedApk$ReceiverDispatcher.<init>(LoadedApk.java:795)
11-09 06:12:58.400: E/ActivityThread(1792): at android.app.LoadedApk.getReceiverDispatcher(LoadedApk.java:596)
11-09 06:12:58.400: E/ActivityThread(1792): at android.app.ContextImpl.registerReceiverInternal(ContextImpl.java:1316)
11-09 06:12:58.400: E/ActivityThread(1792): at android.app.ContextImpl.registerReceiver(ContextImpl.java:1296)
11-09 06:12:58.400: E/ActivityThread(1792): at android.app.ContextImpl.registerReceiver(ContextImpl.java:1290)
11-09 06:12:58.400: E/ActivityThread(1792): at android.content.ContextWrapper.registerReceiver(ContextWrapper.java:423)
11-09 06:12:58.400: E/ActivityThread(1792): at com.example.numero.SignUpActivity.sendSMS(SignUpActivity.java:235)
11-09 06:12:58.400: E/ActivityThread(1792): at com.example.numero.SignUpActivity.access$3(SignUpActivity.java:193)
11-09 06:12:58.400: E/ActivityThread(1792): at com.example.numero.SignUpActivity$1.onClick(SignUpActivity.java:117)
11-09 06:12:58.400: E/ActivityThread(1792): at android.view.View.performClick(View.java:4204)
11-09 06:12:58.400: E/ActivityThread(1792): at android.view.View$PerformClick.run(View.java:17355)
11-09 06:12:58.400: E/ActivityThread(1792): at android.os.Handler.handleCallback(Handler.java:725)
11-09 06:12:58.400: E/ActivityThread(1792): at android.os.Handler.dispatchMessage(Handler.java:92)
11-09 06:12:58.400: E/ActivityThread(1792): at android.os.Looper.loop(Looper.java:137)
11-09 06:12:58.400: E/ActivityThread(1792): at android.app.ActivityThread.main(ActivityThread.java:5041)
11-09 06:12:58.400: E/ActivityThread(1792): at java.lang.reflect.Method.invokeNative(Native Method)
11-09 06:12:58.400: E/ActivityThread(1792): at java.lang.reflect.Method.invoke(Method.java:511)
11-09 06:12:58.400: E/ActivityThread(1792): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
11-09 06:12:58.400: E/ActivityThread(1792): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
11-09 06:12:58.400: E/ActivityThread(1792): at dalvik.system.NativeStart.main(Native Method)
11-09 06:13:08.551: I/Process(1792): Sending signal. PID: 1792 SIG: 9