Login page reading details from SQLite database does not work [closed]

Fruisereash

New Member
Possible Duplicate:
java.lang.NullPointerException when trying to access SQLite database I cannot get my login screen to work. The user should enter their login name and password which is then compared against a database containing previous registrations. Can someone please tell me where I am going wrong and why the code is not working?**Login.java** package com.B00512756.angertwo; import android.app.Activity; import android.content.ContentValues; import android.content.Context; import android.content.Intent; import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteDatabase.CursorFactory; import android.database.sqlite.SQLiteOpenHelper; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.EditText; public class Login extends Activity implements OnClickListener{ public static final String DATABASE_NAME = "login_database.db"; public static final String USER_INFO_TABLE = "user_information"; public static final String COLUMN_ID = "UserID"; public static final String COLUMN_RATING = "UserName"; public static final String COLUMN_NAME = "Password"; public EditText txtUserName; public EditText txtPassword; public static Button btnLogin; public static Button btnCancel; /** Called when the activity is first created. */ @SuppressWarnings("unused") @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.loginpage); txtUserName=(EditText)this.findViewById(R.id.txtUname); txtPassword=(EditText)this.findViewById(R.id.txtPwd); //btnLogin=(Button)this.findViewById(R.id.btnLogin); Button Login = (Button) findViewById(R.id.btnLogin); Button Register = (Button) findViewById(R.id.btnregister); Button Cancel = (Button) findViewById(R.id.btnCancel); Register.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { Intent myIntent = new Intent(view.getContext(), Registration.class); startActivityForResult(myIntent, 0); finish(); } }); Cancel.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { android.os.Process.killProcess(android.os.Process.myPid()); } }); Login.setOnClickListener(new View.OnClickListener() { @SuppressWarnings("null") @Override public void onClick(View v) { // TODO Auto-generated method stub String name = txtUserName.getText().toString(); String pwd = txtPassword.getText().toString(); SQLiteDatabase regDB = null; //String[] columns = new String[]{COLUMN_ID, COLUMN_RATING, COLUMN_NAME }; try { Cursor c = regDB.query(USER_INFO_TABLE, new String[] { COLUMN_ID, COLUMN_RATING, COLUMN_NAME}, null, null, null, null, null); if(null!=c){ c.moveToFirst(); System.out.println("Cursor Size"+c.getCount()); } String result = ""; int iRow = c.getColumnIndex(COLUMN_ID); int iRating = c.getColumnIndex(COLUMN_RATING); int iName = c.getColumnIndex(COLUMN_NAME); c.moveToLast(); for (int i = c.getCount() - 1; i >= 0; i--) { // Get the data result = result + c.getString(iRow) + " " + c.getString(iRating) + " " + c.getString(iName) + "\n" ; if("select * from USER_INFO_TABLE where UserName =" + "\""+ name + "\""+" and Password="+ "\""+ pwd != null ); { Intent j = new Intent(); j.setClassName("com.B00512756.angertwo", "com.B00512756.angertwo.AngerprototypetwoActivity"); startActivity(j);} // Move the cursor c.moveToPrevious(); } c.close(); } catch (Exception e) { } } }); } private SQLiteDatabase getWritableDatabase() { // TODO Auto-generated method stub return null; } @Override public void onClick(View arg0) { // TODO Auto-generated method stub } }**AndroidMainfest:**<?xml version="1.0" encoding="utf-8"?><manifest package="com.B00512756.angertwo" android:versionCode="1" android:versionName="1.0" xmlns:android="http://schemas.android.com/apk/res/android"> <uses-sdk android:minSdkVersion="8" /> <application android:name=".AppState" android:icon="@drawable/icon" android:label="@string/app_name"> <activity android:name=".Login" android:label="@string/main_title"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name=".Login" android:label="@string/begin_label" android:theme="@android:style/Theme"></activity> <activity android:name=".Question1" android:label="@string/question_one" android:theme="@android:style/Theme"></activity> <activity android:name=".Question2" android:label="@string/question_two" android:theme="@android:style/Theme"></activity> <activity android:name=".Question3" android:label="@string/question_three" android:theme="@android:style/Theme"></activity> <activity android:name=".Question4" android:label="@string/question_four" android:theme="@android:style/Theme"></activity> <activity android:name=".Question5" android:label="@string/question_five" android:theme="@android:style/Theme"></activity> <activity android:name=".AngerprototypetwoActivity" android:label="@string/main_title" android:theme="@android:style/Theme"></activity> <activity android:name=".nextQ1" android:id="@+id/next_Q1_button" android:theme="@android:style/Theme"></activity> <activity android:name=".Strategies" android:label="@string/strategies_label" android:theme="@android:style/Theme"></activity> <activity android:name=".Contact" android:label="@string/begin_label" android:theme="@android:style/Theme"></activity> <activity android:name=".Strat_What_Is_Anger" android:label="@string/strategies_label_what_is_anger" android:theme="@android:style/Theme"></activity> <activity android:name=".Strat_Use_Distraction" android:label="@string/strategies_label_distraction" android:theme="@android:style/Theme"></activity> <activity android:name=".Registration" android:label="@string/registration" android:theme="@android:style/Theme"></activity> </application></manifest>
 
Back
Top