-2
    package com.example.alex.askii;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import java.sql.DriverManager;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

//Alex Levin

public class Login extends AppCompatActivity {
    Button login;
    Button signUp;
    EditText userNameET;
    EditText passWordET;
    DatabaseHelper helper = new DatabaseHelper(this);



    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);
        login = (Button)findViewById(R.id.Login);
        signUp = (Button)findViewById(R.id.signUp);
        userNameET = (EditText)findViewById(R.id.username);
        passWordET = (EditText)findViewById(R.id.password);


        login.setOnClickListener(new View.OnClickListener(){
            @Override
            public void onClick(View v){
                //get text valiues
                String userName = userNameET.getText().toString();
                String passWord = passWordET.getText().toString();
                //Query in java the username
                String actualPassword = helper.searchPass(userName);
                //If Correct
                if(passWord.equals(actualPassword)){
                    Toast.makeText(getApplicationContext(),
                            "Redirecting...", Toast.LENGTH_SHORT).show();
                    /*
                    Intent i = new Intent(mainActivity.this, display.class);
                    i.putExtra("UserName", str);
                    startActivity(i)

                    Example code to go to next activity ^^
                     */
                }else{
                    Toast.makeText(getApplicationContext(), "Invalid Username Or Password", Toast.LENGTH_SHORT).show();
                }

            }

        });

        signUp.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent i = new Intent(Login.this, signUP.class);
                startActivity(i);
            }
        });



    }



}

    <?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.example.alex.askii.Login">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Askii Login"
        android:textSize = "30dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.033"
        tools:layout_constraintRight_creator="1"
        tools:layout_constraintLeft_creator="1" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text= "Username:"
        android:textSize="20dp"
        app:layout_constraintRight_toLeftOf="@+id/username"
        tools:layout_constraintRight_creator="1"
        tools:layout_constraintBottom_creator="1"
        app:layout_constraintBottom_toBottomOf="@+id/username"
        android:layout_marginEnd="7dp"
        android:layout_marginBottom="4dp"
        android:layout_marginRight="7dp" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text= "Password:"
        android:textSize="20dp"
        android:id="@+id/textView"
        tools:layout_constraintBottom_creator="1"
        android:layout_marginStart="16dp"
        app:layout_constraintBottom_toBottomOf="parent"
        tools:layout_constraintLeft_creator="1"
        android:layout_marginBottom="169dp"
        app:layout_constraintLeft_toLeftOf="parent"
        android:layout_marginLeft="16dp" />



    <Button xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/Login"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Login"
        android:onClick="login"
        tools:layout_constraintRight_creator="1"
        tools:layout_constraintBottom_creator="1"
        app:layout_constraintBottom_toBottomOf="parent"
        android:layout_marginEnd="84dp"
        app:layout_constraintRight_toRightOf="parent"
        android:layout_marginBottom="88dp"
        android:layout_marginRight="130dp" />

    <EditText
        android:id="@+id/password"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:ems="10"
        android:inputType="textPassword"
        tools:layout_constraintRight_creator="1"
        app:layout_constraintRight_toRightOf="@+id/username"
        app:layout_constraintBaseline_toBaselineOf="@+id/textView"
        tools:layout_constraintBaseline_creator="1"
        tools:layout_constraintLeft_creator="1"
        app:layout_constraintLeft_toLeftOf="@+id/username" />

    <EditText
        android:id="@+id/username"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:ems="10"
        android:inputType="textPersonName"
        android:text="Enter Username"
        tools:layout_constraintBottom_creator="1"
        app:layout_constraintBottom_toTopOf="@+id/password"
        android:layout_marginStart="11dp"
        tools:layout_constraintLeft_creator="1"
        android:layout_marginBottom="20dp"
        app:layout_constraintLeft_toRightOf="@+id/textView"
        android:layout_marginLeft="11dp" />

    <Button xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/signUp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Sign Up"
        tools:layout_constraintRight_creator="1"
        tools:layout_constraintBottom_creator="1"
        app:layout_constraintBottom_toBottomOf="parent"
        android:layout_marginEnd="84dp"
        app:layout_constraintRight_toRightOf="parent"
        android:layout_marginRight="216dp"
        android:layout_marginBottom="47dp" />


</android.support.constraint.ConstraintLayout>

    package com.example.alex.askii;

import android.app.Activity;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

/**
 * Created by Alex on 12/30/2017.
 */

