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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T23:02:22+00:00 2026-05-27T23:02:22+00:00

This is goign to be very simple i expect to sort out and just

  • 0

This is goign to be very simple i expect to sort out and just me being a newbie going about in circles.

I have multiple tabs across my screen. The following code should read a text input and assign its value to Shared Preferences when another tab is selected. However, whenever i change to another tab my code fails with a NullPointerException – I believe i have tracked it down to the onPause() of the below code, and I believe it is because i am failing to pass the data within the variable correctly.

Any pointers appreciated!

package com.androidbook.epcsn;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;

import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.os.Bundle;
import android.os.Environment;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

@SuppressWarnings("unused")
public class jobActivity extends Activity {   

public static final String SN_PREFERENCES  = "SiteNotePrefs";

SharedPreferences mPrefSettings;
String jobID;
String jobAddress ;
String jobPostcode ;

public void onCreate(Bundle savedInstanceState) {        
    super.onCreate(savedInstanceState);          
    setContentView(R.layout.joblayout); 

    final SharedPreferences mPrefSettings = getSharedPreferences (SN_PREFERENCES, Context.MODE_WORLD_WRITEABLE);

    initjobID();
    initjobaddress();
    initjobpostcode();
}

private void initjobpostcode() {
    EditText jobPostcode = (EditText)findViewById(R.id.jobPostcodeText);
}

private void initjobaddress() {
    EditText jobAddress = (EditText)findViewById(R.id.jobAddressText);
}

private void initjobID() {
    EditText jobID = (EditText)findViewById(R.id.jobIDText);
}

@Override
protected void onPause(){
    super.onPause();

    String strjobID = jobID;
    String strjobAddress = jobAddress;
    String strjobPostcode = jobPostcode;

    Editor editor = mPrefSettings.edit();
    editor.putString("jobID", strjobID);
    editor.putString("jobAddress", strjobAddress);
    editor.putString("jobPostcode", strjobPostcode);
    editor.commit();
}
}
  • 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-05-27T23:02:23+00:00Added an answer on May 27, 2026 at 11:02 pm

    You set values to local variables in the init methods, not the class properties as intended, e.g.:

    EditText jobID;
    
    // Then later... it's clobberin' time.
    private void initjobID() {
        EditText jobID = (EditText)findViewById(R.id.jobIDText);
    }
    

    The property jobID is shadowed by the local jobID declared in the method.

    (Java conventions would name the method initJobId, and the property jobId).

    To set instance properties in the init methods, remove the local declarations and use this pattern:

    EditText jobID;
    private void initjobID() {
        jobID = (EditText)findViewById(R.id.jobIDText);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I can't find concise information about what is going on in this very simple
This is going to be a very simple question, I have code that looks
Hi im a complete newbie and this may seem very simple to any experienced
I'm almost certain this is going to be a very simple answer but I
I have this very simple form: <form id=header_search><input type=text value=search></form> and this is my
I've got a very simple question about a game I created (this is not
This is going to sound too silly / too basic - sorry about that,
This is going to be a long post and just for fun, so if
This seems like a very simple problem, but I cannot get a scrollbox to
I have a very simple model that includes the auto-filled field much like 'created'.

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.