0

To the kind moderator who marked this thread as a duplicate: I visited the "original" thread and it has nothing (that I can see) that could help me. Please re open this thread.

My app keeps crashing when I run this build (it's a basic login and registration form). The problem is for sure in the LoginActivity.java code, but I don't know what the problem is.

Here's the RegistrationActivity.java code

package com.example.sean.cookappreal;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.*;

public class RegisterActivity extends AppCompatActivity {

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

        final EditText etUsername = (EditText) 
findViewById(R.id.etUsername);
        final EditText etEmailAddress = (EditText) 
findViewById(R.id.etEmailAddress);
        final EditText etPassword = (EditText) 
findViewById(R.id.etPassword);

        final Button bRegister = (Button) findViewById(R.id.bRegister);
    }
}

Here's the LoginActvitity.java code:

package com.example.sean.cookappreal;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.*;
import android.content.Intent;

public class LoginActivity extends AppCompatActivity {

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

        final EditText etUsername = (EditText) 
findViewById(R.id.etUsername);
        final EditText etPassword = (EditText) 
findViewById(R.id.etPassword);
        final Button bLogin = (Button) findViewById(R.id.bLogin);
        final TextView registerLink = (TextView) 
findViewById(R.id.tvRegisterHere);

        registerLink.setOnClickListener(new View.OnClickListener()
        {
            @Override
            public void onClick(View v)
            {
                Intent registerIntent = new 
Intent(LoginActivity.this,RegisterActivity.class);
                LoginActivity.this.startActivity(registerIntent);
            }
        });
    }
}

And finally here's the UserAreaActivity.java code (this is just a very simple home welcome screen).

package com.example.sean.cookappreal;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.*;




public class UserAreaActivity extends AppCompatActivity {

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

        final EditText etUsername = (EditText) 
     findViewById(R.id.etUsername);
        final TextView welcomeMessage = (TextView) 
     findViewById(R.id.tvWelcomeMsg);

    }
}

Here's my manifest code as asked for.

<?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
        package="com.example.sean.cookappreal">

        <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=".LoginActivity">
                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />

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

    </manifest>

Here's the log cat information.

