Update Password using SQLite - android

I am developing an application using SQLite. My requirement is that I want to update a password in my table.
I wrote an update query but it is not working. Error:
android.database.sqlite.SQLiteException: unrecognized token: "' WHERE username = ?": ,
while compiling: UPDATE TABLE_USER SET password = god' WHERE username = ?` condition.
The code:
UserDaoImpl.java
public void updateEntry(String newPassword,String name)
{
Cursor cur= myDB.rawQuery("UPDATE "+UserDBHandler.USER_TABLE+" SET
"+UserDBHandler.PASSWORD+" = "+newPassword+"' WHERE "+
UserDBHandler.USER_NAME+" = ?",new String[]{name});
}
ChangePasswordActivity.java
public class ChngePasswordActivity extends Activity {
private EditText oldPwdEdit;
private EditText newPwdEdit;
private EditText cnfrmEdit;
private Button submitBtn;
private String oldPwd;
private String newPwd;
private String cnfrmPwd;
private UserDaoImpl userDetalsIml;
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_changepassword);
//Bundle extra = this.getIntent().getExtras();
//String name= extra.getString("udp");
Intent intent2=getIntent();
final String name1=intent2.getStringExtra("val");
Log.e("prasad2",name1);
oldPwdEdit = (EditText)findViewById(R.id.oldEdt);
newPwdEdit = (EditText)findViewById(R.id.newpswEdt);
cnfrmEdit = (EditText)findViewById(R.id.pswEdt);
submitBtn = (Button)findViewById(R.id.cnfrmPwdBtn);
submitBtn.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
oldPwd = oldPwdEdit.getText().toString().trim();
newPwd = newPwdEdit.getText().toString().trim();
cnfrmPwd=cnfrmEdit.getText().toString().trim();
if(oldPwd==null||"".equalsIgnoreCase(oldPwd)){
String header = "OLD PASSWORD REQUIRE";
Toast.makeText(getApplicationContext(),header,100).show();
}
else if(newPwd==null ||"".equalsIgnoreCase(newPwd)){
String header = "NEW PASSWORD IS REQUIRE";
Toast.makeText(getApplicationContext(), header,
100).show();
}
else if(cnfrmPwd==null ||"".equalsIgnoreCase(cnfrmPwd)){
String header = "COINFIRM PASSWORD IS REQUIRE";
Toast.makeText(getApplicationContext(), header,
100).show();
}
else if(!newPwd.equalsIgnoreCase(cnfrmPwd)){
String header = "PASSWORD DOES NOT MATCH";
Toast.makeText(getApplicationContext(), header,
100).show();
}
else{
userDetalsIml = new
UserDaoImpl(getApplicationContext());
userDetalsIml.updateEntry(newPwd,name1);
}
}
});
}
}

You are missing a ' in your query at here UserDBHandler.PASSWORD+" = "
Try this updated one
Cursor cur= myDB.rawQuery("UPDATE "+UserDBHandler.USER_TABLE+" SET
"+UserDBHandler.PASSWORD+" = '"+newPassword+"' WHERE "+
UserDBHandler.USER_NAME+" = ?",new String[]{name});

Ooops!! you have done a very little mistakes.
Please replece your code
Cursor cur= myDB.rawQuery("UPDATE "+UserDBHandler.USER_TABLE+" SET
"+UserDBHandler.PASSWORD+" = "+newPassword+"' WHERE "+
UserDBHandler.USER_NAME+" = ?",new String[]{name});
by
Cursor cur= myDB.rawQuery("UPDATE "+UserDBHandler.USER_TABLE+" SET
"+UserDBHandler.PASSWORD+" = '"+newPassword+"' WHERE "+
UserDBHandler.USER_NAME+" = ?",new String[]{name});
There is only missing ' before newPassword .

Related

Retrive my database values from my database and then using them on a programmatic SMS message?