public class signUP extends AppCompatActivity{

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

    }
    Button signUpOnPage = (Button)findViewById(R.id.signUpOnPage);

    public void onSignUpOnPage(View v){
        if(v.getId() == R.id.signUpOnPage){
            EditText userName = (EditText)findViewById(R.id.newUserName);
            EditText passWord = (EditText)findViewById(R.id.newPassWord);
            EditText confPassword = (EditText)findViewById(R.id.newUserName);

            String userNameString = userName.getText().toString();
            String passWordString = passWord.getText().toString();
            String confPasswordString = confPassword.getText().toString();

            if(!passWordString.equals(confPasswordString)){
                Toast check = Toast.makeText(signUP.this, "Passwords Don't Match", Toast.LENGTH_SHORT);
                check.show();
            }
        }
    }
}

For some reason I am getting the following error

12-30 02:39:59.308 1969-1969/com.example.alex.askii E/AndroidRuntime: FATAL EXCEPTION: main
                                                                      java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.alex.askii/com.example.alex.askii.signUP}: java.lang.NullPointerException
                                                                          at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1880)
                                                                          at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
                                                                          at android.app.ActivityThread.access$600(ActivityThread.java:123)
                                                                          at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
                                                                          at android.os.Handler.dispatchMessage(Handler.java:99)
                                                                          at android.os.Looper.loop(Looper.java:137)
                                                                          at android.app.ActivityThread.main(ActivityThread.java:4424)
                                                                          at java.lang.reflect.Method.invokeNative(Native Method)
                                                                          at java.lang.reflect.Method.invoke(Method.java:511)
                                                                          at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
                                                                          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
                                                                          at dalvik.system.NativeStart.main(Native Method)
                                                                       Caused by: java.lang.NullPointerException
                                                                          at android.support.v7.app.AppCompatDelegateImplBase.<init>(AppCompatDelegateImplBase.java:118)
                                                                          at android.support.v7.app.AppCompatDelegateImplV9.<init>(AppCompatDelegateImplV9.java:152)
                                                                          at android.support.v7.app.AppCompatDelegateImplV11.<init>(AppCompatDelegateImplV11.java:29)
                                                                          at android.support.v7.app.AppCompatDelegateImplV14.<init>(AppCompatDelegateImplV14.java:53)
                                                                          at android.support.v7.app.AppCompatDelegate.create(AppCompatDelegate.java:204)
                                                                          at android.support.v7.app.AppCompatDelegate.create(AppCompatDelegate.java:184)
                                                                          at android.support.v7.app.AppCompatActivity.getDelegate(AppCompatActivity.java:518)
                                                                          at android.support.v7.app.AppCompatActivity.findViewById(AppCompatActivity.java:189)
                                                                          at com.example.alex.askii.signUP.<init>(signUP.java:16)
                                                                          at java.lang.Class.newInstanceImpl(Native Method)
                                                                          at java.lang.Class.newInstance(Class.java:1319)
                                                                          at android.app.Instrumentation.newActivity(Instrumentation.java:1023)
                                                                          at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1871)
                                                                          at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981) 
                                                                          at android.app.ActivityThread.access$600(ActivityThread.java:123) 
                                                                          at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147) 
                                                                          at android.os.Handler.dispatchMessage(Handler.java:99) 
                                                                          at android.os.Looper.loop(Looper.java:137) 
                                                                          at android.app.ActivityThread.main(ActivityThread.java:4424) 
                                                                          at java.lang.reflect.Method.invokeNative(Native Method) 
                                                                          at java.lang.reflect.Method.invoke(Method.java:511) 
                                                                          at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784) 
                                                                          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551) 
                                                                          at dalvik.system.NativeStart.main(Native Method) 

I am really unsure why this is happening maybe it is something wrong with my manifests but I doubt it because the manifest was autogenerated. Please help I can't find the answer online because it seems like I followed everything online correctly this is the last place I came to for help I am so frustrated right now!

  • I am sorry about how is this an exact duplicate of anyone elses questions? I am sure people have had similar problems which I have looked at! For some reason just not working for me! Thats why I asked for help! – Alex Levin Dec 30 '17 at 08:01

1 Answers1

0

Move

signUpOnPage = (Button)findViewById(R.id.signUpOnPage);

to onCreate()

ThomasEdwin
  • 2,035
  • 1
  • 24
  • 36