Q: sqlite getPosition() and getCount() crashes app userDB = openOrCreateDatabase("UserDB", Context.MODE_PRIVATE, null);
userDB.execSQL("CREATE TABLE IF NOT EXISTS users(username VARCHAR NOT NULL,password VARCHAR NOT NULL,credential VARCHAR NOT NULL,PRIMARY KEY(username));");
String lineRead;
try {
    lineRead = is.readLine();
    while (lineRead != null) {
        String[] splitLine = lineRead.split(",");
        Cursor c = userDB.rawQuery(
                "SELECT * FROM users WHERE username='" + splitLine[0]
                        + "'", null);
        if (c.getCount() == 0) {
            userDB.execSQL("INSERT INTO users(username, password, credential) VALUES (\'"
                    + splitLine[0]
                    + "\', \'"
                    + splitLine[1]
                    + "\', \'"
                    + splitLine[2] + "\');");
        }
} catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}
Cursor c = userDB.rawQuery(
        "SELECT * FROM users WHERE username='" + username
                + "' AND password='" + password + "'", null);
if (c.getCount() == 0) {
    TextView tv = (TextView) findViewById(R.id.loginResult);
    tv.setText("Invalid User ID/Password.");
    return;
}
TextView tv = (TextView) findViewById(R.id.loginResult);
tv.setText(c.getPosition());

My app keeps crashing whenever it reaches the last line. I think my table is formatted properly and my query should be proper because I've been able to set a TextView to equal the first column of my table with:
tv.setText(c.getColumnNames()[0]);

getPosition() isn't the only function that crashes either, the other ones I've tried that also crashes the app include: getString(0) and getCount(). Though the getCount() in the if block works perfectly fine in checking if something is an existing row in the table.
It also doesn't help that logcat only tells me that this my app crashes only at this line. Any help with why logcat isn't being very descriptive or why my app is crashing at all would be greatly appreciated.

A:    String str= null;
   c.moveToFirst();
    if(c.getCount() > 0){

        str= c.getString(1);  // Here you need to edit string or int. And column no also

    }  else {
       str= "Invalid Login Credentials";
    }
    c.close();
    userDB.close();

  TextView tv = (TextView) findViewById(R.id.loginResult);
  tv.setText(str);


A: Your inputstreamreader (is) encoded. Do a logcat operation just after you do
"lineRead = is.readLine();"and check inputstream reader.

A: You are crashing because you are calling tv.setText with an integer. That integer is supposed to be the ID of a string resource, but you are passing in -1, which is the cursor position before you call one of the set-position functions like moveToFirst.
I'm not sure what your intent is; what text are you trying to put into the TextView?
