開発中のAndroidアプリにListViewを追加しようとしていますが、ListViewを追加すると常に起動し、クラッシュします。私は助けが必要です。グーグルで助けを求めてみましたが、見つかりませんでした。なぜ機能しないのかわかりません。以下は私のMainActivity.javaです
public class MainActivity extends FragmentActivity {
private GoogleMap maap;
static final String[] OptionS = new String[]{"for 1","for 2","for 3","for 4"};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ListView listView= (ListView) findViewById(R.id.listView1);
listView.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
// When clicked, show a toast with the TextView text
Toast.makeText(getApplicationContext(),
((TextView) view).getText(), Toast.LENGTH_SHORT).show();
}
});
setContentView(R.layout.activity_main);
getActionBar().setDisplayHomeAsUpEnabled(true);
GooglePlayServicesUtil.isGooglePlayServicesAvailable(getApplicationContext());
maap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map))
.getMap();
maap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
maap.getUiSettings().setMyLocationButtonEnabled(true);
maap.getUiSettings().setAllGesturesEnabled(true);
CameraPosition Position =new CameraPosition.Builder()
.target(new LatLng(33.53,10.08))
.zoom(7.2f)
.tilt(40)
.build();
CameraUpdate Update = CameraUpdateFactory.newCameraPosition(Position);
maap.moveCamera(Update);
maap.addMarker(new MarkerOptions()
.position(new LatLng(33.53,10.08))
.title("TEST")
.draggable(true)
.snippet("is good"));
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.item1:
startActivity(new Intent(this, ActivityMenus.class));
case R.id.item2:
startActivity(new Intent(this, ActivityMenus.class));
case R.id.item3:
startActivity(new Intent(this, ActivityMenus.class));
case R.id.item4:
startActivity(new Intent(this, ActivityMenus.class));
}
return true;
}
}