Código Java:
Ver original
package conexion; import java.util.ArrayList; import java.util.List; import java.util.logging.Level; import java.util.logging.Logger; import json.JSONParser; import org.apache.http.message.BasicNameValuePair; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; import android.app.Activity; import android.app.ProgressDialog; import android.os.AsyncTask; import android.os.Bundle; import android.util.Log; import android.view.View; import android.view.Window; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.EditText; import android.widget.Toast; import com.example.facturacion_movil.R; public class ViewRegistro extends Activity implements OnClickListener{ EditText txtcod, txtruc,txtnom,txtcor,txtced; Button btnContinuar; String num_fact,fecha,cliente,direccion,correo,cedula,subtotal,descuento,iva,total; // Progress Dialog private ProgressDialog pDialog; // JSON parser class JSONParser jsonParser = new JSONParser(); JSONArray clients; //testing on Emulator: //ids @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.activity_registro); txtced = (EditText)findViewById(R.id.txtCedCliente); txtnom = (EditText)findViewById(R.id.txtNomCliente); txtcod = (EditText)findViewById(R.id.txtCodCliente); txtruc = (EditText)findViewById(R.id.txtRucCliente); txtcor = (EditText)findViewById(R.id.txtCorCliente); btnContinuar.setOnClickListener(this); } @Override // TODO Auto-generated method stub new CreateUser().execute(); } @Override protected void onPreExecute() { super.onPreExecute(); pDialog = new ProgressDialog(ViewRegistro.this); pDialog.setMessage("Esperando Conexion..."); pDialog.setIndeterminate(false); pDialog.setCancelable(true); pDialog.show(); } @Override // TODO Auto-generated method stub // Check for success tag int success; try { // Building Parameters List<BasicNameValuePair> params = new ArrayList<BasicNameValuePair>(); params.add(new BasicNameValuePair("cedula", cedula)); Log.d("request!", "starting"); //Posting user data to script JSONObject json = jsonParser.makeHttpRequest(REGISTER_URL, "POST", params); // full json response Log.d("Registering attempt", json.toString()); // json success element success = json.getInt(TAG_SUCCESS); if (success == 1) { Log.d("Cliente Encontrado!", json.toString()); clients = json.getJSONArray(TAG_CLIENTS); for (int i = 0; i < clients.length(); i++) { JSONObject c = clients.getJSONObject(i); // Storing each json item in variable Toast.makeText(getApplicationContext(), nom_cli, Toast.LENGTH_LONG).show(); txtnom.setText(nom_cli); txtcor.setText(correo); } return json.getString(TAG_MESSAGE); }else{ Log.d("Cliente no Encontrado!", json.getString(TAG_MESSAGE)); return json.getString(TAG_MESSAGE); } } catch (JSONException e) { e.printStackTrace(); e.getMessage(); Logger.getLogger(ViewRegistro.class.getName()).log(Level.SEVERE, null, e); } return null; } // dismiss the dialog once product deleted pDialog.dismiss(); if (file_url != null){ Toast.makeText(ViewRegistro.this, file_url, Toast.LENGTH_LONG).show(); } } } }
mediante codigo php y con uso de json me busca un dato en una base de datos mysql al probarlo desde el xampp funciona pero al momento de ejecutarlo desde el terminal y tratar de mostrar el resultado de la consulta que son 3 parametros me arroja el sgte error. alguien que me de alguna idea de porque el fallo.
Código Java:
Ver original
02-22 21:57:17.791: W/System.err(10742): at conexion.ViewRegistro$CreateUser.doInBackground(ViewRegistro.java:116) 02-22 21:57:17.791: W/System.err(10742): at conexion.ViewRegistro$CreateUser.doInBackground(ViewRegistro.java:1) 02-22 21:57:17.791: W/System.err(10742): at java.util.concurrent.FutureTask.run(FutureTask.java:237) 02-22 21:57:17.791: W/System.err(10742): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231) 02-22 21:57:17.791: W/System.err(10742): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112) 02-22 21:57:17.791: W/System.err(10742): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587) 02-22 21:57:17.796: E/conexion.ViewRegistro(10742): null 02-22 21:57:17.796: E/conexion.ViewRegistro(10742): org.json.JSONException: No value for clients 02-22 21:57:17.796: E/conexion.ViewRegistro(10742): at org.json.JSONObject.get(JSONObject.java:355) 02-22 21:57:17.796: E/conexion.ViewRegistro(10742): at org.json.JSONObject.getJSONArray(JSONObject.java:549) 02-22 21:57:17.796: E/conexion.ViewRegistro(10742): at conexion.ViewRegistro$CreateUser.doInBackground(ViewRegistro.java:116) 02-22 21:57:17.796: E/conexion.ViewRegistro(10742): at conexion.ViewRegistro$CreateUser.doInBackground(ViewRegistro.java:1) 02-22 21:57:17.796: E/conexion.ViewRegistro(10742): at android.os.AsyncTask$2.call(AsyncTask.java:288) 02-22 21:57:17.796: E/conexion.ViewRegistro(10742): at java.util.concurrent.FutureTask.run(FutureTask.java:237) 02-22 21:57:17.796: E/conexion.ViewRegistro(10742): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231) 02-22 21:57:17.796: E/conexion.ViewRegistro(10742): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112) 02-22 21:57:17.796: E/conexion.ViewRegistro(10742): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587) 02-22 21:57:17.836: E/ViewRootImpl(10742): sendUserActionEvent() mView == null