1

Estoy intentando pasar de mi MainActivity que es mi Login a una ventana que contiene una lista de distintos fragments, pero cuando ingreso mis datos en el Login y le doy al botón "Ingresar", ésta lanza la otra actividad y la aplicación se cierra (android studio).

He intentado con estas dos formas y las dos me cierran la aplicación cuando doy al botón Ingresar... Ayúdenme por favor.

  1. Intent i=new Intent(getApplicationContext(), Inicio.class); startActivity(i);
  2. Intent intent = new Intent(MainActivity.this, Inicio.class); MainActivity.this.startActivity(intent);

Este es mi MainActivity donde está el login

public class MainActivity extends AppCompatActivity {

EditText txtCor, txtPas;
Button btnIngresar;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    txtCor = findViewById(R.id.txtCor);
    txtPas = findViewById(R.id.txtPas);

    btnIngresar = findViewById(R.id.btnIngresar);

    btnIngresar.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {

            Thread tr=new Thread(){
                @Override
                public void run() {
                    final String res=enviarPost(txtCor.getText().toString(), txtPas.getText().toString());
                    runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            int r=objJSON(res);
                            if (r>0){
                                //Intent i=new Intent(getApplicationContext(), Inicio.class);
                                //startActivity(i);
                                Intent intent =new Intent(getApplicationContext(),Inicio.class);
                                startActivity(intent);
                                finish();

                            }else{
                                Toast.makeText(getApplicationContext(),"Usuario o contraseña incorrectos",
                                        Toast.LENGTH_SHORT).show();
                            }
                        }
                    });
                }
            };
            tr.start();

        }
    });
}
public String enviarPost(String cor, String pas) {
    String parametros = "cor=" + cor + "&pas=" + pas;
    HttpURLConnection connection = null;
    String respuesta = "";
    try {
        URL url = new URL("http://192.168.1.10/WebService/valida.php");
        connection = (HttpURLConnection) url.openConnection();
        connection.setRequestMethod("POST");
        connection.setRequestProperty("Content-Length", "" + Integer.toString(parametros.getBytes().length));

        // con esto se indica que salen algunos datos (parametros)
        connection.setDoOutput(true);
        DataOutputStream wr = new DataOutputStream(connection.getOutputStream());
        wr.writeBytes(parametros);
        wr.close();

        Scanner inSteam = new Scanner(connection.getInputStream());

        while (inSteam.hasNextLine())
            respuesta += (inSteam.nextLine());

    } catch (Exception e) {
    }
    return respuesta.toString();
}

public int objJSON(String rspta) {
    int res = 0;
    try {
        JSONArray json=new JSONArray(rspta);
        if(json.length()>0)
            res=1;
    } catch (Exception e) {}
    return res;
}

}


Este es mi archivo style.xml

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
</style>

<style name="AppTheme.NoActionBar">
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
</style>

<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />

<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />


Este es mi Logcat

02-24 10:56:08.385 9361-9361/? I/art: Late-enabling -Xcheck:jni
02-24 10:56:08.765 9361-9361/? I/InstantRun: starting instant run server: is main process
02-24 10:56:08.977 9361-9361/? W/art: Before Android 4.1, method android.graphics.PorterDuffColorFilter android.support.graphics.drawable.VectorDrawableCompat.updateTintFilter(android.graphics.PorterDuffColorFilter, android.content.res.ColorStateList, android.graphics.PorterDuff$Mode) would have incorrectly overridden the package-private method in android.graphics.drawable.Drawable
02-24 10:56:09.216 9361-9385/? D/OpenGLRenderer: Render dirty regions requested: true
02-24 10:56:09.223 9361-9361/? D/Atlas: Validating map...
02-24 10:56:09.283 9361-9385/? I/Adreno-EGL: <qeglDrvAPI_eglInitialize:379>: EGL 1.4 QUALCOMM build:  ()
                                             OpenGL ES Shader Compiler Version: E031.25.03.01
                                             Build Date: 01/29/15 Thu
                                             Local Branch: 
                                             Remote Branch: 
                                             Local Patches: 
                                             Reconstruct Branch: 
