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

  • SEARCH
  • Home
  • 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 8124875
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T06:36:46+00:00 2026-06-06T06:36:46+00:00

So I’m making an application for my class where the user submits a form

  • 0

So I’m making an application for my class where the user submits a form and the data is recorded in a database. Right now I’m trying to implement a check that checks if the username the user is trying to pick exists in the database or not. Here’s my code right now:

//Username duplicate check                                                                                                                       
String mSelection = MyContentProvider.COLUMN_USERNAME + "= ?";
String[] mSelectionArgs = new String[] { "Username" };
String[] mProjection = new String[]{MyContentProvider.COLUMN_USERNAME};
mCursor = getContentResolver().query(MyContentProvider.CONTENT_URI,
                                     mProjection,
                                     mSelection,
                                     mSelectionArgs, 
                                     null);
if (mCursor.moveToFirst()){
if (userName.getText().toString().equals(mCursor.getString(mCursor.getColumnIndex(MyContentProvider.COLUMN_USERNAME)))){
    submitCheck = false;
    userName.setHint("Username taken");
}   

}
mCursor.close();

When this is run, the if statement garners an error. Here’s the logcat:

06-24 00:56:55.125: E/AndroidRuntime(907): FATAL EXCEPTION: main
06-24 00:56:55.125: E/AndroidRuntime(907): android.database.CursorIndexOutOfBoundsException: Index -1 requested, with a size of 0
06-24 00:56:55.125: E/AndroidRuntime(907):  at android.database.AbstractCursor.checkPosition(AbstractCursor.java:400)
06-24 00:56:55.125: E/AndroidRuntime(907):  at android.database.AbstractWindowedCursor.checkPosition(AbstractWindowedCursor.java:136)
06-24 00:56:55.125: E/AndroidRuntime(907):  at android.database.AbstractWindowedCursor.getString(AbstractWindowedCursor.java:50)
06-24 00:56:55.125: E/AndroidRuntime(907):  at android.database.CursorWrapper.getString(CursorWrapper.java:114)
06-24 00:56:55.125: E/AndroidRuntime(907):  at com.connor.black.HomeWork2Activity$1.onClick(HomeWork2Activity.java:132)
06-24 00:56:55.125: E/AndroidRuntime(907):  at android.view.View.performClick(View.java:3511)
06-24 00:56:55.125: E/AndroidRuntime(907):  at android.view.View$PerformClick.run(View.java:14105)
06-24 00:56:55.125: E/AndroidRuntime(907):  at android.os.Handler.handleCallback(Handler.java:605)
06-24 00:56:55.125: E/AndroidRuntime(907):  at android.os.Handler.dispatchMessage(Handler.java:92)
06-24 00:56:55.125: E/AndroidRuntime(907):  at android.os.Looper.loop(Looper.java:137)
06-24 00:56:55.125: E/AndroidRuntime(907):  at android.app.ActivityThread.main(ActivityThread.java:4424)
06-24 00:56:55.125: E/AndroidRuntime(907):  at java.lang.reflect.Method.invokeNative(Native Method)
06-24 00:56:55.125: E/AndroidRuntime(907):  at java.lang.reflect.Method.invoke(Method.java:511)
06-24 00:56:55.125: E/AndroidRuntime(907):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
06-24 00:56:55.125: E/AndroidRuntime(907):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
06-24 00:56:55.125: E/AndroidRuntime(907):  at dalvik.system.NativeStart.main(Native Method)

Here’s a little bit of my content provider for some context:

public class MyContentProvider extends ContentProvider{
public final static String DBNAME = "FormStorage";
public static final String AUTHORITY = "com.connor.black.provider";
public final static String TABLE_NAMESTABLE = "formstable";
private static UriMatcher sUriMatcher;

public final static String COLUMN_FIRSTNAME = "FirstName";
public final static String COLUMN_LASTNAME = "LastName";
public final static String COLUMN_PHONE = "PhoneNumber";
public final static String COLUMN_EMAIL = "Email";
public final static String COLUMN_USERNAME = "Username";
public final static String COLUMN_PASSWORD = "Password";
public final static String COLUMN_GENDER = "Gender";
public final static String COLUMN_COUNTRY = "Country";
public static final Uri CONTENT_URI = Uri.parse("content://com.connor.black.provider/" + TABLE_NAMESTABLE);


private static final String SQL_CREATE_MAIN = "CREATE TABLE " + TABLE_NAMESTABLE + "("+"_ID INTEGER PRIMARY KEY, "+
                                                                    "FirstName TEXT, " +
                                                                    "LastName TEXT, " +
                                                                    "PhoneNumber TEXT, " +
                                                                    "Email TEXT, " +
                                                                    "Username TEXT, " +
                                                                    "Password TEXT, " +
                                                                    "Gender TEXT, " +
                                                                    "Country TEXT)";
  • 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-06T06:36:50+00:00Added an answer on June 6, 2026 at 6:36 am

    You should not hard code the column index values directly into your code. This is because,

    1. It’s poor design.

    2. It makes your project difficult to maintain (i.e. if you add a column to your table later, it is possible that the column’s integer could change, thus breaking your code).

    3. There is no way to know for certain if 0 corresponds to the username column. The integer value is assigned by an internal library that manages your SQLite database… you should never rely on internal libraries as the Android team could change the implementation at any time.

    I suggest you change your code to the following:

    int userCol = mCursor.getColumnIndex(MyContentProvider.USERNAME_COLUMN);
    mCursor.getString(userCol);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

this is what i have right now Drawing an RSS feed into the php,
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is
I have a jquery bug and I've been looking for hours now, I can't
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am doing a simple coin flipping experiment for class that involves flipping a
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I need to clean up various Word 'smart' characters in user input, including but

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.