Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Null pointer Exception in shared preference #4

Open
raja-arumugam opened this issue Aug 13, 2018 · 0 comments
Open

Null pointer Exception in shared preference #4

raja-arumugam opened this issue Aug 13, 2018 · 0 comments

Comments

@raja-arumugam
Copy link

raja-arumugam commented Aug 13, 2018

`import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RadioGroup;

public class ChooseLaptopRepair extends AppCompatActivity {

Button button;
RadioGroup radioGroup;
RadioButton radioButton1,radioButton2,radioButton3;
EditText issue;
Context context;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.choose_laptop_repair);

    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    radioGroup = (RadioGroup) findViewById(R.id.lapcondition);
    radioButton1 = (RadioButton) findViewById(R.id.laptopbattery);
    radioButton2 = (RadioButton) findViewById(R.id.laptopdisplay);
    radioButton3 = (RadioButton) findViewById(R.id.laptopOS);
    issue = (EditText) findViewById(R.id.laptopIssue);
    button= (Button) findViewById(R.id.laprepair);

    //shared preference  //Get error here
    SharedPreferences sharedPreferences = context.getSharedPreferences("chooselaptoprepair",Context.MODE_PRIVATE);
    SharedPreferences.Editor shEditor = sharedPreferences.edit();
    shEditor.putBoolean("LapRepairButton1", radioButton1.isChecked()).apply();
    shEditor.putBoolean("LapRepairButton2", radioButton2.isChecked()).apply();
    shEditor.putBoolean("LapRepairButton3", radioButton3.isChecked()).apply();
    shEditor.putString("LapRepairIssue",issue.getText().toString());
    shEditor.commit();

    button.setOnClickListener(new View.OnClickListener()
    {
    @Override
    public void onClick(View v) {
        Intent intent= new Intent(ChooseLaptopRepair.this,BranchActivityLaptopRepair.class);
        startActivity(intent);
    }
    });

}

}`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant