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

  • Home
  • SEARCH
  • 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 8510623
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T03:45:21+00:00 2026-06-11T03:45:21+00:00

my application is still crashing I don’t know I think its because the shared

  • 0

my application is still crashing I don’t know

I think its because the shared preference

in A activity I load the shared preference that was saved in the B activity

and the application its forced close when its first launched

here is my A activity:

public class DawaaActivity extends Activity implements View.OnClickListener {
/** Called when the activity is first created. */
Button add;
SharedPreferences emportPref = this.getSharedPreferences("dawaaData",MODE_PRIVATE);;
String meDawaa = emportPref.getString("subject", "no data yet");

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    Toast.makeText(DawaaActivity.this, meDawaa , Toast.LENGTH_SHORT).show();
    initialaiz();
}

private void initialaiz() {
    // TODO Auto-generated method stub
    add = (Button) findViewById(R.id.button3);
    add.setOnClickListener(this);
}

public void onClick(View v) {
    // TODO Auto-generated method stub
    Intent data = new Intent(DawaaActivity.this,SettingActivity.class);
    startActivity(data);
}

}

this is my B Activity:

public class SettingActivity extends Activity implements View.OnClickListener {
EditText et;
EditText et1;
Spinner list;
TimePicker startTime;
Button save;
Button cancel;
private SharedPreferences exportPref;
@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.setting);
    initialaiz();
}
private void initialaiz() {
    // TODO Auto-generated method stub
    et = (EditText) findViewById(R.id.text);
    et1 = (EditText) findViewById(R.id.text1);
    list = (Spinner) findViewById(R.id.spinner);
    startTime = (TimePicker) findViewById(R.id.timePicker);
    save = (Button) findViewById(R.id.save);
    cancel = (Button) findViewById(R.id.cancel);
    save.setOnClickListener(this);
    cancel.setOnClickListener(this);
}
public void onClick(View v) {
    // TODO Auto-generated method stub
    switch(v.getId()){
    case R.id.save:
        save();
        Intent transferData = new Intent(SettingActivity.this,DawaaActivity.class);
        startActivity(transferData);
        break;
    case R.id.cancel:
        finish();
        break;
    }
}
public void save() {
    // TODO Auto-generated method stub
    exportPref = getSharedPreferences("dawaaData",MODE_PRIVATE);
    SharedPreferences.Editor editor = exportPref.edit();
    editor.putString("subject", et.getText().toString());
    editor.putString("dosesC", et1.getText().toString());
    editor.putString("doses", list.getSelectedItem().toString());
    editor.putInt("hour", startTime.getCurrentHour());
    editor.putInt("minute", startTime.getCurrentMinute());
    editor.putInt("exists", 1);
    editor.commit();
    Toast.makeText(SettingActivity.this,"data has been saved" ,Toast.LENGTH_SHORT).show();
}

}

could you help me??

  • 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-11T03:45:23+00:00Added an answer on June 11, 2026 at 3:45 am

    Change:

    SharedPreferences emportPref = this.getSharedPreferences("dawaaData",MODE_PRIVATE);;
    String meDawaa = emportPref.getString("subject", "no data yet");
    

    To:

    SharedPreferences emportPref;
    String meDawaa;
    

    And add the following to your onCreate() :

    emportPref = this.getSharedPreferences("dawaaData",MODE_PRIVATE);
    meDawaa = emportPref.getString("subject", "no data yet");
    

    You were getting an error because you were trying to use the Activity context before it had been created in onCreate().

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some old code (an old but still maintained VB6 application) that from
In a complete Java EE application that's clustered is the DTO pattern still a
I'm having a problem with an ASP.NET MVC application that I'm developing. I'm still
Does anyone know why my application still receives the ACTION_BOOT_COMPLETED broadcast even when my
Is there a push notification plugin/approach for phonegap (android/iphone) where: the application can still
We are still in .NET 1.1 I have a small application about 15 pages.
I am still trying to test my WinForm application, however some of the testing
My application downloads and caches photos into coreData in background threads while still allowing
I have declared AddType application/x-font-woff woff but chromium still always give me the message
I have ~40 achievements in my Facebook application. I'm still in dev environement performing

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.