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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T21:31:55+00:00 2026-06-14T21:31:55+00:00

I’m trying to store the pin using shared preferences since I have two different

  • 0

I’m trying to store the pin using shared preferences since I have two different activities which are EnterPin and ConfirmPin.

For EnterPin, I have
[start code]

package com.example.textsmslock;

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.v4.app.NavUtils;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class EnterPin extends Activity {
public String[] pin = new String[4];
public Button[] buttons = new Button[10];
public int counter = 0;
public String FILENAME = "pin_file";
public static final String PinCode = "1234";

    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_enter_pin);
    //getActionBar().setDisplayHomeAsUpEnabled(true);

    buttons[1] = (Button)findViewById(R.id.button1);
    buttons[2] = (Button)findViewById(R.id.button2);
    buttons[3] = (Button)findViewById(R.id.button3);
    buttons[4] = (Button)findViewById(R.id.button4);
    buttons[5] = (Button)findViewById(R.id.button5);
    buttons[6] = (Button)findViewById(R.id.button6);
    buttons[7] = (Button)findViewById(R.id.button7);
    buttons[8] = (Button)findViewById(R.id.button8);
    buttons[9] = (Button)findViewById(R.id.button9);
    buttons[0] = (Button)findViewById(R.id.button0);


    //Restore the preferences
    SharedPreferences settings = getSharedPreferences(PinCode, 0);


}
public void button1(View view)
{
    if(counter < 3)
    {
        pin[counter] = "1";
        counter++;
    }
    else
    {
        PinEntered();
    }
}
public void button2(View view)
{
    if(counter < 3)
    {
        pin[counter] = "2";
        counter++;
    }
    else
    {
        PinEntered();
    }
} 
public void button3(View view)
{
    if(counter < 3)
    {
        pin[counter] = "3";
        counter++;
    }
    else
    {
        PinEntered();
    }
}
public void button4(View view)
{
    if(counter < 3)
    {
        pin[counter] = "4";
        counter++;
    }
    else
    {
        PinEntered();
    }
}
public void button5(View view)
{
    if(counter < 3)
    {
        pin[counter] = "5";
        counter++;
    }
    else
    {
        PinEntered();
    }
}
public void button6(View view)
{
    if(counter < 3)
    {
        pin[counter] = "6";
        counter++;
    }
    else
    {
        PinEntered();
    }
}
public void button7(View view)
{
    if(counter < 3)
    {
        pin[counter] = "7";
        counter++;
    }
    else
    {
        PinEntered();
    }
}
public void button8(View view)
{
    if(counter < 3)
    {
        pin[counter] = "8";
        counter++;
    }
    else
    {
        PinEntered();
    }
}
public void button9(View view)
{
    if(counter < 3)
    {
        pin[counter] = "9";
        counter++;
    }
    else
    {
        PinEntered();
    }
}
public void button0(View view)
{
    if(counter < 3)
    {
        pin[counter] = "0";
        counter++;
    }
    else
    {
        PinEntered();
    }
}
public void PinEntered()
{
if(counter == 3)
    {
        putString(pin,0);

    }
}
}

[end code]

for ConfirmPin I have
[start code]

package com.example.textsmslock;

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

import android.os.Bundle;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.support.v4.app.NavUtils;

public class ConfirmPin extends EnterPin {
public String[] pinconfirm = new String[4];
public Button[] buttons = new Button[10];
public int counter = 0;
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_confirm_pin);
    //getActionBar().setDisplayHomeAsUpEnabled(true);
    buttons[1] = (Button)findViewById(R.id.button1);
    buttons[2] = (Button)findViewById(R.id.button2);
    buttons[3] = (Button)findViewById(R.id.button3);
    buttons[4] = (Button)findViewById(R.id.button4);
    buttons[5] = (Button)findViewById(R.id.button5);
    buttons[6] = (Button)findViewById(R.id.button6);
    buttons[7] = (Button)findViewById(R.id.button7);
    buttons[8] = (Button)findViewById(R.id.button8);
    buttons[9] = (Button)findViewById(R.id.button9);
    buttons[0] = (Button)findViewById(R.id.button0);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.activity_confirm_pin, menu);
    return true;
}


@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
        case android.R.id.home:
            NavUtils.navigateUpFromSameTask(this);
            return true;
    }
    return super.onOptionsItemSelected(item);
}
public void button1(View view)
{
    if(counter < 3)
    {
        pinconfirm[counter] = "1";
        counter++;
    }
    else
    {
        ConfirmingPin();
    }
}
public void button2(View view)
{
    if(counter < 3)
    {
        pinconfirm[counter] = "2";
        counter++;
    }
    else
    {
        ConfirmingPin();
    }
} 
public void button3(View view)
{
    if(counter < 3)
    {
        pinconfirm[counter] = "3";
        counter++;
    }
    else
    {
        ConfirmingPin();
    }
}
public void button4(View view)
{
    if(counter < 3)
    {
        pinconfirm[counter] = "4";
        counter++;
    }
    else
    {
        ConfirmingPin();
    }
}
public void button5(View view)
{
    if(counter < 3)
    {
        pinconfirm[counter] = "5";
        counter++;
    }
    else
    {
        ConfirmingPin();
    }
}
public void button6(View view)
{
    if(counter < 3)
    {
        pinconfirm[counter] = "6";
        counter++;
    }
    else
    {
        ConfirmingPin();
    }
}
public void button7(View view)
{
    if(counter < 3)
    {
        pinconfirm[counter] = "7";
        counter++;
    }
    else
    {
        ConfirmingPin();
    }
}
public void button8(View view)
{
    if(counter < 3)
    {
        pinconfirm[counter] = "8";
        counter++;
    }
    else
    {
        ConfirmingPin();
    }
}
public void button9(View view)
{
    if(counter < 3)
    {
        pinconfirm[counter] = "9";
        counter++;
    }
    else
    {
        ConfirmingPin();
    }
}
public void button0(View view)
{
    if(counter < 3)
    {
        pinconfirm[counter] = "0";
        counter++;
    }
    else
    {
        ConfirmingPin();
    }
}

public void ConfirmingPin()
{
          SharedPreferences settings = getSharedPreferences(PinCode, 0);
      SharedPreferences.Editor editor = settings.edit();
      editor.putString(pinconfirm, 0);

      editor.commit();
}
}

I get an error on the when I call putString can someone explain to me why? Am I doing the sharedPreferences incorrectly?

  • 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-14T21:31:56+00:00Added an answer on June 14, 2026 at 9:31 pm

    You are using putString(String key, String value) with wrong types.
    You’re trying to add a stringarray instead of string as the key for the putString();
    Also as the value for the same putString(); you’re adding an int which should be string as well. If you wan’t the first item in pinconfirm:

    editor.putString("PIN", pinconfirm[0].ToString());
    

    If you want to add everything from the array, you can do something like save it as a single commaseperated string:

    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < pinconfirm.length; i++) {
       sb.append(pinconfirm[i]).append(",");
    }
    editor.putString("pinconfirm", sb.toString());
    

    Then when you get the String from SharedPreferences simply parse it like this:

    String[] pinconfirm= pinconfirms.split(",");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have an autohotkey script which looks up a word in a bilingual dictionary
I'm trying to select an H1 element which is the second-child in its group
I have an array which has BIG numbers and small numbers in it. I
I've tracked down a weird MySQL problem to the two different ways I was
I have a text area in my form which accepts all possible characters from
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I have thousands of HTML files to process using Groovy/Java and I need to
I am trying to loop through a bunch of documents I have to put

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.