1

I have DataBase Table in which i have COULMNS KEY_ID(INT), EMAIL(TEXT), PASSWORD(TEXT), FIRST_NAME(TEXT), LAST_NAME(TEXT)

I have a function in SqliteConnection Class :

public String Well(String el,String pl)
{
    SQLiteDatabase pox =this.getReadableDatabase();
    String qr="SELECT "+FIRST_NAME+" FROM "+TABLE_NAME+" WHERE "+EMAIL+" = "+el+" AND "+PASSWORD+" = "+pl;
    Cursor cur =pox.rawQuery(qr,null);
    String itemname =  cur.getString(cur.getColumnIndex(FIRST_NAME));
    pox.close();
    cur.close();
    return  itemname;

}

In the above function i am passing EMAIL as e1 and PASSWORD as p1 and trying to fetch FIRST_NAME of user that matches EMAIL and PASSWORD.
When i call this function inside any other activity than its causing a java.lang.NullPointerException exception. Is there any problem in this function.

LogCat

12-02 11:02:36.943 2368-2368/? W/dalvikvm: VFY: unable to find class referenced in signature (Landroid/graphics/drawable/Icon;)
12-02 11:02:36.943 2368-2368/? I/dalvikvm: Could not find method android.widget.ImageView.setImageIcon, referenced from method android.support.v7.widget.AppCompatImageView.setImageIcon
12-02 11:02:36.943 2368-2368/? W/dalvikvm: VFY: unable to resolve virtual method 16525: Landroid/widget/ImageView;.setImageIcon (Landroid/graphics/drawable/Icon;)V
12-02 11:02:36.943 2368-2368/? D/dalvikvm: VFY: replacing opcode 0x6f at 0x0000
12-02 11:02:37.073 1559-1574/system_process W/ActivityManager: Launch timeout has expired, giving up wake lock!
12-02 11:02:38.343 1670-1681/com.android.inputmethod.latin W/Binder: Caught a RuntimeException from the binder stub implementation.
                                                                     java.lang.NullPointerException
                                                                         at android.inputmethodservice.IInputMethodWrapper.setSessionEnabled(IInputMethodWrapper.java:280)
                                                                         at com.android.internal.view.IInputMethod$Stub.onTransact(IInputMethod.java:129)
                                                                         at android.os.Binder.execTransact(Binder.java:404)
                                                                         at dalvik.system.NativeStart.run(Native Method)
12-02 11:02:38.343 1559-1713/system_process W/InputMethodManagerService: Got RemoteException sending setActive(false) notification to pid 2323 uid 10055
12-02 11:02:38.353 2368-2368/com.example.sony.sqloperations I/Choreographer: Skipped 83 frames!  The application may be doing too much work on its main thread.
12-02 11:02:40.533 1559-1573/system_process I/ActivityManager: Displayed com.example.sony.sqloperations/.MainActivity: +4s448ms (total +13s453ms)
12-02 11:03:00.013 1616-1616/com.android.systemui D/EGL_emulation: eglMakeCurrent: 0xb8f0e180: ver 2 0
12-02 11:03:00.093 1616-1616/com.android.systemui D/dalvikvm: GC_FOR_ALLOC freed 20284K, 67% free 10469K/30824K, paused 50ms, total 68ms
  • share your crash log with question – Goku Dec 02 '17 at 05:35
  • @Prem Logcat added –  Dec 02 '17 at 05:38
  • share your code for **android.widget.ImageView.setImageIcon** – Goku Dec 02 '17 at 05:42
  • It works perfectly if i dont call the above mentioned function, is this function causing exceptions for other class. –  Dec 02 '17 at 05:44
  • check this https://stackoverflow.com/questions/20683255/windeath-on-notifydatasetchanged – Goku Dec 02 '17 at 05:53
  • 1
    @IntelliJAmiya do you think the function is correct? , please tell me –  Dec 02 '17 at 06:19
  • 2
    Not that I can see how it is causing the issue you are explaining. The method **`Well`** has a flaw in that it is not moving the cursor to point to a row. The cursor when initially retrieved is positioned to before the first row. To position, you could use `if(cur.moveToFirst()) { String itemname = cur.getString(cur.getColumnIndex(FIRST_NAME));}`. – MikeT Dec 02 '17 at 06:25

1 Answers1

0

At first, Use SINGLE quote in SELECT Statement .

  "SELECT  _FIRST_NAME FROM " + TABLE_NAME +" WHERE FIELD_NAME='"_FIELD_VALUE "' AND FIELD_NAME_TWO='" _FIELD_VALUE_TWO  "'";

Then

 if (cursor.moveToFirst()) 
 {
     String itemname = cur.getString(0); // Or (cur.getColumnIndex(YOUR_FIELD_NAME));     
 }
IntelliJ Amiya
  • 74,896
  • 15
  • 165
  • 198
  • 1
    i solved it the reason was the query was not correctly formatted although i accepted your answer as its the same as i solved it –  Dec 07 '17 at 08:12