Click here to Skip to main content
15,881,172 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I created a project in android database.

it first it work correctly but i remove some coding and again past it.then it show me

the "the bind value at index 1 is null"
when i press the follwoing delete button



delet_btn.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				try{
			pass=delet_edtt.getText().toString();
			DOP=new DatabaseOperations(CTX);
			Cursor CR=DOP.getUserPass(DOP, USERNAME);
			CR.moveToFirst();
			boolean login_status=false;
			String NAME="";
			if( delet_edtt.getText().toString().trim().length()==0)
			{
						Toast.makeText(getBaseContext(), "Please Enter password", Toast.LENGTH_LONG).show();
			}
			else{
			do{
				if(USERNAME!=null)
				{
			if(pass.equals(CR.getString(0)))
			{
				login_status=true;
			}
				}
			}while(CR.moveToNext());
			
			if(login_status)
			{
			//delet user
				
				DOP.deleteUser(DOP, USERNAME, pass);
				Toast.makeText(getBaseContext(), "Account removed successfully....", Toast.LENGTH_LONG).show();
				}
			
			
			else
			{
				Toast.makeText(getBaseContext(), "Invalid user password....try with correct password", Toast.LENGTH_LONG).show();
				finish();
			}
			}
			}
			
			
			catch(Exception e)
			{
				Toast.makeText(getBaseContext(), e.getMessage(), Toast.LENGTH_LONG).show();
			}
			}
		});
		 
	}
}


this is the database coding




public class DatabaseOperations extends SQLiteOpenHelper {
	public static final int database_version=1;
	public String CREATE_QUERY= "CREATE TABLE "+TableInfo.TABLE_NAME+"("+ TableInfo.USER_NAME+" TEXT,"+TableInfo.USER_PASS+" TEXT);";
	//public String CREATE_QUERY = "CREATE TABLE "+ TableData.TableInfo.TABLE_NAME+"("+ TableData.TableInfo.USER_NAME+" TEXT,"+ TableData.TableInfo.USER_PASS+" TEXT,"+TableData.TableInfo.USER_EMAIL+" TEXT);";
	public DatabaseOperations(Context context) {
		super(context, TableInfo.DATABASE_NAME, null, database_version);
		Log.d("Database operations","Database created");
		// TODO Auto-generated constructor stub
	}

	@Override
	public void onCreate(SQLiteDatabase sdb) {
		// TODO Auto-generated method stub
	sdb.execSQL(CREATE_QUERY);	
	Log.d("Database operations","Table created");
	}

	@Override
	public void onUpgrade(SQLiteDatabase arg0, int arg1, int arg2) {
		// TODO Auto-generated method stub

	}
	public void putInformation(DatabaseOperations dop,String name,String pass)
	{
		SQLiteDatabase SQ=dop.getWritableDatabase();
		ContentValues cv=new ContentValues();
		cv.put(TableInfo.USER_NAME, name);
		cv.put(TableInfo.USER_PASS,pass);
	long k=	SQ.insert(TableInfo.TABLE_NAME, null, cv);
	Log.d("Database operations","one raw inserted");
	}
	
public Cursor getInformation(DatabaseOperations dop)
{
SQLiteDatabase SQ=dop.getReadableDatabase();
String[] columns={TableInfo.USER_NAME,TableInfo.USER_PASS};
Cursor CR=SQ.query(TableInfo.TABLE_NAME, columns, null, null, null, null, null);
return CR;
}
public Cursor getUserPass(DatabaseOperations DOP,String user)
{
	SQLiteDatabase SQ=DOP.getReadableDatabase();
	String selection=TableInfo.USER_NAME +" LIKE ?";
	String columns[]={TableInfo.USER_PASS};
	String args[]={user};
	Cursor CR=SQ.query(TableInfo.TABLE_NAME, columns, selection, args, null, null, null);
	return CR;
}
public void deleteUser(DatabaseOperations DOP,String user,String pass)
{
String selection=TableInfo.USER_NAME +" LIKE ? AND "+TableInfo.USER_PASS +" LIKE ?";
String columns[]={TableInfo.USER_PASS};
String args[]={user,pass};
SQLiteDatabase SQ=DOP.getWritableDatabase();
SQ.delete(TableInfo.TABLE_NAME,selection,args);
}
}
Posted
Updated 1-Sep-15 19:59pm
v9
Comments
Richard MacCutchan 31-Aug-15 3:28am    
The issue seems to be with your DatabaseOperations class, but you have not shown the code. You need to check that you are i) creating the records correctly on registration, and ii) reading them back correctly on login.
wajib rehman 31-Aug-15 8:19am    
sir Richard MacCutchan i updated the question and added the database code please check it and help me .
Richard MacCutchan 31-Aug-15 12:03pm    
I cannot see anything obviously wrong, but then I cannot test it properly. I suggest you use your debugger to check what happens on your INSERT and SELECT operations. Also notice the following two lines:

long k= SQ.insert(TableInfo.TABLE_NAME, null, cv);
Log.d("Database operations","one raw inserted");

You should not put out messages saying something has succeeded unless you first check the status.
wajib rehman 2-Sep-15 1:23am    
ok but now i want to remove (delete) all the data stored in the database.
how i can?
Richard MacCutchan 2-Sep-15 3:35am    
Just delete the file and create a new one.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900