I just start my hands on Eclipse and want to know what cause error in my apps. I wonder if their is a way like Visual Studio.
What I means is I have got Null pointer Exception but even after putting Breakpoint i am confused what cause error happen.
Because I am new most of time I run bad or code which will not work. How I recognize my mistake. Sometime my code is not working and exception are hard to figure out the real issue happen with my code.
Do someone check the code and guide me how to find it. I means how to know where the null pointer exception happen.
public class MainActivity extends Activity {
Set<String> tasks = new HashSet<String>();
final String prefName = "andorid";
SharedPreferences sp = getSharedPreferences(prefName, MODE_PRIVATE);
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
SetupApp();
}
// / Add the task in this function
private void SetupApp() {
tasks.add("blah");
if (!sp.contains("tasks")) {
Editor edit = sp.edit();
edit.putStringSet("tasks", tasks);
edit.commit();
}
}
public void btnClick(View view) {
EditText etxt = (EditText) findViewById(R.id.txtTask);
tasks.add(etxt.getText().toString());
}
public void UpdateUI(String TaskName) {
final ListView listview = (ListView) findViewById(R.id.listView1);
Set<String> tasks = sp.getStringSet("tasks", new HashSet<String>());
@SuppressWarnings("unchecked")
ArrayList<String> taskarr = (ArrayList<String>) tasks;
final ArrayList<String> list = new ArrayList<String>();
for (int i = 0; i < taskarr.size(); ++i) {
list.add(taskarr.get(i));
}
}
public void LoadTasks() {
}
}
class StableArrayAdapter extends ArrayAdapter<String> {
HashMap<String, Integer> mIdMap = new HashMap<String, Integer>();
public StableArrayAdapter(Context context, int textViewResourceId,
List<String> objects) {
super(context, textViewResourceId, objects);
for (int i = 0; i < objects.size(); ++i) {
mIdMap.put(objects.get(i), i);
}
}
@Override
public long getItemId(int position) {
String item = getItem(position);
return mIdMap.get(item);
}
@Override
public boolean hasStableIds() {
return true;
}
}