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;








-1















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












share|improve this question
























  • 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


















-1















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












share|improve this question
























  • 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














-1












-1








-1








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












share|improve this question
















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 android sharedpreferences






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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

















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













2 Answers
2






active

oldest

votes


















0














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









share|improve this answer






























    0














    testing_name is not initialized.






    share|improve this answer

























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



      );













      draft saved

      draft discarded


















      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









      0














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









      share|improve this answer



























        0














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









        share|improve this answer

























          0












          0








          0







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









          share|improve this answer













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










          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Mar 22 at 21:23









          Amrat SinghAmrat Singh

          238211




          238211























              0














              testing_name is not initialized.






              share|improve this answer





























                0














                testing_name is not initialized.






                share|improve this answer



























                  0












                  0








                  0







                  testing_name is not initialized.






                  share|improve this answer















                  testing_name is not initialized.







                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Mar 22 at 21:28









                  morten.c

                  2,72433239




                  2,72433239










                  answered Mar 22 at 21:09









                  Sandeep PolamuriSandeep Polamuri

                  4387




                  4387



























                      draft saved

                      draft discarded
















































                      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.




                      draft saved


                      draft discarded














                      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





















































                      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







                      Popular posts from this blog

                      SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

                      용인 삼성생명 블루밍스 목차 통계 역대 감독 선수단 응원단 경기장 같이 보기 외부 링크 둘러보기 메뉴samsungblueminx.comeh선수 명단용인 삼성생명 블루밍스용인 삼성생명 블루밍스ehsamsungblueminx.comeheheheh

                      155 수학 과학 기타 둘러보기 메뉴eh추가해eh문서를 완성해