Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7858203
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T21:19:03+00:00 2026-06-02T21:19:03+00:00

I am trying to insert some data into a table I created. I have

  • 0

I am trying to insert some data into a table I created. I have this class:

public class DataBase extends SQLiteOpenHelper {
private static final String DB_NAME = "db_mydatabase";
private static final int DB_VERSION = 1;

private static final String TBL_USERS = "users";
private static final String TBL_USERSE_CREATE = "CREATE TABLE IF NOT EXISTS "
                            + TBL_USERS + "(id integer PRIMARY KEY AUTOINCREMENT, "
                            + "usr varchar(128) NOT NULL UNIQUE, psw varchar(512));";

public DataBase(Context context) {
    super(context, DB_NAME, null, DB_VERSION);
}

public List<String> GetUsersList() {
    List<String> users = new ArrayList<String>();
    SQLiteDatabase db = this.getWritableDatabase();
    Cursor c = db.rawQuery("SELECT id, usr FROM " + TBL_USERS, null);
    if (c != null ) {
        if  (c.moveToFirst()) {
            do {
                String firstName = c.getString(c.getColumnIndex("USR"));
                users.add(firstName);
                } while (c.moveToNext());
        }
    }
    return users;
}

public void CreateNewUser(String username, String password) {
    SQLiteDatabase db = this.getWritableDatabase();
    db.execSQL("INSERT INTO " + TBL_USERS + " (usr, psw) VALUES ('" + username + "', '" + password + "')");
            //If I comment this line, it doesn't crashes anymore, but I don't see why
}

@Override
public void onCreate(SQLiteDatabase db) {
    db.execSQL(TBL_USERSE_CREATE);
}

@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
    db.execSQL("DROP TABLE IF EXISTS " + TBL_USERS);
    onCreate(db);
}

}

So, when I press the REGISTER button, the username and password from a EditText are sent to CreateNewUser. My Activity class looks like this:

public class RegisterActivity extends Activity {
List<String> values;
DataBase dtb;
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.register);

    ListView listView = (ListView) findViewById(R.id.listView1);

    dtb = new DataBase(MainActivity.MainContext);
    values = dtb.GetUsersList();

    listView.setAdapter(new ArrayAdapter<String>(MainActivity.MainContext, R.layout.listitem, values));

    Button Create = (Button) findViewById(R.id.Create);
    Create.setOnClickListener(new View.OnClickListener() {
       public void onClick(View arg0) {
           EditText username = (EditText)findViewById(R.id.Username);
           EditText password = (EditText)findViewById(R.id.Password);
           if (username.getText().length()>0 && password.getText().length()>0) {
               if (values.indexOf(username.getText())<0) {
                   dtb.CreateNewUser(username.getText().toString(), password.getText().toString());
                   values = dtb.GetUsersList();
               }
           }
       }
    });
}

}

I am a beginner as a SQLite programmer and I get this understandable critical error and crash

