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 8907421
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T02:54:41+00:00 2026-06-15T02:54:41+00:00

I am trying to work on my android project but getting a null pointer

  • 0

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:

/*—GetSet.java —- */

public class GetSet {

long gwid=0;

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

public long getId()
{
    return gwid;
}

}

The following is my MainActivity.java file

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;
}

}

Line number 69 is where i get the problem which is the foll line:

 obj_getset.setId(setid);

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

 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;
 }

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 ?

LogCat

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

Program closes down unexpectedly.

  • 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-15T02:54:42+00:00Added an answer on June 15, 2026 at 2:54 am

    final GetSet obj_getset = null;

    Well of course you’re getting a nullPointerException; Your obj_getset is defined to be null right there.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to get the browser function in my Android application to work but
I am trying to get Android USB host mode to work; but I need
I'm trying to use this widget ( https://github.com/johannilsson/android-pulltorefresh ) in a phonegap project, but
Trying to build my android project with Buildr (Apache), but can't find any info
I am working on an android project and I am trying to work out
I am trying to use KSoap library in android project to work with webservices
I'm trying to build an Android project using the ndk, but I have run
I am trying to get google maps to work in my android project. I
Trying to work with Eclipse for Android (ADT plugin) development at my iMac (2.4Ghz,
So I am trying to work through the example here: http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/graphics/SurfaceViewOverlay.html and on the

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.