NullPointerException when trying to set the id entered by a user
<p>I am trying to work on my android project but getting a null pointer exception in my main function. 
So, based on the input id, i wish to set the id entered from the editText and retrieve it when i call the get function which will complete my where clause for the condition.
here is my code:</p>

<p>/*---GetSet.java ---- */</p>

<pre><code>public class GetSet {

long gwid=0;

public void setId(long id)
{
    gwid = id;
}

public long getId()
{
    return gwid;
}

}
</code></pre>

<p>The following is my MainActivity.java file</p>

<pre><code>public class MainActivity extends Activity {

EditText etGWid;
Button OKbtn;

public final static String EXTRA_MESSAGE = "com.example.myfirstapp.MESSAGE";

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);


    etGWid = (EditText)findViewById(R.id.etGWID);
    OKbtn = (Button)findViewById(R.id.OKbtn);

    final GetSet obj_getset = null;
    final SharedPreferences app_preferences = PreferenceManager.getDefaultSharedPreferences(this);  
            // Create a shared preferences variable using the SharedPreferenceManager for storing GWids

    SharedPreferences.Editor editor = app_preferences.edit();  // We also need a shared preferences editor to handle the shared preference requests
    // Call the edit method (library function) to editor variable can edit the key, values.

    editor.putInt("47688507", 47688507);   // put in the shared preferences values of user GWids and give them a key for retrieval purposes
    editor.putInt("1234567", 1234567);
    editor.putInt("7654321", 7654321);

    editor.commit();   //commit is necessary to save the shared preferences



    OKbtn.setOnClickListener(new View.OnClickListener() {

        @SuppressWarnings("null")
        @Override
        public void onClick(View arg0) {
            // TODO Auto-generated method stub

            String gwidCheck = etGWid.getText().toString();  //get the value user enters for GWid

            if(app_preferences.contains(gwidCheck))       // this will check the stored shared preferences and compare with the value entered
            {
                Context context = getApplicationContext();
                CharSequence text = "Login Successfull";
                int duration = Toast.LENGTH_SHORT;                              //If it exists, then create a toast message for success



                //etGWid.setText("");    // make the textbox empty
                long setid = Long.parseLong(gwidCheck);   // take the string gwid and convert to long
                obj_getset.setId(setid);    // set the gwid entered
                Toast toast = Toast.makeText(context, text, duration);
                toast.show();
                intentfunction();
            } 
            else
            {
                Context context = getApplicationContext();
                CharSequence text = "Login Failed";                     // If doesnt exist, create a toast for fail
                int duration = Toast.LENGTH_SHORT;

                Toast toast = Toast.makeText(context, text, duration);
                toast.show();
            }

        }
    });
}


private void intentfunction()
{
     Intent intent = new Intent(this, SelectOptions.class);
     //editText = (EditText) findViewById(R.id.editText1);
     //editText = new EditText(this);

    String message = "TestHello";
    intent.putExtra(EXTRA_MESSAGE, message);
    startActivity(intent);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.activity_main, menu);
    return true;
}

}
</code></pre>

<p>Line number 69 is where i get the problem which is the foll line:</p>

<pre><code> obj_getset.setId(setid);
</code></pre>

<p>And this is one of a method in MySQLitehelper.java file that is used to retrieve the row based on the id:</p>

<pre><code> public Cursor getRecord(long rowId) throws SQLException
{
        Cursor mCursor =
        db.query(true, TABLE_NAME, new String[] {COLUMN_ID,
        COLUMN_DATE, COLUMN_LOCATION, COLUMN_TIME},
        COLUMN_ID + "=" + getset.getId(), null, null, null, null, null);
        if (mCursor != null) 
        {
            mCursor.moveToFirst();
        }
 return mCursor;
 }
</code></pre>

<p>My Question is, how do I set the value entered by the user so I can get the value and based on that value, I can put the condition in my where clause just like above. Where am I going wrong ?</p>

<h1>LogCat</h1>

<pre><code>11-29 21:19:22.525: D/AndroidRuntime(10323): Shutting down VM
11-29 21:19:22.525: W/dalvikvm(10323): threadid=1: thread exiting with uncaught         exception (group=0x40a70930)
11-29 21:19:22.583: E/AndroidRuntime(10323): FATAL EXCEPTION: main
11-29 21:19:22.583: E/AndroidRuntime(10323): java.lang.NullPointerException
11-29 21:19:22.583: E/AndroidRuntime(10323):    at     com.example.upd.MainActivity$1.onClick(MainActivity.java:69)
11-29 21:19:22.583: E/AndroidRuntime(10323):    at     android.view.View.performClick(View.java:4202)
11-29 21:19:22.583: E/AndroidRuntime(10323):    at android.view.View$PerformClick.run(View.java:17340)
11-29 21:19:22.583: E/AndroidRuntime(10323):    at android.os.Handler.handleCallback(Handler.java:725)
11-29 21:19:22.583: E/AndroidRuntime(10323):    at android.os.Handler.dispatchMessage(Handler.java:92)
11-29 21:19:22.583: E/AndroidRuntime(10323):    at android.os.Looper.loop(Looper.java:137)
11-29 21:19:22.583: E/AndroidRuntime(10323):    at android.app.ActivityThread.main(ActivityThread.java:5039)
11-29 21:19:22.583: E/AndroidRuntime(10323):    at java.lang.reflect.Method.invokeNative(Native Method)
11-29 21:19:22.583: E/AndroidRuntime(10323):    at java.lang.reflect.Method.invoke(Method.java:511)
11-29 21:19:22.583: E/AndroidRuntime(10323):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
11-29 21:19:22.583: E/AndroidRuntime(10323):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
11-29 21:19:22.583: E/AndroidRuntime(10323):    at dalvik.system.NativeStart.main(Native Method)
11-29 21:19:25.702: I/Process(10323): Sending signal. PID: 10323 SIG: 9
</code></pre>

<p>Program closes down unexpectedly.</p>
