This is my first post at StackExchange. I am a very beginner Android developer. I was making an app for saving arrays(lists). But unfortunately when I run my app it shows {Unfortunately, Shop has stopped!}. I am pretty much familiar with this error and many times I have also been able to get through it. But this time, I can't figure out what am I doing wrong. My code looks perfect but somehow keeps showing that error. I am pasting my java code below. Please go through my code and point my mistake! PLEASE~!
AddItem.java
package com.rcube.shop;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Set;
import android.app.Activity;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class AddItem extends Activity{
SharedPreferences store = PreferenceManager.getDefaultSharedPreferences(getApplication());
SharedPreferences.Editor edit = store.edit();
ArrayList<String> itemarray = new ArrayList<String>();
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.add_item);
Button addnewitem = (Button) findViewById(R.id.addnewitem);
final EditText getitemname = (EditText)findViewById(R.id.getitem);
addnewitem.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
String newitemname = getitemname.getText().toString();
if(newitemname.length()!=0){
itemarray.add(newitemname);
Set<String> itemset = new HashSet<String>(itemarray);
edit.putStringSet("items_set", itemset);
edit.commit();
}else{
Toast.makeText(AddItem.this, "Write Item name before submitting!", Toast.LENGTH_LONG).show();
}
}
});
}
}
Please tell me what am I doing wrong. And I have add new android activity in Android Manifest also, so this error is not because of that. Thanks again! PEACE~!