07-26 17:27:17.491 13115-13115/com.example.sean.cookappreal E/Zygote: v2
07-26 17:27:17.491 13115-13115/com.example.sean.cookappreal W/SELinux: Function: selinux_compare_spd_ram, index[1], priority [2], priority version is VE=SEPF_SECMOBILE_6.0.1_0033
07-26 17:27:17.491 13115-13115/com.example.sean.cookappreal I/libpersona: KNOX_SDCARD checking this for 10238
07-26 17:27:17.491 13115-13115/com.example.sean.cookappreal I/libpersona: KNOX_SDCARD not a persona
07-26 17:27:17.501 13115-13115/com.example.sean.cookappreal E/Zygote: accessInfo : 0
07-26 17:27:17.501 13115-13115/com.example.sean.cookappreal W/SELinux: SELinux: seapp_context_lookup: seinfo=default, level=s0:c512,c768, pkgname=com.example.sean.cookappreal 
07-26 17:27:17.501 13115-13115/com.example.sean.cookappreal I/art: Late-enabling -Xcheck:jni
07-26 17:27:17.541 13115-13115/com.example.sean.cookappreal D/TimaKeyStoreProvider: TimaSignature is unavailable
07-26 17:27:17.541 13115-13115/com.example.sean.cookappreal D/ActivityThread: Added TimaKeyStore provider
07-26 17:27:17.581 13115-13115/com.example.sean.cookappreal D/ResourcesManager: For user 0 new overlays fetched Null
07-26 17:27:17.721 13115-13115/com.example.sean.cookappreal W/art: Failed execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg  --debuggable --instruction-set=arm --instruction-set-features=smp,div,atomic_ldrd_strd --runtime-arg -Xrelocate --boot-image=/system/framework/boot.art --runtime-arg -Xms64m --runtime-arg -Xmx512m --compiler-filter=speed --instruction-set-variant=cortex-a15 --instruction-set-features=default --dex-file=/data/app/com.example.sean.cookappreal-1/split_lib_dependencies_apk.apk --oat-file=/data/dalvik-cache/arm/data@app@com.example.sean.cookappreal-1@split_lib_dependencies_apk.apk@classes.dex) because non-0 exit status
07-26 17:27:17.951 13115-13115/com.example.sean.cookappreal W/art: Failed execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg  --debuggable --instruction-set=arm --instruction-set-features=smp,div,atomic_ldrd_strd --runtime-arg -Xrelocate --boot-image=/system/framework/boot.art --runtime-arg -Xms64m --runtime-arg -Xmx512m --compiler-filter=speed --instruction-set-variant=cortex-a15 --instruction-set-features=default --dex-file=/data/app/com.example.sean.cookappreal-1/split_lib_slice_0_apk.apk --oat-file=/data/dalvik-cache/arm/data@app@com.example.sean.cookappreal-1@split_lib_slice_0_apk.apk@classes.dex) because non-0 exit status
07-26 17:27:18.021 13115-13115/com.example.sean.cookappreal W/art: Failed execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg  --debuggable --instruction-set=arm --instruction-set-features=smp,div,atomic_ldrd_strd --runtime-arg -Xrelocate --boot-image=/system/framework/boot.art --runtime-arg -Xms64m --runtime-arg -Xmx512m --compiler-filter=speed --instruction-set-variant=cortex-a15 --instruction-set-features=default --dex-file=/data/app/com.example.sean.cookappreal-1/split_lib_slice_1_apk.apk --oat-file=/data/dalvik-cache/arm/data@app@com.example.sean.cookappreal-1@split_lib_slice_1_apk.apk@classes.dex) because non-0 exit status
07-26 17:27:18.081 13115-13115/com.example.sean.cookappreal W/art: Failed execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg  --debuggable --instruction-set=arm --instruction-set-features=smp,div,atomic_ldrd_strd --runtime-arg -Xrelocate --boot-image=/system/framework/boot.art --runtime-arg -Xms64m --runtime-arg -Xmx512m --compiler-filter=speed --instruction-set-variant=cortex-a15 --instruction-set-features=default --dex-file=/data/app/com.example.sean.cookappreal-1/split_lib_slice_2_apk.apk --oat-file=/data/dalvik-cache/arm/data@app@com.example.sean.cookappreal-1@split_lib_slice_2_apk.apk@classes.dex) because non-0 exit status
07-26 17:27:18.151 13115-13115/com.example.sean.cookappreal W/art: Failed execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg  --debuggable --instruction-set=arm --instruction-set-features=smp,div,atomic_ldrd_strd --runtime-arg -Xrelocate --boot-image=/system/framework/boot.art --runtime-arg -Xms64m --runtime-arg -Xmx512m --compiler-filter=speed --instruction-set-variant=cortex-a15 --instruction-set-features=default --dex-file=/data/app/com.example.sean.cookappreal-1/split_lib_slice_3_apk.apk --oat-file=/data/dalvik-cache/arm/data@app@com.example.sean.cookappreal-1@split_lib_slice_3_apk.apk@classes.dex) because non-0 exit status
07-26 17:27:18.211 13115-13115/com.example.sean.cookappreal W/art: Failed execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg  --debuggable --instruction-set=arm --instruction-set-features=smp,div,atomic_ldrd_strd --runtime-arg -Xrelocate --boot-image=/system/framework/boot.art --runtime-arg -Xms64m --runtime-arg -Xmx512m --compiler-filter=speed --instruction-set-variant=cortex-a15 --instruction-set-features=default --dex-file=/data/app/com.example.sean.cookappreal-1/split_lib_slice_4_apk.apk --oat-file=/data/dalvik-cache/arm/data@app@com.example.sean.cookappreal-1@split_lib_slice_4_apk.apk@classes.dex) because non-0 exit status
07-26 17:27:18.271 13115-13115/com.example.sean.cookappreal W/art: Failed execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg  --debuggable --instruction-set=arm --instruction-set-features=smp,div,atomic_ldrd_strd --runtime-arg -Xrelocate --boot-image=/system/framework/boot.art --runtime-arg -Xms64m --runtime-arg -Xmx512m --compiler-filter=speed --instruction-set-variant=cortex-a15 --instruction-set-features=default --dex-file=/data/app/com.example.sean.cookappreal-1/split_lib_slice_5_apk.apk --oat-file=/data/dalvik-cache/arm/data@app@com.example.sean.cookappreal-1@split_lib_slice_5_apk.apk@classes.dex) because non-0 exit status
07-26 17:27:18.331 13115-13115/com.example.sean.cookappreal W/art: Failed execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg  --debuggable --instruction-set=arm --instruction-set-features=smp,div,atomic_ldrd_strd --runtime-arg -Xrelocate --boot-image=/system/framework/boot.art --runtime-arg -Xms64m --runtime-arg -Xmx512m --compiler-filter=speed --instruction-set-variant=cortex-a15 --instruction-set-features=default --dex-file=/data/app/com.example.sean.cookappreal-1/split_lib_slice_6_apk.apk --oat-file=/data/dalvik-cache/arm/data@app@com.example.sean.cookappreal-1@split_lib_slice_6_apk.apk@classes.dex) because non-0 exit status
07-26 17:27:18.401 13115-13115/com.example.sean.cookappreal W/art: Failed execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg  --debuggable --instruction-set=arm --instruction-set-features=smp,div,atomic_ldrd_strd --runtime-arg -Xrelocate --boot-image=/system/framework/boot.art --runtime-arg -Xms64m --runtime-arg -Xmx512m --compiler-filter=speed --instruction-set-variant=cortex-a15 --instruction-set-features=default --dex-file=/data/app/com.example.sean.cookappreal-1/split_lib_slice_7_apk.apk --oat-file=/data/dalvik-cache/arm/data@app@com.example.sean.cookappreal-1@split_lib_slice_7_apk.apk@classes.dex) because non-0 exit status
07-26 17:27:18.471 13115-13115/com.example.sean.cookappreal W/art: Failed execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg  --debuggable --instruction-set=arm --instruction-set-features=smp,div,atomic_ldrd_strd --runtime-arg -Xrelocate --boot-image=/system/framework/boot.art --runtime-arg -Xms64m --runtime-arg -Xmx512m --compiler-filter=speed --instruction-set-variant=cortex-a15 --instruction-set-features=default --dex-file=/data/app/com.example.sean.cookappreal-1/split_lib_slice_8_apk.apk --oat-file=/data/dalvik-cache/arm/data@app@com.example.sean.cookappreal-1@split_lib_slice_8_apk.apk@classes.dex) because non-0 exit status
07-26 17:27:18.531 13115-13115/com.example.sean.cookappreal W/art: Failed execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg  --debuggable --instruction-set=arm --instruction-set-features=smp,div,atomic_ldrd_strd --runtime-arg -Xrelocate --boot-image=/system/framework/boot.art --runtime-arg -Xms64m --runtime-arg -Xmx512m --compiler-filter=speed --instruction-set-variant=cortex-a15 --instruction-set-features=default --dex-file=/data/app/com.example.sean.cookappreal-1/split_lib_slice_9_apk.apk --oat-file=/data/dalvik-cache/arm/data@app@com.example.sean.cookappreal-1@split_lib_slice_9_apk.apk@classes.dex) because non-0 exit status
07-26 17:27:18.531 13115-13115/com.example.sean.cookappreal W/System: ClassLoader referenced unknown path: /data/app/com.example.sean.cookappreal-1/lib/arm
07-26 17:27:18.541 13115-13115/com.example.sean.cookappreal I/InstantRun: starting instant run server: is main process
07-26 17:27:18.671 13115-13115/com.example.sean.cookappreal 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
07-26 17:27:18.891 13115-13115/com.example.sean.cookappreal D/AndroidRuntime: Shutting down VM
07-26 17:27:18.891 13115-13115/com.example.sean.cookappreal E/AndroidRuntime: FATAL EXCEPTION: main
                                                                              Process: com.example.sean.cookappreal, PID: 13115
                                                                              java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.sean.cookappreal/com.example.sean.cookappreal.LoginActivity}: java.lang.ClassCastException: android.widget.RelativeLayout cannot be cast to android.widget.TextView
                                                                                  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3255)
                                                                                  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3351)
                                                                                  at android.app.ActivityThread.access$1100(ActivityThread.java:222)
                                                                                  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1796)
                                                                                  at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                                  at android.os.Looper.loop(Looper.java:158)
                                                                                  at android.app.ActivityThread.main(ActivityThread.java:7230)
                                                                                  at java.lang.reflect.Method.invoke(Native Method)
                                                                                  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
                                                                                  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
                                                                               Caused by: java.lang.ClassCastException: android.widget.RelativeLayout cannot be cast to android.widget.TextView
                                                                                  at com.example.sean.cookappreal.LoginActivity.onCreate(LoginActivity.java:19)
                                                                                  at android.app.Activity.performCreate(Activity.java:6877)
                                                                                  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1136)
                                                                                  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3208)
                                                                                  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3351) 
                                                                                  at android.app.ActivityThread.access$1100(ActivityThread.java:222) 
                                                                                  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1796) 
                                                                                  at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                                                  at android.os.Looper.loop(Looper.java:158) 
                                                                                  at android.app.ActivityThread.main(ActivityThread.java:7230) 
                                                                                  at java.lang.reflect.Method.invoke(Native Method) 
                                                                                  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230) 
                                                                                  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120) 
