-1

I want to create a simple app to upload my location .I have two activities and in first activity the user can input parameters url for upload with editbox , a checkbox if user wish upload location save preferences button and start button for go to get location activity.I try this but no work...How i call my function start and save?Any help?I have errors when debug...after click button

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    SharedPreferences preferences = getSharedPreferences("gpstracker" , MODE_PRIVATE);

    String strValue = preferences.getString("Url",strValued);


      edittxtUrl = (EditText)findViewById(R.id.txtUrl);
      edittxtUrl.setText(strValue);


     Button buttonStart = (Button)findViewById(R.id.buttonStart);        
     buttonStart.setOnClickListener(startListener); 

     Button buttonSave = (Button)findViewById(R.id.buttonSave);        
     buttonSave.setOnClickListener(saveListener); 


}

private OnClickListener startListener = new OnClickListener() {
    public void onClick(View v) {

        Start();
    }
};


 private OnClickListener saveListener = new OnClickListener() {
    public void onClick(View v) {

        Save();
    }
};



public void Save() {

 SharedPreferences preferences = getSharedPreferences("gpstracker" , MODE_PRIVATE);
  SharedPreferences.Editor editor = preferences.edit(); 

   edittxtUrl = (EditText)findViewById(R.id.txtUrl);
  String strUrl = edittxtUrl.getText().toString();


  CheckBox chkTandC = (CheckBox)findViewById(R.id.chkTandC);
  boolean blnTandC = chkTandC.isChecked();

  editor.putString("Url", strUrl); // value to store

  editor.putBoolean("TandC", blnTandC); // value to store    
  // Commit to storage
  editor.commit();    

}
public void Start() {

 startActivity(new Intent(this, LocTracker.class));
 }   
user1950855
  • 31
  • 1
  • 4

1 Answers1

0

Without your log cat it is somewhat hard to tell what your problem is, but what I think is happening is that you are passing a null view to the start method, and this is a problem because you are then trying to get a context. Effectively what you have written is

null.getContext()

which doesn't work. You can fix this by replacing view.getContext() with getApplicationContext()

jcw
  • 5,132
  • 7
  • 45
  • 54