02-24 10:56:09.286 9361-9385/? I/OpenGLRenderer: Initialized EGL, version 1.4
02-24 10:56:09.303 9361-9385/? D/OpenGLRenderer: Enabling debug mode 0
02-24 10:56:09.392 9361-9361/? I/Timeline: Timeline: Activity_idle id: android.os.BinderProxy@3a189687 time:310770737
02-24 10:56:26.956 9361-9361/com.example.matias.taken W/IInputConnectionWrapper: endBatchEdit on inactive InputConnection
02-24 10:56:30.362 9361-9361/com.example.matias.taken I/Timeline: Timeline: Activity_launch_request id:com.example.matias.taken time:310791706
02-24 10:56:30.936 9361-9361/com.example.matias.taken D/AndroidRuntime: Shutting down VM
02-24 10:56:30.937 9361-9361/com.example.matias.taken E/AndroidRuntime: FATAL EXCEPTION: main
                                                                        Process: com.example.matias.taken, PID: 9361
                                                                        java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.matias.taken/co.quindio.sena.tutorialwebservice.Inicio}: java.lang.IllegalStateException: This Activity already has an action bar supplied by the window decor. Do not request Window.FEATURE_SUPPORT_ACTION_BAR and set windowActionBar to false in your theme to use a Toolbar instead.
                                                                            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2309)
                                                                            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2369)
                                                                            at android.app.ActivityThread.access$800(ActivityThread.java:149)
                                                                            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1289)
                                                                            at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                            at android.os.Looper.loop(Looper.java:135)
                                                                            at android.app.ActivityThread.main(ActivityThread.java:5258)
                                                                            at java.lang.reflect.Method.invoke(Native Method)
                                                                            at java.lang.reflect.Method.invoke(Method.java:372)
                                                                            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:898)
                                                                            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:693)
                                                                         Caused by: java.lang.IllegalStateException: This Activity already has an action bar supplied by the window decor. Do not request Window.FEATURE_SUPPORT_ACTION_BAR and set windowActionBar to false in your theme to use a Toolbar instead.
                                                                            at android.support.v7.app.AppCompatDelegateImplV9.setSupportActionBar(AppCompatDelegateImplV9.java:201)
                                                                            at android.support.v7.app.AppCompatActivity.setSupportActionBar(AppCompatActivity.java:129)
                                                                            at co.quindio.sena.tutorialwebservice.Inicio.onCreate(Inicio.java:31)
                                                                            at android.app.Activity.performCreate(Activity.java:5979)
                                                                            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
                                                                            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2262)
                                                                            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2369) 
                                                                            at android.app.ActivityThread.access$800(ActivityThread.java:149) 
                                                                            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1289) 
                                                                            at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                                            at android.os.Looper.loop(Looper.java:135) 
                                                                            at android.app.ActivityThread.main(ActivityThread.java:5258) 
                                                                            at java.lang.reflect.Method.invoke(Native Method) 
                                                                            at java.lang.reflect.Method.invoke(Method.java:372) 
                                                                            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:898) 
                                                                            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:693) 

02-24 10:56:30.943 9361-9361/? I/Process: Sending signal. PID: 9361 SIG: 9

Este es mi manifest

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="co.quindio.sena.tutorialwebservice">

    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.CAMERA"/><!--- para usar la camara desde la App -->
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/><!--escribir en memoria para guardar las fotos -->
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/><!--leer las imagenes guardadas en la galeria -->


    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity
            android:name=".MainActivity"
            android:label="@string/app_name"
            android:theme="@style/AppTheme.NoActionBar">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <provider
            android:name="android.support.v4.content.FileProvider"
            android:authorities="${applicationId}.provider"
            android:exported="false"
            android:grantUriPermissions="true">
            <meta-data
                android:name="android.support.FILE_PROVIDER_PATHS"
                android:resource="@xml/provider_paths"/>
        </provider>
        <activity android:name=".Inicio" />
    </application>

</manifest>
3
  • Para agregar información a tu pregunta se realiza mediante el boton "editar". Te sugiero agregar que error se muestra en el LogCat.
    – Jorgesys
    el 24 feb. 2018 a las 14:09
  • el logcat menciona problema con el Action Bar. Como tienes en el manifest en android:theme de la activity inicio? es el mismo que esta en styles?
    – armen
    el 24 feb. 2018 a las 16:18
  • Arriba agregue mi manifest Armen el 24 feb. 2018 a las 16:28

1 respuesta 1

0

Si estas usando un Navigation Drawer, lo mas probale es que el layout del DrawerLayout tenga un widget.Toolbar, el cual se inicializa en onCreate de tu activity Inicio, por lo tanto en el manifest debes de declarar android:theme="@style/Theme.AppCompat.NoActionBar" ó

android:theme="@style/AppTheme.NoActionBar"

de esa activity y en styles debes de tener algo así:

<style name="AppTheme.NoActionBar">
        <item name="windowActionBar">false</item>
        <item name="windowNoTitle">true</item>
        <item name="drawerArrowStyle">@style/HamburguesaIcon</item>
    </style>

En tu caso tienes que declarar el tema en el manifest:

<activity 
android:name=".Inicio" 
android:theme="@style/AppTheme.NoActionBar"/>
1
  • Muchas gracias amigo, esto me soluciono el problema. Saludos y que tengas buen día! el 24 feb. 2018 a las 17:06

Tu Respuesta

By clicking “Publica tu respuesta”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

¿No es la respuesta que buscas? Examina otras preguntas con la etiqueta o formula tu propia pregunta.