07-26 17:32:19.201 13115-13115/com.example.sean.cookappreal I/Process: Sending signal. PID: 13115 SIG: 9

Here's my Activity Register Layout

enter image description here

Here's my Activity Login Layout

enter image description here

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
  • Do you have entries in your app manifest XML file for all the activities involved here? Now would be a great time to learn how to use a debugger. If you could tell us exactly where the code is crashing, that would save us a lot of guess work here. – Tim Biegeleisen Jul 26 '17 at 11:37
  • @TimBiegeleisen The part that causes the code to crash is the LoginActivity.java code, from the final variable declarations to the end of that docs code. – Sean Kurian Jul 26 '17 at 11:54
  • @MaheshGawhane What do you mean by error log? I'm running this build on my phone, so the app just opens and immediately crashes with the message "Unfortunately, cookAppReal has stopped". – Sean Kurian Jul 26 '17 at 11:57
  • See this for logs: https://developer.android.com/studio/profile/android-monitor.html or directly https://developer.android.com/studio/debug/am-logcat.html – Adinia Jul 26 '17 at 11:59
  • Can you add a breakpoint on the first line of the `onCreate()` method of the `LoginActivity`? Let's see where it is dying. – Tim Biegeleisen Jul 26 '17 at 12:00
  • 1
    @TimBiegeleisen It looks like its something to do with not being able to cast android.widget.RelativeLayout to android.widget.TextView? – Sean Kurian Jul 26 '17 at 12:05
  • OK what type of widget in your login layout has ID `tvRegisterHere` ? – Tim Biegeleisen Jul 26 '17 at 12:08
  • @TimBiegeleisen It's a checkedTextView. – Sean Kurian Jul 26 '17 at 12:10
  • Humm, the design view doesn't help, we need the text version(switch tabs in the left corner). Also, seems you removed the error logs, does it mean you solved that? – Adinia Jul 26 '17 at 12:17
  • @Adinia , no, they seemed unreadable to me and I was worried it wasn't what people were looking for but since you seem to understand them I'll put them back. I'll also upload the text versions now. – Sean Kurian Jul 26 '17 at 12:20
  • Have you read the link about logs that I posted earlier? If the Debugger it's not your best friend, you can't do anything. When you have a crash, you have to look for error type logs (E/..), starting by 'Caused by:', then research for that, if you don't know what it means. In this case, it's clearly stated that there is a ClassCastException in LoginActivity on line 19. `Caused by: java.lang.ClassCastException: android.widget.RelativeLayout cannot be cast to android.widget.TextView at com.example.sean.cookappreal.LoginActivity.onCreate(LoginActivity.java:19)` – Adinia Jul 26 '17 at 12:29
  • You seriously need to learn some basics about android studio and debugging . – shine_joseph Jul 26 '17 at 12:32
  • While I agree that this is not a duplicate of the question chosen by ModularSynth(not a moderator, btw, just an Android expert), once you post your real error, it'll most surely be a duplicate of another existing question, like https://stackoverflow.com/a/6076490/469983 – Adinia Jul 26 '17 at 12:40
  • issue fixed???? – shine_joseph Jul 26 '17 at 12:47
  • If the OP doesn't **stop changing this post every now and then**, the question will always be invalid for any comment or answer we could provide. Originally, it asked about this error: `The processing instruction target matching “[xX][mM][lL]” is not allowed`. Hence, the duplicate. – Phantômaxx Jul 26 '17 at 12:49
  • Issue not fixed, still looking for help. Something in the LoginActvitity.java (Ik cause app loads and runs when I delete the code i added to it) is causing the app to instacrash. Any insights would be much appreciated. – Sean Kurian Jul 26 '17 at 14:16

1 Answers1

0

as I could see, you use the ID's for etUsername and etPassword twice. You could use them just use once a time per the complete app. Also it's not possible to find and element by the id, which is not in the layout.

Tarik

Tarik Weiss
  • 336
  • 2
  • 15