Hola buenas noches estoy intentando hacer un login pero se detiene la app cuando intento meter el usuario y contraseña
supongo que lo unico que necesitan es la clase java login:
public class Login extends AppCompatActivity {
TextView tv_registrar;
EditText etnombre, etapellidos,etusuario, etcertificacion, etclave;
Button entrar;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
etnombre = findViewById(R.id.nom);
etapellidos = findViewById(R.id.ape);
etusuario = findViewById(R.id.usr);
etcertificacion = findViewById(R.id.cert);
etclave = findViewById(R.id.pass);
entrar= findViewById(R.id.entrar);
tv_registrar=findViewById(R.id.tv_registrar);
tv_registrar.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) { /*enlace de texto registro con activity Registro*/
Intent intentReg = new Intent(Login.this, Registro.class);
Login.this.startActivity(intentReg);
}
});
entrar.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View view){
final String user_name=etusuario.getText().toString();
final String password=etclave.getText().toString();
Response.Listener<String> responseListener = new Response.Listener<String>() {
@Override
public void onResponse(String response) {
try {
JSONObject jsonResponse = new JSONObject(response);
boolean success = jsonResponse.getBoolean("success");
if (success){ /*SI EL INICIO DE SECION ES EXITOSO TRAERA LOS DATOS DE LA BASE.. */
String name = jsonResponse.getString("name");
String user_name = jsonResponse.getString("user_name");
String course = jsonResponse.getString("course");
String password = jsonResponse.getString("password");
/*ENVIAR datos atraves de un activity a otro primer parametro es donde nos enctramos
* y el segundo es a donde vamos a enviar la informacion*/
Intent intent = new Intent (Login.this, Bienvenido.class);
intent.putExtra("name",name);
intent.putExtra("user_name",user_name);
intent.putExtra("course",course);
intent.putExtra("password",password);
Login.this.startActivity(intent);
}else {
AlertDialog.Builder builder = new AlertDialog.Builder(Login.this);
builder.setMessage("ERROR EN EL INICIO DE SESION")
.setNegativeButton("Retry",null)
.create().show();
}
} catch (JSONException e) {
e.printStackTrace();
}
}
};
SolicitudDeInicio SolicitudDeInicio = new SolicitudDeInicio(user_name,password,responseListener);
/*CLASE PARA COMUNICARSE CON VOLLEY*/
RequestQueue queue = Volley.newRequestQueue(Login.this);
queue.add(SolicitudDeInicio);
}
});
}
}
y el codigo java que conecta con mi base de datos
public class SolicitudDeInicio extends StringRequest {
private static final String SOLICITUD_DE_INICIO_URL = "http://192.168.1.75/Login.php";
private Map<String, String> params;
public SolicitudDeInicio(String user_name, String password, Response.Listener<String> listener) {
super(Request.Method.POST, SOLICITUD_DE_INICIO_URL, listener, null);
params = new HashMap<>();
params.put("user_name", user_name);
params.put("password", password);
}
@Override
public Map<String, String> getParams() {
return params;
}
}
agradeceria mucho su ayuda ya que soy nuevo programando y todo funciona perfecto pero cuando ingreso el usuario y la contraseña la app se detiene.
gracias
agrego codigo java registro
public class Registro extends AppCompatActivity implements View.OnClickListener {
EditText etnombre, etapellidos,etusuario, etcertificacion, etcontra;
Button aceptar;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_registro);
etnombre = findViewById(R.id.nom);
etapellidos = findViewById(R.id.ape);
etusuario = findViewById(R.id.usr);
etcertificacion = findViewById(R.id.cert);
etcontra = findViewById(R.id.contra);
aceptar= findViewById(R.id.aceptar);
aceptar.setOnClickListener(this);
}
@Override
public void onClick(View view) {
final String name=etnombre.getText().toString();
final String surname=etapellidos.getText().toString();
final String user_name=etusuario.getText().toString();
final String course=etcertificacion.getText().toString();
final String password=etcontra.getText().toString();
Response.Listener<String> respoListener = new Response.Listener<String>() {
@Override
public void onResponse(String response) {
try {
JSONObject jsonResponse = new JSONObject(response);
boolean success = jsonResponse.getBoolean("success");
if (success){ /*si el registro es exitoso nos envia a la pagina principal*/
Intent intent = new Intent(Registro.this,Login.class);
Registro.this.startActivity(intent);
}else{
AlertDialog.Builder builder = new AlertDialog.Builder(Registro.this);
builder.setMessage("ERROR EN EL REGISTRO")
.setNegativeButton("Retry",null)
.create().show();
}
} catch (JSONException e) {
e.printStackTrace();
}
}
};
SolicitudDeRegistro solicitudDeRegistro = new SolicitudDeRegistro(name, surname, user_name, course, password, respoListener);
RequestQueue queue = Volley.newRequestQueue(Registro.this);
queue.add(solicitudDeRegistro);
}
}
agrego codigo java de registro que conecta con mi base de datos
public class SolicitudDeRegistro extends StringRequest {
private static final String SOLICITUD_DE_REGISTRO_URL= "http://192.168.1.75/Register.php";
private Map<String,String> params;
public SolicitudDeRegistro (String name, String surname, String user_name, String course, String password, Response.Listener<String> listener)
{
super (Method.POST, SOLICITUD_DE_REGISTRO_URL,listener,null);
params=new HashMap<>();
params.put("name",name);
params.put("surname",surname);
params.put("user_name",user_name);
params.put("course",course);
params.put("password",password);
}
@Override
public Map<String, String> getParams() {
return params;
}
}
Gracias :)
Esos son los errores que me marca el Logcat inmediatamente despues de que se cierra la app
2018-12-12 16:04:31.960 3604-3604/? E/RecyclerView: No adapter attached; skipping layout
2018-12-12 16:04:35.458 6324-6324/? E/libmdmdetect: Failed to open /sys/bus/msm_subsys/devices/subsys0/name: Permission denied
2018-12-12 16:04:36.154 6336-6336/? E/libmdmdetect: Failed to open /sys/bus/msm_subsys/devices/subsys0/name: Permission denied
2018-12-12 16:04:36.893 6354-6354/? E/libmdmdetect: Failed to open /sys/bus/msm_subsys/devices/subsys0/name: Permission denied
2018-12-12 16:05:04.886 6433-6433/? E/libmdmdetect: Failed to open /sys/bus/msm_subsys/devices/subsys0/name: Permission denied
2018-12-12 16:05:06.174 3999-3999/? E/Finsky: [1] com.google.android.finsky.verifier.impl.VerifyPerSourceInstallationConsentInstallTask.b(86): Package name null is not an installed package
2018-12-12 16:05:08.959 2207-6551/? E/PacketFilter: combine fail
2018-12-12 16:05:09.375 6549-6549/? E/libmdmdetect: Failed to open /sys/bus/msm_subsys/devices/subsys0/name: Permission denied
2018-12-12 16:05:09.847 6625-6625/? E/ACRA: Initializing ANR detector for process: com.facebook.appmanager
2018-12-12 16:05:10.141 6625-6703/? E/ActivityThread: Failed to find provider info for com.facebook.appmanager.nekodirect
2018-12-12 16:05:10.177 2207-2455/? E/ConnectivityService: RemoteException caught trying to send a callback msg for NetworkRequest [ LISTEN id=1552, [ Capabilities: INTERNET&NOT_RESTRICTED&TRUSTED&FOREGROUND] ]
2018-12-12 16:05:10.499 6742-6742/? E/GoogleTagManager: Invalid macro: _gtm.loadEventEnabled
2018-12-12 16:05:10.510 6742-6762/? E/GoogleTagManager: Invalid macro: _gtm.loadEventEnabled
2018-12-12 16:05:11.078 6864-6864/? E/CloudUtils: deviceBlackList =
2018-12-12 16:05:11.079 6864-6864/? E/HWAccelerateUtils: the model supported hw acceleration
2018-12-12 16:05:11.083 6864-6864/? E/b: deviceIdHash = fe18e7b7-2a3b-4d63-b290-4e652461ff4f
2018-12-12 16:05:11.490 6966-6966/? E/ACRA: Initializing ANR detector for process: com.facebook.katana
2018-12-12 16:05:12.713 6966-7089/? E/CompactDiskManagerImpl.cpp: Failed to remove new folder structure directories: No such file or directory
2018-12-12 16:05:13.427 6966-7083/? E/fb4a.BackgroundLocationReportingManager: Starting location collection failed due to PERMISSION_DENIED, will retry when location services returns
2018-12-12 16:05:44.668 6576-6576/com.example.brian.login E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.brian.login, PID: 6576
java.lang.NullPointerException: Attempt to invoke virtual method 'android.text.Editable android.widget.EditText.getText()' on a null object reference
at com.example.brian.login.Login$2.onClick(Login.java:52)
at android.view.View.performClick(View.java:5685)
at android.view.View$PerformClick.run(View.java:22481)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:241)
at android.app.ActivityThread.main(ActivityThread.java:6274)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
2018-12-12 16:05:44.690 679-783/? E/JavaDumper:FW: utils.c(256): mkdir (/data/crashdata) failed. File exists
2018-12-12 16:05:44.698 679-783/? E/JavaDumper:FW: ramdump_framework.c(317): fp is NULL
2018-12-12 16:05:44.698 679-783/? E/JavaDumper:FW: ramdump_framework.c(498): Read-only file system
2018-12-12 16:05:44.799 679-783/? E/JavaDumper:FW: JavaDumper.cpp(262): Failed to remove /tmp/dropbox.txt:Unknown error -2
Archivo Login xml
<?xml version="1.0" encoding="utf-8"?>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginVertical="30dp"
android:src="@drawable/simboloborrado"
/>
<EditText
android:id="@+id/usu"
android:layout_width="200dp"
android:layout_height="20dp"
android:hint="Usuario"
android:layout_gravity="center_horizontal"
android:background="#11000000"
android:inputType="text"
android:layout_marginVertical="15dp"
/>
<EditText
android:id="@+id/pass"
android:layout_width="200dp"
android:layout_height="20dp"
android:hint="Clave"
android:layout_gravity="center_horizontal"
android:layout_marginVertical="10dp"
android:background="#11000000"
android:inputType="textPassword"
/>
<Button
android:id="@+id/entrar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="Entrar"
/>
<TextView
android:id="@+id/tv_registrar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:hint="Registrar"
android:layout_marginVertical="10dp"
/>
nuevo error
2018-12-13 00:44:06.500 2207-3232/? E/ActivityManager: Sending non-protected broadcast org.codeaurora.intent.action.ACTION_NETWORK_SPECIFIER_SET from system 2802:com.android.phone/1001 pkg com.android.phone
java.lang.Throwable
at com.android.server.am.ActivityManagerService.checkBroadcastFromSystem(ActivityManagerService.java:18676)
at com.android.server.am.ActivityManagerService.broadcastIntentLocked(ActivityManagerService.java:19250)
at com.android.server.am.ActivityManagerService.broadcastIntent(ActivityManagerService.java:19341)
at android.app.ActivityManagerNative.onTransact(ActivityManagerNative.java:505)
at com.android.server.am.ActivityManagerService.onTransact(ActivityManagerService.java:2959)
at android.os.Binder.execTransact(Binder.java:565)
xml
deactivity_login
?