I'm new to this in Android Studio, the first applications did install me well, but lately they have not been installed. When creating the App, when it only has the text "Hello World" it is installed well, but as soon as I make a couple of methods and an intent to go to another layout, it does not let me install it. On the mobile it opens and closes alone and in the Android Studio emulator it says "nameApp Has been stoped".
I know it's something I do wrong, but I do not understand which, or where the fault is.
Manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.x.prueba">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".MainActivity2"></activity>
</application>
</manifest>
*. java
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
public class MainActivity extends AppCompatActivity {
Button siguiente;
Button salir;
EditText nombre;
EditText apellido;
EditText año;
int añoVerif;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
siguiente = (Button) findViewById(R.id.btnSiguiente);
salir = (Button) findViewById(R.id.btnSalir);
nombre = (EditText) findViewById(R.id.etNombre);
apellido = (EditText) findViewById(R.id.etApellido);
año = (EditText) findViewById(R.id.etAño);
añoVerif = Integer.parseInt(año.getText().toString());
siguiente.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
if(nombre.toString().isEmpty() || apellido.toString().isEmpty() || año.toString().isEmpty()){
Log.e("Vacío", "Error, campos vacíos.");
nombre.setHint("Llena todos los campos.");
apellido.setHint("Llena todos los campos.");
año.setHint("Llena todos los campos.");
}else {
if (añoVerif > 2017 && añoVerif < 1900) {
Log.e("Error", "Error en el año introducido");
}else{
lanzarActividad();
}
}
}
});
}
public void lanzarActividad(){
Intent intent = new Intent(MainActivity.this, MainActivity2.class);
startActivity(intent);
}
}