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 7643967
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T09:34:29+00:00 2026-05-31T09:34:29+00:00

I am using arrayadapter to show data on listview.What i have coded is shown

  • 0

I am using arrayadapter to show data on listview.What i have coded is shown below bt i am getting null pointer exception .Please tell me what i have missed ?

ArrayAdapter<String> adapter;
setContentView(R.layout.menu_home_activity);
        OptionsList = (ListView) findViewById(R.id.OptionsLists);
String[] array = getResources().getStringArray(R.array.personal_settings);
            adapter = new ArrayAdapter<String>(MenuHomeActivity.this,
                    R.layout.menu_home_activity, R.id.text, array);
            OptionsList.setAdapter(adapter);

menu_home_activity.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <ListView
        android:name="@+id/OptionsLists"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" >
    </ListView>

</LinearLayout>

Logcat says :

03-14 10:54:59.242: E/AndroidRuntime(267): Uncaught handler: thread main exiting due to uncaught exception
03-14 10:54:59.252: E/AndroidRuntime(267): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.biz.elife/com.biz.elife.MenuHomeActivity}: java.lang.NullPointerException
03-14 10:54:59.252: E/AndroidRuntime(267):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2496)
03-14 10:54:59.252: E/AndroidRuntime(267):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2512)
03-14 10:54:59.252: E/AndroidRuntime(267):  at android.app.ActivityThread.access$2200(ActivityThread.java:119)
03-14 10:54:59.252: E/AndroidRuntime(267):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1863)
03-14 10:54:59.252: E/AndroidRuntime(267):  at android.os.Handler.dispatchMessage(Handler.java:99)
03-14 10:54:59.252: E/AndroidRuntime(267):  at android.os.Looper.loop(Looper.java:123)
03-14 10:54:59.252: E/AndroidRuntime(267):  at android.app.ActivityThread.main(ActivityThread.java:4363)
03-14 10:54:59.252: E/AndroidRuntime(267):  at java.lang.reflect.Method.invokeNative(Native Method)
03-14 10:54:59.252: E/AndroidRuntime(267):  at java.lang.reflect.Method.invoke(Method.java:521)
03-14 10:54:59.252: E/AndroidRuntime(267):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
03-14 10:54:59.252: E/AndroidRuntime(267):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
03-14 10:54:59.252: E/AndroidRuntime(267):  at dalvik.system.NativeStart.main(Native Method)
03-14 10:54:59.252: E/AndroidRuntime(267): Caused by: java.lang.NullPointerException
03-14 10:54:59.252: E/AndroidRuntime(267):  at com.biz.elife.MenuHomeActivity.onCreate(MenuHomeActivity.java:33)
03-14 10:54:59.252: E/AndroidRuntime(267):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
03-14 10:54:59.252: E/AndroidRuntime(267):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2459)
03-14 10:54:59.252: E/AndroidRuntime(267):  ... 11 more

Edit :

33rd line is

OptionsList.setAdapter(adapter);

when i try setting adapter to list it gives error if i remove this line no error is displayed and also no components on screen are displayed only a black screen appears

Thanks everybody for precious time and replys my mistake was in the menu_home_activity i added android:name="@+id/OptionsList"
that i changed to

android:id="@+id/OptionsList"
  • 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-05-31T09:34:30+00:00Added an answer on May 31, 2026 at 9:34 am

    Try to put the code in try-catch block
    I think

    OptionsList = (ListView) findViewById(R.id.OptionsLists);

    is causing a null pointer. Better handle the code for possible exceptions(null or others).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using ListView to show search results. I have a Coustomized arrayListAdapter which returns
I have show Array in listview. with black text color. if i using android.R.color.black
I have a listView with some data coming from a server.I want to do
I have a problem on refresh the listview using thread. How to use it
Using online interfaces to a version control system is a nice way to have
Using TortoiseSVN against VisualSVN I delete a source file that I should not have
Using C# and System.Data.SqlClient, is there a way to retrieve a list of parameters
I am using a progress bar in android, so that till my data is
I'm just getting my feet wet with Android and have built a UI that
Im trying to display this listview, but I keep getting a: 07-17 21:14:22.233: ERROR/AndroidRuntime(349):

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.