I'm confused and cannot figure out how I can send an SMS message using values stored on my database.
The SMS would appear like this: ('NAME'... Message content, etc..), the message would then be sent using the contact numbers entered by the user on the sqlite database.
Here's the code I've used to get the data during signup.
public class LoginDataBaseAdapter {
static final String DATABASE_NAME = "login.db";
static final int DATABASE_VERSION = 1;
public static final int NAME_COLUMN = 1;
// TODO: Create public field for each column in your table.
// SQL Statement to create a new database.
static final String DATABASE_CREATE = "create table "+"LOGIN"+
"( " +"ID"+" integer primary key autoincrement,"+ "USERNAME text, PASSWORD text, NAME text, C1 integer, C2 integer); ";
// Variable to hold the database instance
public SQLiteDatabase db;
// Context of the application using the database.
private final Context context;
// Database open/upgrade helper
private DataBaseHelper dbHelper;
public LoginDataBaseAdapter(Context _context) {
context = _context;
dbHelper = new DataBaseHelper(context, DATABASE_NAME, null, DATABASE_VERSION);
}
public LoginDataBaseAdapter open() throws SQLException {
db = dbHelper.getWritableDatabase();
return this;
}
public void close()
{
db.close();
}
public SQLiteDatabase getDatabaseInstance()
{
return db;
}
public void insertEntry(String userName,String password, String name, String cn1, String cn2) {
ContentValues newValues = new ContentValues();
// Assign values for each row.
newValues.put("USERNAME", userName);
newValues.put("PASSWORD",password);
newValues.put("NAME",name);
newValues.put("C1", cn1);
newValues.put("C2", cn2);
// Insert the row into your table
db.insert("LOGIN", null, newValues);
// Toast.makeText(context, "Reminder Is Successfully Saved", Toast.LENGTH_LONG).show();
}
public int deleteEntry(String UserName) {
//String id=String.valueOf(ID);
String where="USERNAME=?";
int numberOFEntriesDeleted= db.delete("LOGIN", where, new String[]{UserName}) ;
// Toast.makeText(context, "Number fo Entry Deleted Successfully : "+numberOFEntriesDeleted, Toast.LENGTH_LONG).show();
return numberOFEntriesDeleted;
}
public String getSingleEntry(String userName) {
Cursor cursor = db.query("LOGIN", null, " USERNAME=?", new String[]{userName}, null, null, null);
if(cursor.getCount()<1) { // username doesn't exist
cursor.close();
return "NOT EXIST";
}
cursor.moveToFirst();
String password = cursor.getString(cursor.getColumnIndex("PASSWORD"));
cursor.close();
return password;
}
public boolean isExist (String userName) {
boolean exists;
Cursor cursor = db.query("LOGIN", null, " USERNAME=?", new String[]{userName}, null, null, null);
if (cursor.getCount()>0) { // username exists
exists = true;
cursor.close();
return exists;
}
return false;
}
public void updateEntry(String userName,String password) {
// Define the updated row content.
ContentValues updatedValues = new ContentValues();
// Assign values for each row.
updatedValues.put("USERNAME", userName);
updatedValues.put("PASSWORD", password);
String where="USERNAME = ?";
db.update("LOGIN",updatedValues, where, new String[]{userName});
}}
And here is the SignUpActivity
public class SignUpActivity extends AppCompatActivity {
Button bSignup;
TextView tvSign;
EditText etUN, etPW, etPW2, etFN, etC1, etC2;
LoginDataBaseAdapter loginDataBaseAdapter;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sign_up);
loginDataBaseAdapter = new LoginDataBaseAdapter(this);
loginDataBaseAdapter = loginDataBaseAdapter.open();
bSignup = (Button)findViewById(R.id.bSignup);
tvSign = (TextView)findViewById(R.id.tvSign);
etUN = (EditText)findViewById(R.id.etUN);
etPW = (EditText)findViewById(R.id.etPW);
etPW2 = (EditText)findViewById(R.id.etPW2);
etFN = (EditText)findViewById(R.id.etFN);
etC1 = (EditText)findViewById(R.id.etC1);
etC2 = (EditText)findViewById(R.id.etC2);
bSignup.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
String username = etUN.getText().toString();
String password = etPW.getText().toString();
String password2 = etPW2.getText().toString();
String name = etFN.getText().toString();
String c1 = etC1.getText().toString();
String c2 = etC2.getText().toString();
// check if fields are vacant
if (username.equals("") || password.equals("") || password2.equals("") || name.equals("")
|| c1.equals("")|| c2.equals("")) {
Toast.makeText(getApplicationContext(), "Incomplete Data", Toast.LENGTH_SHORT).show();
return;
}
// check if passwords 1 and 2 match
if (!password.equals(password2)) {
Toast.makeText(getApplicationContext(), "Passwords don't match. Please try again.", Toast.LENGTH_LONG).show();
return;
}
//check is username is still available for use
if (loginDataBaseAdapter.isExist(username)){
Toast.makeText(getApplicationContext(),"Username already taken. Please try again.", Toast.LENGTH_LONG).show();
return;
}
else {
// allow data to be saved in the database
loginDataBaseAdapter.insertEntry(username, password, name, c1, c2);
Toast.makeText(getApplicationContext(), "Account Successfully Created ", Toast.LENGTH_LONG).show();
Intent intent = new Intent(getApplicationContext(), MainActivity.class);
startActivity(intent);
}
}
});
tvSign.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent intent = new Intent(getApplicationContext(), MainActivity.class);
startActivity(intent);
}
});
}
}
Once I'm logged in, how can I get those values ("i.e. NAME, C1, and C2") and send an SMS by pushing a button?
Update
I've used this on my LoginDataBaseAdapter.
public HashMap<String, String> getUserDetails(){
HashMap <String,String> user = new HashMap <String,String> ();
String selectQuery = "SELECT * FROM " + "LOGIN";
Cursor cursor = db.rawQuery(selectQuery, null);
// Move to first row
cursor.moveToFirst();
if(cursor.getCount()>0){
user.put("USERNAME", cursor.getString(1));
user.put("PASSWORD", cursor.getString(2));
user.put("NAME", cursor.getString(3));
user.put("C1", cursor.getString(4));
user.put("C2", cursor.getString(5));
}
cursor.close();
db.close();
// return user
return user;
}
Then this code at my HomeActivity:
tvHello = (TextView)findViewById(R.id.tvHello);
HashMap <String, String> details = loginDataBaseAdapter.getUserDetails();
String name_text = details.get("NAME");
tvHello.setText("Welcome " + name_text);
It seems that it can only get the first entry and not the current entry for the current user. Any ideas to fix this issue? Thank you very much.
Managed to get it right. So I'll answer my own question.
Create a editText area wherein you'll enter your name to retrieve. Then use this code to retrieve it
public String getData(String verif) {
Cursor cursor = db.query("LOGIN", null, " USERNAME=?", new String[]{verif}, null, null, null);
if(cursor.getCount()<1) {
cursor.close();
return "No records exist";
}
cursor.moveToFirst();
String get_name = cursor.getString(cursor.getColumnIndex("NAME"));
cursor.close();
return get_name;
}
Once retrieved, set the name in a TextView. Then convert it to string like so:
String myName = myTextView.getText().toString();
Then:
smsManager.sendTextMessage(number, null, "My name is "+ myName ,null,
null);
'number' is a String containing the contact number where you want to send your SMS

