代码Activity
:
public class MainActivity extends Activity {
private ListView lv;
private CustomAdapter adapter;
private ArrayList<Event> fetch = new ArrayList<Event>();
private Button button;
int counter = 0;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
adapter = new CustomAdapter(MainActivity.this, R.id.listview,fetch);
lv.setAdapter(adapter);
button = (Button) findViewById(R.id.button);
button.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Event temp=new Event("Date","Details","GeoLocation","Location","EvtName");
fetch.add(temp);
counter++;
adapter.notifyDataSetChanged();
} });
}
}
该应用程序失败,出现Unable to start Activity componentInfo
错误。Logcat
是:
05-06 12:56:34.248: E/AndroidRuntime(2215): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.nasotech/com.nasotech.MainActivity}: java.lang.NullPointerException
我怎样才能解决这个问题?