Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9117733
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T04:57:58+00:00 2026-06-17T04:57:58+00:00

Please, I’ve been trying to add ListView to the android app am developing but

  • 0

Please, I’ve been trying to add ListView to the android app am developing but it always starts and then crashes when I add the ListView. I need help. I’ve tried googling for help but found none. I don’t know why its not working. Below is my 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;
  }
} 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T04:57:59+00:00Added an answer on June 17, 2026 at 4:57 am

    You must call setContentView() before trying to use findViewById().

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);  // Move me here
    
        ListView listView= (ListView) findViewById(R.id.listView1);
        // etc 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Please i need help, this code below works fine on my localhost, php5.3+ but
Please let me know what steps I need to follow when my application crashes
Please take a look of my code 1st. I am trying to add some
Please help me I'm developing an android application to display a pinch zoom-able and
Please look at the following code. I can't get my values to add up.
Please look at the screenshot below. I am trying to remove the white space
Please how can I use spl_autoload_register() with Codeigniter? I need to do this because
Please feel free to add multiple answers, each with a single point, to make
Please explain using plain english why we need and why we use Interface in
Please let me know if this has been asked before, I wasn't able to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.