Android-value not able to set in textview

I have a SQLite database add2cart which stores details of products added to cart.I need to display the number of products each user have in their cart,in a text view. crtno is my textview.I want to display the number in textview when each user clicks add2cart button.
code
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.product_dtls);
name = (TextView) findViewById(R.id.txtPr_name);
price = (TextView) findViewById(R.id.txtprice);
specification=(TextView)findViewById(R.id.txtPr_spec);
feature=(TextView)findViewById(R.id.txtPr_feature);
crtno=(TextView)findViewById(R.id.crtno);
add2cart=(Button)findViewById(R.id.add2cart);
DataBaseHandler dbh = new DataBaseHandler(this);
SQLiteDatabase db = dbh.getWritableDatabase();
Intent in = getIntent();
Bundle bn = in.getExtras();
Bundle bun=in.getExtras();
final String dtl=bun.getString("key");
nme = bn.getString("name");
Cursor cr = db.rawQuery("SELECT * FROM product WHERE pname = '"+nme+"'", null);
while(cr.moveToNext())
{
String name = cr.getString(cr.getColumnIndex("pname"));
String pr1price = cr.getString(cr.getColumnIndex("pprice"));
String prspc=cr.getString(cr.getColumnIndex("pspec"));
String prfeature=cr.getString(cr.getColumnIndex("pfeature"));
pname = name;
prprice = pr1price;
pspec=prspc;
pfeature=prfeature;
}
name.setText(pname);
price.setText("Rs " +prprice + "/-");
specification.setText(pspec);
feature.setText(pfeature);
add2cart.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
boolean incart=false;
String nm=name.getText().toString();
mydb=Product_Details.this.openOrCreateDatabase("addcart", MODE_PRIVATE, null);
mydb.execSQL("CREATE TABLE IF NOT EXISTS add2cart(usr TEXT,img BLOB,pnme TEXT,prate NUMERIC,pqty NUMERIC,ptotl NUMERIC)");
Cursor cur=mydb.rawQuery("select * from add2cart where pnme='"+nm+"' AND usr='"+dtl+"'",null);
if (cur.moveToFirst()){
String prdname=cur.getString(cur.getColumnIndex("pnme"));
if (nm.equals(prdname)){
add2cart.setText("Already in Cart");
incart=true;
}
}
if(incart==false){
mydb.execSQL("INSERT INTO add2cart (usr,pnme,prate)VALUES('"+dtl+"','"+nm+"','"+prprice+"')");
Toast.makeText(getApplicationContext(),"added to cart",Toast.LENGTH_SHORT).show();
Cursor crsr=mydb.rawQuery("select pnme from add2cart where usr='"+dtl+"'", null);
// int count=0;
Boolean val=false;
int count=crsr.getCount();
Toast.makeText(getApplicationContext(),"count"+count, Toast.LENGTH_LONG).show();
crtno.setText(Integer.toString(count));
// abc=crtno.getText().toString();
if (crtno!=null) {
val=true;
crtno.setText(Integer.toString(count));
}
if (val=false) {
crtno.setText("0");
}
}
}
});
}
}
change condition.(make sure you have done above on click listner crtno = findviewbyId....)
if(count != null && count > 0){
crtno.setText(count+"");
}else{
crtno.setText("0");
}

