我正在从 Eclipse 中的 android 应用程序连接到外部数据库。它是使用 PHP 和 JSON 的 MySQL 服务器。问题是,当我从 localhost 进行测试时,一切正常,但是为了提供 Web 服务器的 URL,应用程序已关闭。
private ProgressDialog pDialog;
public static String mensaje_bienvenida = "com.example.AndroidConnectingToPhpMySQL.MESSAGE";
Button btnLogin;
EditText txtNick;
EditText txtClave;
JSONParser jsonParser = new JSONParser();
//private static String url_usu = "http://10.0.2.2/SistemaMedico/verificarusuario.php";
//ip orange ventas: 207.58.133.155
private static String url_usu = "http://www.orangeventas.com/SistemaMedico/verificarusuario.php";
private static final String TAG_SUCCESS = "success";
private static final String TAG_USUARIO = "usuario";
private static final String TAG_NICK = "nick";
private static final String TAG_CLAVE = "clave";
private static final String TAG_IDUSU = "idusu";
private static final String TAG_IDPER = "idper";
private static final String TAG_NOMBRE = "nombre";
private static final String TAG_SEXO = "sexo";
String nick;
String clave;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_screen);
/*StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);*/
//Le damos a las variables las propiedades de sus respectivos controles
btnLogin = (Button)findViewById(R.id.login);
txtNick = (EditText)findViewById(R.id.nick);
txtClave = (EditText)findViewById(R.id.clave);
//Evento clic del botón
btnLogin.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(txtNick.getText().toString().trim().length() > 0)
{
if(txtClave.getText().toString().trim().length() >= 6)
{
nick = txtNick.getText().toString().trim();
clave = txtClave.getText().toString().trim();
new ValidarUsuario().execute();
}
else
{
AlertDialog.Builder builder = new AlertDialog.Builder(MainScreenActivity.this);
builder.setTitle("Mensaje");
builder.setMessage("Ingrese Clave");
builder.setPositiveButton("Aceptar", null);
builder.create();
builder.show();
txtClave.requestFocus();
}
}
else
{
AlertDialog.Builder builder = new AlertDialog.Builder(MainScreenActivity.this);
builder.setTitle("Mensaje");
builder.setMessage("Ingrese Nick de Usuario");
builder.setPositiveButton("Aceptar", null);
builder.create();
builder.show();
txtNick.requestFocus();
}
}
});
}
class ValidarUsuario extends AsyncTask<String, String, String>
{
/*
@Override
protected void onPreExecute()
{
super.onPreExecute();
pDialog = new ProgressDialog(MainScreenActivity.this);
pDialog.setMessage("Loading products. Please wait...");
pDialog.setIndeterminate(false);
pDialog.setCancelable(false);
pDialog.show();
}*/
protected String doInBackground(String...params)
{
runOnUiThread(new Runnable() {
@Override
public void run() {
int success;
try
{
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair(TAG_NICK, nick));
params.add(new BasicNameValuePair(TAG_CLAVE, clave));
JSONObject json = jsonParser.makeHttpRequest(url_usu, "POST", params);
Log.d("Validando Usuario", json.toString());
success = json.getInt(TAG_SUCCESS);
if(success == 1)
{
JSONArray usuarioObj = json.getJSONArray(TAG_USUARIO);
JSONObject usuario = usuarioObj.getJSONObject(0);
/*
Intent intent = new Intent(getApplicationContext(), MenuActivity.class);
intent.putExtra(mensaje_bienvenida, usuario.getString(TAG_NOMBRE));*/
String genero = "BIENVENIDO";
final String nusu = usuario.getString(TAG_NOMBRE);
//mensaje_bienvenida = nusu;
if(usuario.getString(TAG_SEXO)=="F")
{
genero = "BIENVENIDA";
}
AlertDialog.Builder builder = new AlertDialog.Builder(MainScreenActivity.this);
builder.setTitle("Mensaje");
builder.setMessage(genero + " " + usuario.getString(TAG_NOMBRE));
/*
builder.setPositiveButton("Aceptar", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
Log.i("Dialogo", "Aceptado");
Intent intent = new Intent(getApplicationContext(), MenuActivity.class);
intent.putExtra(mensaje_bienvenida, nusu);
startActivity(intent);
}
});*/
builder.create();
builder.show();
Intent intent = new Intent(getApplicationContext(), MenuActivity.class);
intent.putExtra(mensaje_bienvenida, nusu);
startActivity(intent);
}
else
{
AlertDialog.Builder builder = new AlertDialog.Builder(MainScreenActivity.this);
builder.setTitle("Mensaje");
builder.setMessage("Intente nuevamente");
builder.setPositiveButton("Aceptar", null);
builder.create();
builder.show();
txtClave.setText("");
txtClave.requestFocus();
}
}
catch(JSONException ex)
{
ex.printStackTrace();
}
}
});
return null;
}
}
使用调试错误出现:源附件不包含文件 InvocationTargetException.class 的源。
但我重复一遍,从 localhost 运行一切正常。我需要帮助。谢谢你。