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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T11:53:31+00:00 2026-06-07T11:53:31+00:00

import android.content.Context; import android.content.SharedPreferences; import android.net.Uri; public class LoadSettings { public static void LoadMySettings

  • 0
import android.content.Context;
import android.content.SharedPreferences;
import android.net.Uri;

public class LoadSettings 
{
public static void LoadMySettings   (Context ctx)
{
SharedPreferences sharedPreferences = ctx.getSharedPreferences("MY_SHARED_PREF", 0);
String strSavedMem1 = sharedPreferences.getString("gSendTo", "");
String strSavedMem2 = sharedPreferences.getString("gInsertInto", "");
String cCalId = sharedPreferences.getString("gCalID", "");

setInsertIntoStr(strSavedMem2);
setSendToStr(strSavedMem1);
}

private static String cSendToStr;
private static String cInsertIntoStr;
private int cCalId;
private Uri cCalendars;

public String getSendToStr()
{
    return this.cSendToStr;
}
public static void setSendToStr(String pSendToStr)
{
    cSendToStr = pSendToStr;
}
public String getInsertIntoStr()
{
return this.cInsertIntoStr;
}

public static void setInsertIntoStr(String pInsertIntoStr)
{
cInsertIntoStr = pInsertIntoStr;
}

}

from the calling class i have tryed lots the current is.

LoadSettings.LoadMySettings(this);

but when i try to get some data for example.

textSavedMem1.setText(LoadSettings.getSendToStr());

i get a Null error.

  • 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-07T11:53:33+00:00Added an answer on June 7, 2026 at 11:53 am

    LoadMySettings is not a class but a method (so it should start with a lower case, if you follow Oracle/Sun’s naming conventions for the Java language).

    You access it indeed by calling LoadSettings.loadMySettings(someContext), where someContext is the context to pass around. In your example, we don’t know what this refers to, so maybe your error lies there.


    Then when you do this: textSavedMem1.setText(LoadSettings.getSendToStr());

    You call a non-static method, so that should be either using an instance of LoadSettings or, more likely considering your code, you could change getSendToStr to be:

        public static String getSendToStr()
        {
            return cSendToStr;
        }
    

    Though that seems to be rather bad design.

    Maybe if you tell us more about what you try to do, we can help more, as as such our answers will just take you one step further.


    EDIT: Ok, I just figured out what you are trying to do…

    You need to go back and learn basic Java concepts and read on access modifiers, and constructors first, and OO semantics in Java in general.

    Change your class to this:

    public class LoadSettings 
    {
        public LoadSettings(Context ctx)
        {
            SharedPreferences sharedPreferences =
                ctx.getSharedPreferences("MY_SHARED_PREF", 0);
            String strSavedMem1 = sharedPreferences.getString("gSendTo", "");
            String strSavedMem2 = sharedPreferences.getString("gInsertInto", "");
            String cCalId = sharedPreferences.getString("gCalID", "");
    
            setInsertIntoStr(strSavedMem2);
            setSendToStr(strSavedMem1);
        }
    
        private String cSendToStr;
        private String cInsertIntoStr;
        private int cCalId;
        private Uri cCalendars;
    
        public String getSendToStr()
        {
           return cSendToStr;
        }
    
        public void setSendToStr(String pSendToStr)
        {
            cSendToStr = pSendToStr;
        }
    
        public String getInsertIntoStr()
        {
            return cInsertIntoStr;
        }
    
        public void setInsertIntoStr(String pInsertIntoStr)
        {
            cInsertIntoStr = pInsertIntoStr;
        }
    
    }
    

    And create a new instance of LoadSettings with:

    LoadSettings mySettings = new LoadSettings(someContext);
    

    You can then correctly invoke:

    textSavedMem1.setText(mySettings.getSendToStr());
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

import android.content.Intent; import android.net.*; public class ignitionClass { Intent dialI = new Intent(Intent.ACTION_CALL, Uri.parse(tel:610-970-1218));
import android.content.Intent; import android.content.SharedPreferences; import android.os.Bundle; import android.preference.PreferenceManager; import android.preference.PreferenceActivity; public class Preferences extends
My source code is: import android.content.Context; import android.hardware.SensorManager; public class ShakeEvent implements SensorEventListener {
package com.ewebapps; import android.content.Context; import android.graphics.Canvas; import android.graphics.Paint; import android.view.View; public class Dot extends
Code for SQL class as follows: import java.text.SimpleDateFormat; import java.util.Date; import android.content.ContentValues; import android.content.Context;
I have a very simple dialog defined as: import android.app.AlertDialog; import android.content.Context; import android.view.LayoutInflater;
package nidhin.survey; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteOpenHelper; import android.content.ContentValues; import android.content.Context; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteOpenHelper;
This is my MyTasteActivity code: package MyTaste; import android.app.Activity; import android.content.Context; import android.os.Bundle; import
I've borrowed the following code from Wei-Meng Lee's "Beginning Android Application Development": import android.content.Context;
import com.google.android.maps.MapActivity; import com.google.android.maps.MapView; import android.os.Bundle; public class Map2Activity extends MapActivity { /** Called

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.