Código:
aqui lo que hago es preguntar si JSON devolvio un "1" o "0" cuando recive el "1" todo marcha bien y hago algo...pero cuando recibo un "0" se cancela la palicacion....alguien que me ayude con esto por favor le pongo error que me muestra el log CAttry { int success = json.getInt(TAG_SUCCESS); if (success == 1) { Intent i = getIntent(); setResult(100, i); finish(); } if (success == 0) { Toast.makeText(getApplicationContext(), "Espere hay un error...", Toast.LENGTH_SHORT).show(); } } catch (JSONException e) { e.printStackTrace(); }
Código:
06-21 18:49:51.309: E/AndroidRuntime(348): FATAL EXCEPTION: AsyncTask #3 06-21 18:49:51.309: E/AndroidRuntime(348): java.lang.RuntimeException: An error occured while executing doInBackground() 06-21 18:49:51.309: E/AndroidRuntime(348): at android.os.AsyncTask$3.done(AsyncTask.java:200) 06-21 18:49:51.309: E/AndroidRuntime(348): at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:274) 06-21 18:49:51.309: E/AndroidRuntime(348): at java.util.concurrent.FutureTask.setException(FutureTask.java:125) 06-21 18:49:51.309: E/AndroidRuntime(348): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:308) 06-21 18:49:51.309: E/AndroidRuntime(348): at java.util.concurrent.FutureTask.run(FutureTask.java:138) 06-21 18:49:51.309: E/AndroidRuntime(348): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1088) 06-21 18:49:51.309: E/AndroidRuntime(348): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:581) 06-21 18:49:51.309: E/AndroidRuntime(348): at java.lang.Thread.run(Thread.java:1019) 06-21 18:49:51.309: E/AndroidRuntime(348): Caused by: java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare() 06-21 18:49:51.309: E/AndroidRuntime(348): at android.os.Handler.<init>(Handler.java:121) 06-21 18:49:51.309: E/AndroidRuntime(348): at android.widget.Toast.<init>(Toast.java:68) 06-21 18:49:51.309: E/AndroidRuntime(348): at android.widget.Toast.makeText(Toast.java:231) 06-21 18:49:51.309: E/AndroidRuntime(348): at com.example.taller06oct.EditEmpleadosActivity$SaveEmpleadoDetails.doInBackground(EditEmpleadosActivity.java:275) 06-21 18:49:51.309: E/AndroidRuntime(348): at com.example.taller06oct.EditEmpleadosActivity$SaveEmpleadoDetails.doInBackground(EditEmpleadosActivity.java:1) 06-21 18:49:51.309: E/AndroidRuntime(348): at android.os.AsyncTask$2.call(AsyncTask.java:185) 06-21 18:49:51.309: E/AndroidRuntime(348): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:306) 06-21 18:49:51.309: E/AndroidRuntime(348): ... 4 more 06-21 18:49:54.459: E/WindowManager(348): Activity com.example.taller06oct.EditEmpleadosActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@40586d08 that was originally added here 06-21 18:49:54.459: E/WindowManager(348): android.view.WindowLeaked: Activity com.example.taller06oct.EditEmpleadosActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@40586d08 that was originally added here 06-21 18:49:54.459: E/WindowManager(348): at android.view.ViewRoot.<init>(ViewRoot.java:258) 06-21 18:49:54.459: E/WindowManager(348): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:148) 06-21 18:49:54.459: E/WindowManager(348): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91) 06-21 18:49:54.459: E/WindowManager(348): at android.view.Window$LocalWindowManager.addView(Window.java:424) 06-21 18:49:54.459: E/WindowManager(348): at android.app.Dialog.show(Dialog.java:241) 06-21 18:49:54.459: E/WindowManager(348): at com.example.taller06oct.EditEmpleadosActivity$SaveEmpleadoDetails.onPreExecute(EditEmpleadosActivity.java:218) 06-21 18:49:54.459: E/WindowManager(348): at android.os.AsyncTask.execute(AsyncTask.java:391) 06-21 18:49:54.459: E/WindowManager(348): at com.example.taller06oct.EditEmpleadosActivity$1.onClick(EditEmpleadosActivity.java:95) 06-21 18:49:54.459: E/WindowManager(348): at android.view.View.performClick(View.java:2485) 06-21 18:49:54.459: E/WindowManager(348): at android.view.View$PerformClick.run(View.java:9080) 06-21 18:49:54.459: E/WindowManager(348): at android.os.Handler.handleCallback(Handler.java:587) 06-21 18:49:54.459: E/WindowManager(348): at android.os.Handler.dispatchMessage(Handler.java:92) 06-21 18:49:54.459: E/WindowManager(348): at android.os.Looper.loop(Looper.java:123) 06-21 18:49:54.459: E/WindowManager(348): at android.app.ActivityThread.main(ActivityThread.java:3683) 06-21 18:49:54.459: E/WindowManager(348): at java.lang.reflect.Method.invokeNative(Native Method) 06-21 18:49:54.459: E/WindowManager(348): at java.lang.reflect.Method.invoke(Method.java:507) 06-21 18:49:54.459: E/WindowManager(348): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839) 06-21 18:49:54.459: E/WindowManager(348): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597) 06-21 18:49:54.459: E/WindowManager(348): at dalvik.system.NativeStart.main(Native Method)
Y este es el codigo que tengo en el php y JSON.
Código PHP:
// array for JSON response
$response = array();
// check for required fields
if (isset($_POST['nombre']) && isset($_POST['cedula']) && isset($_POST['apellido'])) {
$nombre = $_POST['nombre'];
$cedula = $_POST['cedula'];
$apellido = $_POST['apellido'];
$sueldo = $_POST['sueldo'];
// include db connect class
// require_once __DIR__ . '/db_connect.php';
include("db_connect.php");
// connecting to db
$db = new DB_CONNECT();
// mysql inserting a new row
$result = mysql_query("INSERT INTO empleados(cedula, nombre, apellido, sueldo) VALUES('$cedula', '$nombre', '$apellido', '$sueldo')");
// check if row inserted or not
if ($result) {
// successfully inserted into database
$response["success"] = 1;
$response["message"] = "Empleado 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);
}