I am developing an android application using java with SQLite. The following code make the error:

String selectQuery = "SELECT * FROM User";
Cursor cursor = db.rawQuery(selectQuery, null);

I checked my program and I found that the cursor make unfortunatly error.

Please help from where is the error come??

I changed the name of the table, but the error is the same

The main idea is that if I want to insert a record to database, there isn't an error, the error is only when selecting a record or may be using the Cursor...

might help if you tell us what the error is...

The application stopped unfortunatly.

the database helper:

public static String getSinlgeEntry(String userName){   
     String selectQuery = "SELECT * FROM lockUser";
     Cursor cursor = db.rawQuery(selectQuery, null);
      if(cursor.getCount()<1){
          cursor.close();
          return "NOT EXIST";
      }
        cursor.close();
        return "zzzzzz";


    }

the main activity:

private OnClickListener onClick=new OnClickListener() {
        public void onClick(View v) {

        String userName=edText1.getText().toString(); 
        String password=edText2.getText().toString(); 

            String storedPassword;

                storedPassword = DBAdapter.getSinlgeEntry("ziad");
                if(storedPassword=="zzzzzz"){
                    Toast.makeText(getApplicationContext(), "Welcome ziad", Toast.LENGTH_LONG).show();
                }
                else{
                    Toast.makeText(getApplicationContext(), "Something wrong ", Toast.LENGTH_LONG).show();
                }
        }
        };

never heard of any database engine giving as an error "the database has stopped unfortunately".
Again, list the actual error...

Hi!
First check the recored is present or not. Because the Toast will never allow you to print the empty result. it will making the " unfortunatly stoped " error..,

No matter which IDE you use there is a logcat which will tell you where error exactly happen. So check it out and stop posting generic error that you see on device screen. You are wasting our time

I found the error and I correct it. Thank you guys.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.