I cannot for the life of me figure out why my launcher activity keeps bailing on me. I've tried debugging but am not getting anything from the output. Can anyone take a look and help? Everything was working fine and then all of sudden...nothing. Won't run in emulator. I'm running intelliJ IDEA Community Edition.
I'm aware that the actual login java code doesn't authenticate or use a password yet. This is just for demonstration purposes before I develop the rest.
Android Manifest
<uses-sdk android:minSdkVersion="23" android:targetSdkVersion="23"/> <uses-permission android:name="android.permission.INTERNET" /> <application android:allowBackup="true" android:label="@string/app_name" android:icon="@drawable/ic_launcher" android:fullBackupContent="true"> <activity android:name=".LoginScreen" android:label="@string/app_name"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name=".dashboardactivity"/> <activity android:name=".RegisterActivity"/> <activity android:name=".messageActivity"/> <activity android:name=".ContactsActivity"/> <activity android:name=".switchContacts"/> </application> </manifest>
Login Screen Java File
package com.Columbus_Switch_Dashboard; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.widget.Button; /** * Created by WBell12 on 12/9/2015. */ public class LoginScreen extends Activity { @Override protected void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); setContentView(R.layout.loginscreen); Button loginBtn =(Button)findViewById(R.id.loginButton); loginBtn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub Intent toDashIntent = new Intent(LoginScreen.this, dashboardactivity.class); //Advance to Dashboard Activity 2/2 startActivity(toDashIntent);} }); Button RegisterBtn =(Button)findViewById(R.id.registerButton); RegisterBtn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub Intent toRegisterIntent = new Intent(LoginScreen.this, RegisterActivity.class); //Advance to Register Activity 2/2 startActivity(toRegisterIntent); } }); }} loginscreen.xml File <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@drawable/loginbackground" android:padding="10dp"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceLarge" android:text="@string/userNameTextRes" android:id="@+id/userNameText" android:layout_marginLeft="0dp" android:layout_marginTop="118dp" android:layout_marginStart="45dp" android:typeface="serif" android:textColor="#ffffff"/> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceLarge" android:text="@string/passwordTextRes" android:id="@+id/passwordText" android:layout_marginTop="29dp" android:typeface="serif" android:layout_below="@+id/userNameText" android:layout_alignParentStart="true" android:textColor="#ffffff"/> <EditText android:layout_width="230dp" android:layout_height="30dp" android:inputType="textPassword" android:ems="10" android:id="@+id/passwordRegisterBox" android:background="#f8f1ff" android:layout_marginLeft="10dp" android:layout_alignBottom="@+id/passwordText" android:layout_alignParentEnd="true"/> <EditText android:layout_width="230dp" android:layout_height="30dp" android:ems="10" android:id="@+id/userNameRegisterBox" android:background="#f8f1ff" android:layout_marginLeft="120dp" android:layout_alignBottom="@+id/userNameText" android:layout_alignParentEnd="true"/> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceLarge" android:text="@string/LoginTitleRes" android:id="@+id/LoginTitle" android:textStyle="bold" android:typeface="serif" android:layout_alignParentTop="true" android:layout_centerHorizontal="true" android:layout_marginTop="39dp" android:textColor="#ffffff"/> <Button android:layout_width="110dp" android:layout_height="wrap_content" android:text="@string/LoginInButtonText" android:id="@+id/loginButton" android:layout_centerVertical="true" android:layout_centerHorizontal="true"/> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" android:layout_marginBottom="46dp" android:textStyle="bold" android:text="@string/logscreenRegisterButton" android:textColor="#ffffff" android:layout_alignParentBottom="true" android:layout_centerHorizontal="true" android:id="@+id/logscreenRegisterButton"/> </RelativeLayout> Logcat Output 12-17 16:49:26.576 9012-9012/com.Columbus_Switch_Dashboard D/AndroidRuntime﹕ Shutting down VM --------- beginning of crash 12-17 16:49:26.578 9012-9012/com.Columbus_Switch_Dashboard E/AndroidRuntime﹕ FATAL EXCEPTION: main Process: com.Columbus_Switch_Dashboard, PID: 9012 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.Columbus_Switch_Dashboard/com.Columbus_Switch_Dashboard. LoginScreen}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.Button.setOnClickListener(android.view.View$OnClickListener)' on a null object reference at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) at android.app.ActivityThread.-wrap11(ActivityThread.java) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:148) at android.app.ActivityThread.main(ActivityThread.java:5417) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.Button.setOnClickListener(android.view.View$OnClickListener)' on a null object reference at com.Columbus_Switch_Dashboard.LoginScreen.onCreate(LoginScreen.java:31) at android.app.Activity.performCreate(Activity.java:6237) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) at android.app.ActivityThread.-wrap11(ActivityThread.java) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:148) at android.app.ActivityThread.main(ActivityThread.java:5417) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
No comments:
Post a Comment