Android-Null pointer Exception in setText

I have a SQLite database to store items in cart. I need to get the count of products in cart corresponding to each user and set it to a textview,each time the user clicks addtocart button.But my code throws an null point exception.please help me.
I am getting nullpointer Exception in line 109: if (!crtno.getText().toString().equals(""))
code
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.product_dtls);
crtno=(TextView)findViewById(R.id.crtno);
imgbtn=(ImageButton)findViewById(R.id.cartimg);
add2cart=(Button)findViewById(R.id.add2cart);
DataBaseHandler dbh = new DataBaseHandler(this);
SQLiteDatabase db = dbh.getWritableDatabase();
Intent in = getIntent();
Bundle bn = in.getExtras();
Bundle bun=in.getExtras();
final String dtl=bun.getString("key");
nme = bn.getString("name");
Cursor cr = db.rawQuery("SELECT * FROM product WHERE pname = '"+nme+"'", null);
while(cr.moveToNext())
{
String name = cr.getString(cr.getColumnIndex("pname"));
String pr1price = cr.getString(cr.getColumnIndex("pprice"));
String prspc=cr.getString(cr.getColumnIndex("pspec"));
String prfeature=cr.getString(cr.getColumnIndex("pfeature"));
pname = name;
prprice = pr1price;
pspec=prspc;
pfeature=prfeature;
}
name.setText(pname);
price.setText("Rs " +prprice + "/-");
specification.setText(pspec);
feature.setText(pfeature);
add2cart.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
boolean incart=false;
String nm=name.getText().toString();
mydb=Product_Details.this.openOrCreateDatabase("addcart", MODE_PRIVATE, null);
mydb.execSQL("CREATE TABLE IF NOT EXISTS add2cart(usr TEXT,img BLOB,pnme TEXT,prate NUMERIC,pqty NUMERIC,ptotl NUMERIC)");
Cursor cur=mydb.rawQuery("select * from add2cart where pnme='"+nm+"' AND usr='"+dtl+"'",null);
if (cur.moveToFirst()){
String prdname=cur.getString(cur.getColumnIndex("pnme"));
if (nm.equals(prdname)){
add2cart.setText("Already in Cart");
incart=true;
}
}
if(incart==false){
mydb.execSQL("INSERT INTO add2cart (usr,pnme,prate)VALUES('"+dtl+"','"+nm+"','"+prprice+"')");
Toast.makeText(getApplicationContext(),"added to cart",Toast.LENGTH_SHORT).show(); Cursor crsr=mydb.rawQuery("select pnme from add2cart where usr='"+dtl+"'", null);
int count=0;
if (!crtno.getText().toString().equals("")) {
count=crsr.getCount();
}
crtno.setText(Integer.toString(count));
}
}
});
}
}
Try like
crtno.getText().toString().equals("")
instead of
crtno.equals("")
Because crtno.getText().toString().equals("") is the command for checking equality of the text inside the textview.
At first you should first pull string displayed in textview and it's done as by:
getText()
Return the text the TextView is displaying.
so your way should be
crtno.getText().toString().equals("")
also try this
crtno.getText().toString().equals(null)