> **04-24 12:30:51.340: E/CursorWindow(7986): Bad request for field slot 0,-1. numRows = 1, numColumns = 2** 04-24 12:30:51.350:
> D/AndroidRuntime(7986): Shutting down VM 04-24 12:30:51.350:
> W/dalvikvm(7986): threadid=3: thread exiting with uncaught exception
> (group=0x4001b188) 04-24 12:30:51.350: E/AndroidRuntime(7986):
> Uncaught handler: thread main exiting due to uncaught exception
> **04-24 12:30:51.380: E/AndroidRuntime(7986): java.lang.IllegalStateException: get field slot from row 0 col -1
> failed** 04-24 12:30:51.380: E/AndroidRuntime(7986):  at
> android.database.CursorWindow.getString_native(Native Method) 04-24
> 12:30:51.380: E/AndroidRuntime(7986):     at
> android.database.CursorWindow.getString(CursorWindow.java:329) 04-24
> 12:30:51.380: E/AndroidRuntime(7986):     at
> android.database.AbstractWindowedCursor.getString(AbstractWindowedCursor.java:49)
> 04-24 12:30:51.380: E/AndroidRuntime(7986):   at
> com.bma.myagenda.DataBase.GetUsersList(DataBase.java:32) 04-24
> 12:30:51.380: E/AndroidRuntime(7986):     at
> com.bma.myagenda.RegisterActivity$1.onClick(RegisterActivity.java:46)
> 04-24 12:30:51.380: E/AndroidRuntime(7986):   at
> android.view.View.performClick(View.java:2364) 04-24 12:30:51.380:
> E/AndroidRuntime(7986):   at
> android.view.View.onTouchEvent(View.java:4179) 04-24 12:30:51.380:
> E/AndroidRuntime(7986):   at
> android.widget.TextView.onTouchEvent(TextView.java:6541) 04-24
> 12:30:51.380: E/AndroidRuntime(7986):     at
> android.view.View.dispatchTouchEvent(View.java:3709) 04-24
> 12:30:51.380: E/AndroidRuntime(7986):     at
> android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884) 04-24
> 12:30:51.380: E/AndroidRuntime(7986):     at
> android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884) 04-24
> 12:30:51.380: E/AndroidRuntime(7986):     at
> android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884) 04-24
> 12:30:51.380: E/AndroidRuntime(7986):     at
> android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884) 04-24
> 12:30:51.380: E/AndroidRuntime(7986):     at
> android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884) 04-24
> 12:30:51.380: E/AndroidRuntime(7986):     at
> com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1659)
> 04-24 12:30:51.380: E/AndroidRuntime(7986):   at
> com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1107)
> 04-24 12:30:51.380: E/AndroidRuntime(7986):   at
> android.app.Activity.dispatchTouchEvent(Activity.java:2061) 04-24
> 12:30:51.380: E/AndroidRuntime(7986):     at
> com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1643)
> 04-24 12:30:51.380: E/AndroidRuntime(7986):   at
> android.view.ViewRoot.handleMessage(ViewRoot.java:1691) 04-24
> 12:30:51.380: E/AndroidRuntime(7986):     at
> android.os.Handler.dispatchMessage(Handler.java:99) 04-24
> 12:30:51.380: E/AndroidRuntime(7986):     at
> android.os.Looper.loop(Looper.java:123) 04-24 12:30:51.380:
> E/AndroidRuntime(7986):   at
> android.app.ActivityThread.main(ActivityThread.java:4363) 04-24
> 12:30:51.380: E/AndroidRuntime(7986):     at
> java.lang.reflect.Method.invokeNative(Native Method) 04-24
> 12:30:51.380: E/AndroidRuntime(7986):     at
> java.lang.reflect.Method.invoke(Method.java:521) 04-24 12:30:51.380:
> E/AndroidRuntime(7986):   at
> com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
> 04-24 12:30:51.380: E/AndroidRuntime(7986):   at
> com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618) 04-24
> 12:30:51.380: E/AndroidRuntime(7986):     at
> dalvik.system.NativeStart.main(Native Method)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T21:19:06+00:00Added an answer on June 2, 2026 at 9:19 pm

    Change:

    String firstName = c.getString(c.getColumnIndex("USR"));
    

    To:

    String firstName = c.getString(c.getColumnIndex("usr"));  //USR != usr
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to insert some text data into a table in SQL Server
I am trying to insert some data into a pysqlite database but even tho
I have a form that is trying to insert some data into an SQL
I'm trying to insert some binary data into database using 'mysql' gem in ruby.
I am trying to insert some data into the database if the app is
Hello I'm trying to insert some XML data into a table on SQL Server
I'm trying to insert some new objects into a firebird database using NHibernate. I
Trying to archive some data from one database table to another over linked server
I'm trying to insert some import lines into a python source file, but i
I'm trying to insert some symbols from LaTeX Math Symbols into my LaTeX document:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.