How to use shared preferencesAndroid - Storing/retrieving strings with shared preferencesHow do I efficiently iterate over each entry in a Java Map?How do save an Android Activity state using save instance state?How do I read / convert an InputStream into a String in Java?How do I generate random integers within a specific range in Java?Why is the Android emulator so slow? How can we speed up the Android emulator?Deleting shared preferencesHow do I convert a String to an int in Java?What's the difference between commit() and apply() in Shared PreferenceHow do I fix android.os.NetworkOnMainThreadException?Why is char[] preferred over String for passwords?
Besides the up and down quark, what other quarks are present in daily matter around us?
Why do money exchangers give different rates to different bills?
Is a lifestealing melee cantrip, in the form of booming blade, unbalanced?
Airbnb - host wants to reduce rooms, can we get refund?
Has any spacecraft ever had the ability to directly communicate with civilian air traffic control?
How could a planet have most of its water in the atmosphere?
Should I replace my bicycle tires if they have not been inflated in multiple years
Why wasn't the Night King naked in S08E03?
Identifying my late father's D&D stuff found in the attic
Can I get a paladin's steed by True Polymorphing into a monster that can cast Find Steed?
What are the predominant Christian view on whether Jesus could have avoided crucifixion?
Is there a legal ground for stripping the UK of its UN Veto if Scotland and/or N.Ireland split from the UK?
What are the differences between credential stuffing and password spraying?
Why was the battle set up *outside* Winterfell?
How can I support myself financially as a 17 year old with a loan?
How to reply this mail from potential PhD professor?
Why is `abs()` implemented differently?
Are we obligated to aspire to be Talmidei Chachamim?
Missed the connecting flight, separate tickets on same airline - who is responsible?
Set command option with document wide newcommand
Number of seconds in 6 weeks
Junior developer struggles: how to communicate with management?
Where can I go to avoid planes overhead?
How would adding a darkvision racial trait to Dragonborn affect balance?
How to use shared preferences
Android - Storing/retrieving strings with shared preferencesHow do I efficiently iterate over each entry in a Java Map?How do save an Android Activity state using save instance state?How do I read / convert an InputStream into a String in Java?How do I generate random integers within a specific range in Java?Why is the Android emulator so slow? How can we speed up the Android emulator?Deleting shared preferencesHow do I convert a String to an int in Java?What's the difference between commit() and apply() in Shared PreferenceHow do I fix android.os.NetworkOnMainThreadException?Why is char[] preferred over String for passwords?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
I want to save user entered login values to save in sharedpreferences and retrieve it in another page. But the problem is when I go to data retrieving page app is crashing. Please help me.
LoginActivity.java
SharedPreferences loginData = getSharedPreferences("userInfo",
Context.MODE_PRIVATE);
SharedPreferences.Editor editor = loginData.edit();
editor.putString("password", passwordbox.getText().toString());
editor.putString("userName", usernamebox.getText().toString());
editor.apply();
Data Retrieving page
public class messagewebview extends AppCompatActivity
TextView testing_name;
@Override
protected void onCreate(Bundle savedInstanceState)
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_messagewebview);
SharedPreferences loginData = getSharedPreferences("userInfo", Context.MODE_PRIVATE);
String name = loginData.getString("userName", "");
String pw = loginData.getString("password","");
String msg = "Saved User Name: " + name + "nSaved Password: " + pw;
testing_name.setText(msg);
java
add a comment |
I want to save user entered login values to save in sharedpreferences and retrieve it in another page. But the problem is when I go to data retrieving page app is crashing. Please help me.
LoginActivity.java
SharedPreferences loginData = getSharedPreferences("userInfo",
Context.MODE_PRIVATE);
SharedPreferences.Editor editor = loginData.edit();
editor.putString("password", passwordbox.getText().toString());
editor.putString("userName", usernamebox.getText().toString());
editor.apply();
Data Retrieving page
public class messagewebview extends AppCompatActivity
TextView testing_name;
@Override
protected void onCreate(Bundle savedInstanceState)
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_messagewebview);
SharedPreferences loginData = getSharedPreferences("userInfo", Context.MODE_PRIVATE);
String name = loginData.getString("userName", "");
String pw = loginData.getString("password","");
String msg = "Saved User Name: " + name + "nSaved Password: " + pw;
testing_name.setText(msg);
java
Loads of examples on SO already. Heres an answer that should help. stackoverflow.com/a/12074219/940834 . Do you have a stack trace as to the crash, so we can see why its crashing? your code looks correct, except thattesting_nameis probably null.. You need to load it from the layout
– Doomsknight
Mar 22 at 21:06
add a comment |
I want to save user entered login values to save in sharedpreferences and retrieve it in another page. But the problem is when I go to data retrieving page app is crashing. Please help me.
LoginActivity.java
SharedPreferences loginData = getSharedPreferences("userInfo",
Context.MODE_PRIVATE);
SharedPreferences.Editor editor = loginData.edit();
editor.putString("password", passwordbox.getText().toString());
editor.putString("userName", usernamebox.getText().toString());
editor.apply();
Data Retrieving page
public class messagewebview extends AppCompatActivity
TextView testing_name;
@Override
protected void onCreate(Bundle savedInstanceState)
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_messagewebview);
SharedPreferences loginData = getSharedPreferences("userInfo", Context.MODE_PRIVATE);
String name = loginData.getString("userName", "");
String pw = loginData.getString("password","");
String msg = "Saved User Name: " + name + "nSaved Password: " + pw;
testing_name.setText(msg);
java
I want to save user entered login values to save in sharedpreferences and retrieve it in another page. But the problem is when I go to data retrieving page app is crashing. Please help me.
LoginActivity.java
SharedPreferences loginData = getSharedPreferences("userInfo",
Context.MODE_PRIVATE);
SharedPreferences.Editor editor = loginData.edit();
editor.putString("password", passwordbox.getText().toString());
editor.putString("userName", usernamebox.getText().toString());
editor.apply();
Data Retrieving page
public class messagewebview extends AppCompatActivity
TextView testing_name;
@Override
protected void onCreate(Bundle savedInstanceState)
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_messagewebview);
SharedPreferences loginData = getSharedPreferences("userInfo", Context.MODE_PRIVATE);
String name = loginData.getString("userName", "");
String pw = loginData.getString("password","");
String msg = "Saved User Name: " + name + "nSaved Password: " + pw;
testing_name.setText(msg);
java
java
edited Mar 23 at 7:56
Anurag Srivastava
2,27821220
2,27821220
asked Mar 22 at 21:04
Kavinda NuwanKavinda Nuwan
12
12
Loads of examples on SO already. Heres an answer that should help. stackoverflow.com/a/12074219/940834 . Do you have a stack trace as to the crash, so we can see why its crashing? your code looks correct, except thattesting_nameis probably null.. You need to load it from the layout
– Doomsknight
Mar 22 at 21:06
add a comment |
Loads of examples on SO already. Heres an answer that should help. stackoverflow.com/a/12074219/940834 . Do you have a stack trace as to the crash, so we can see why its crashing? your code looks correct, except thattesting_nameis probably null.. You need to load it from the layout
– Doomsknight
Mar 22 at 21:06
Loads of examples on SO already. Heres an answer that should help. stackoverflow.com/a/12074219/940834 . Do you have a stack trace as to the crash, so we can see why its crashing? your code looks correct, except that
testing_name is probably null.. You need to load it from the layout– Doomsknight
Mar 22 at 21:06
Loads of examples on SO already. Heres an answer that should help. stackoverflow.com/a/12074219/940834 . Do you have a stack trace as to the crash, so we can see why its crashing? your code looks correct, except that
testing_name is probably null.. You need to load it from the layout– Doomsknight
Mar 22 at 21:06
add a comment |
2 Answers
2
active
oldest
votes
Your variable "testing_name" is not initialized. A variable must be initialized before you start using it.
Do following changes in your code.
public class messagewebview extends AppCompatActivity
TextView testing_name;
@Override protected void onCreate(Bundle savedInstanceState)
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_messagewebview);
// Provide a appropriate view id
testing_name = findViewById(R.id.testing_name);
SharedPreferences loginData = getSharedPreferences("userInfo", Context.MODE_PRIVATE);
String name = loginData.getString("userName", "");
String pw = loginData.getString("password","");
String msg = "Saved User Name: " + name + "nSaved Password: " + pw;
testing_name.setText(msg);
add a comment |
testing_name is not initialized.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55307754%2fhow-to-use-shared-preferences%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Your variable "testing_name" is not initialized. A variable must be initialized before you start using it.
Do following changes in your code.
public class messagewebview extends AppCompatActivity
TextView testing_name;
@Override protected void onCreate(Bundle savedInstanceState)
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_messagewebview);
// Provide a appropriate view id
testing_name = findViewById(R.id.testing_name);
SharedPreferences loginData = getSharedPreferences("userInfo", Context.MODE_PRIVATE);
String name = loginData.getString("userName", "");
String pw = loginData.getString("password","");
String msg = "Saved User Name: " + name + "nSaved Password: " + pw;
testing_name.setText(msg);
add a comment |
Your variable "testing_name" is not initialized. A variable must be initialized before you start using it.
Do following changes in your code.
public class messagewebview extends AppCompatActivity
TextView testing_name;
@Override protected void onCreate(Bundle savedInstanceState)
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_messagewebview);
// Provide a appropriate view id
testing_name = findViewById(R.id.testing_name);
SharedPreferences loginData = getSharedPreferences("userInfo", Context.MODE_PRIVATE);
String name = loginData.getString("userName", "");
String pw = loginData.getString("password","");
String msg = "Saved User Name: " + name + "nSaved Password: " + pw;
testing_name.setText(msg);
add a comment |
Your variable "testing_name" is not initialized. A variable must be initialized before you start using it.
Do following changes in your code.
public class messagewebview extends AppCompatActivity
TextView testing_name;
@Override protected void onCreate(Bundle savedInstanceState)
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_messagewebview);
// Provide a appropriate view id
testing_name = findViewById(R.id.testing_name);
SharedPreferences loginData = getSharedPreferences("userInfo", Context.MODE_PRIVATE);
String name = loginData.getString("userName", "");
String pw = loginData.getString("password","");
String msg = "Saved User Name: " + name + "nSaved Password: " + pw;
testing_name.setText(msg);
Your variable "testing_name" is not initialized. A variable must be initialized before you start using it.
Do following changes in your code.
public class messagewebview extends AppCompatActivity
TextView testing_name;
@Override protected void onCreate(Bundle savedInstanceState)
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_messagewebview);
// Provide a appropriate view id
testing_name = findViewById(R.id.testing_name);
SharedPreferences loginData = getSharedPreferences("userInfo", Context.MODE_PRIVATE);
String name = loginData.getString("userName", "");
String pw = loginData.getString("password","");
String msg = "Saved User Name: " + name + "nSaved Password: " + pw;
testing_name.setText(msg);
answered Mar 22 at 21:23
Amrat SinghAmrat Singh
238211
238211
add a comment |
add a comment |
testing_name is not initialized.
add a comment |
testing_name is not initialized.
add a comment |
testing_name is not initialized.
testing_name is not initialized.
edited Mar 22 at 21:28
morten.c
2,72433239
2,72433239
answered Mar 22 at 21:09
Sandeep PolamuriSandeep Polamuri
4387
4387
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55307754%2fhow-to-use-shared-preferences%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Loads of examples on SO already. Heres an answer that should help. stackoverflow.com/a/12074219/940834 . Do you have a stack trace as to the crash, so we can see why its crashing? your code looks correct, except that
testing_nameis probably null.. You need to load it from the layout– Doomsknight
Mar 22 at 21:06