how to get data from database with condition input an edittext in sqlite android?

I have two edittexts and one button. When pressing the button, if string value of two edittext exist in table then notify: You login success!
It is my code but not working. Help me!Thanks
final String sql_selectLogin =
"select * from sinhvien where username= ? and password=?";
btOK.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Cursor cs = data.rawQuery(sql_selectLogin, new String[] {username, password});
// TODO Auto-generated method stub
if (cs.getCount() == 1)
Toast.makeText(
MainActivity.this,
"You just have succesfull logined by username= " +
edit_username.getText().toString(),
Toast.LENGTH_SHORT).show();
else
Toast.makeText(
MainActivity.this,
"You fail login",
Toast.LENGTH_SHORT).show();
}
});
EDIT
This is my full code:
public class MainActivity extends ActionBarActivity {
EditText edit_username, edit_password;
Button btOK;
SQLiteDatabase data;
String dataname = "login.db";
String tablename = "sinhvien";
String colnameID = "id";
String colnameUser = "username";
String colnamePassword = "password";
String sql_createTable = "create table sinhvien(id integer primary key autoincrement,"
+ "username nvarchar(50) not null, password nvarchar(50) not null);";
String sql_insertTable = "insert into sinhvien(username,password) values('hiunicy','hiunicy123');";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
edit_username = (EditText) findViewById(R.id.editUsername);
edit_password = (EditText) findViewById(R.id.editPassword);
btOK = (Button) findViewById(R.id.btOk);
final String username = edit_username.getText().toString();
final String password = edit_password.getText().toString();
final SQLiteDatabase data = openOrCreateDatabase("sinhvien.db",
MODE_PRIVATE, null);
data.execSQL(sql_createTable);
ContentValues values = new ContentValues();
values.put(colnameUser, "hiunicy1");
values.put(colnamePassword, "hiunicy1233");
data.insert("sinhvien", null, values);
final String sql_selectLogin = "select * from sinhvien where username=? and password=?";
btOK.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Cursor cs = data.rawQuery(sql_selectLogin, new String[] {
username, password });
// TODO Auto-generated method stub
if (cs.getCount() > 0)
Toast.makeText(
MainActivity.this,
"You just have succesfull logined by username= "
+ edit_username.getText().toString(),
Toast.LENGTH_SHORT).show();
else
Toast.makeText(MainActivity.this, "You fail login",
Toast.LENGTH_SHORT).show();
}
});
}
}
Cursor mCursor = db.rawQuery("select * from sinhvien
where username =? and password=?" , new String[] { username,password});
if (mCursor != null) {
if (mCursor.getCount() > 0) {
Toast.makeText(
MainActivity.this,
"You just have succesfull logined by username= "
+ edit_username.getText().toString(),
Toast.LENGTH_SHORT).show();}
else{
Toast.makeText(MainActivity.this, "You fail login",
Toast.LENGTH_SHORT).show();}}
Do like this.
You can do something like this
Cursor findEntry = db.query("sinhvien", columns, "username=? and password=?", new String[] { username, password}, null, null, null);

"Null" appended to database input values from a delimited string

I wonder if someone could show me the error of my ways--I've been struggling with this issue for two days, and realize it must be a fundamental error of initializing variables, but...that reflects the level of my java knowledge.
I'm getting a database result on a delimited string wherein each of the segments has "null" appended to it. It seems that no matter how I change the initialization...well, two days!
I'm declaring the following in the class heading area:
private String strListContent;
private SQLiteDatabase database;
private DatabaseHelper helper2 = new DatabaseHelper(this);
private static final String fields[] = { "_id", "listTitle", "listType",
"listContent", "dateCreated", "dateModified" };
private ArrayList<String> textArray = new ArrayList<String>();
private ArrayList<Integer> imageArray = new ArrayList<Integer>();
Then concatenating my items in
final ImageButton addItem = (ImageButton) findViewById(R.id.btnToAddItem);
addItem.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
itemEdit = (EditText) findViewById(R.id.editTextItem);
if (itemEdit.getText().toString().equals("")) {
showToastMessage("Please enter an item to add...");
} else {
String newListItem = itemEdit.getText().toString();
strListContent += newListItem + "|~|";
...
}}}
I'm using the following bare-bones SQLiteOpenHelper:
public class DatabaseHelper extends SQLiteOpenHelper {
public static final String KEY_ID = "_id";
public DatabaseHelper(Context context) {
super(context, "Cursor", null, 1);
}
#Override
public void onCreate(SQLiteDatabase db) {
db.execSQL("CREATE TABLE IF NOT EXISTS list_data ("
+ KEY_ID
+ " INTEGER PRIMARY KEY AUTOINCREMENT, listTitle TEXT, listType TEXT, listContent TEXT, dateCreated TEXT, dateModified TEXT)");
}
#Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
// Steps to upgrade the database for the new version ...
}
}
To insert the values as so:
ImageButton saveAndBack = (ImageButton) findViewById(R.id.btnSaveBack);
saveAndBack.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
String title = null;
String listContent = null;
Calendar javaCalendar = null;
title = titleEdit.getText().toString();
title = (title=="" || title==null)?"Untitled List":title;
strListContent = (strListContent=="" || strListContent==null)?"No Items|~|":strListContent;
listContent = strListContent;
String type = "R"; //"Regular List"
javaCalendar = Calendar.getInstance();
String currentDate = javaCalendar.get(Calendar.MONTH) + "/" + (javaCalendar.get(Calendar.DATE) + 1) + "/" + javaCalendar.get(Calendar.YEAR);
database = helper2.getWritableDatabase();
ContentValues values = new ContentValues();
values.put("listTitle", title);
values.put("listType", type);
values.put("listContent", listContent);
values.put("dateCreated", currentDate);
values.put("dateModified", currentDate);
database.insert("list_data", null, values);
Intent i = new Intent(RegularList.this, ActivityMain.class);
startActivity(i);
}
});
}
//
//End of OnCreate(){}
//
Then, when I retrieve from another activity:
DatabaseHelper helper = new DatabaseHelper(this);
database = helper.getWritableDatabase();
Cursor data = database.query("list_data", fields, null, null, null,
null, null);
Integer tindex = data.getColumnIndex("listTitle");
Integer iindex = data.getColumnIndex("listType");
Integer cindex = data.getColumnIndex("listContent");
itemCount = 0;
for (data.moveToFirst(); !data.isAfterLast(); data.moveToNext()) {
showToastMessage(data.getString(cindex));
titleArrayList.add(data.getString(tindex));
if (data.getString(iindex) == "R") {
imageArrayList.add(R.drawable.listview_regular);
} else if (data.getString(iindex) == "L") {
imageArrayList.add(R.drawable.listview_location);
} else {
imageArrayList.add(R.drawable.listview_regular);
}
itemCount++;
}
data.close();
...
I can see in the toast message that each item from the delimited string has "null" appended to the front of it...the other values are fine. I hope this hasn't been too verbose, but...any recommendations? Thanks!
To me it looks like you may have simply not initialised the String strListContent before you first append to it with:
strListContent += newListItem + "|~|";
When you do that, you'll get a "null" prefixed in front of the value you are trying to append, just as you observe.
Perhaps you can just initialise in the declaration:
private String strListContent = "";

Categories

Resources