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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T18:48:20+00:00 2026-05-27T18:48:20+00:00

Help Please! I have been trying to get my list view to work as

  • 0

Help Please! I have been trying to get my list view to work as efficiently as possible, but it keeps forceclosing with a NullPointerException. Here is my LogCat. I really cant figure it out.

12-31 14:32:35.552: D/AndroidRuntime(240): Shutting down VM
12-31 14:32:35.552: W/dalvikvm(240): threadid=3: thread exiting with uncaught exception (group=0x4001b188)
12-31 14:32:35.552: E/AndroidRuntime(240): Uncaught handler: thread main exiting due to uncaught exception
12-31 14:32:35.602: E/AndroidRuntime(240): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.cerealBarApps/com.cerealBarApps.FirstLoginActivity}: java.lang.NullPointerException
12-31 14:32:35.602: E/AndroidRuntime(240):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2417)
12-31 14:32:35.602: E/AndroidRuntime(240):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2512)
12-31 14:32:35.602: E/AndroidRuntime(240):  at android.app.ActivityThread.access$2200(ActivityThread.java:119)
12-31 14:32:35.602: E/AndroidRuntime(240):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1863)
12-31 14:32:35.602: E/AndroidRuntime(240):  at android.os.Handler.dispatchMessage(Handler.java:99)
12-31 14:32:35.602: E/AndroidRuntime(240):  at android.os.Looper.loop(Looper.java:123)
12-31 14:32:35.602: E/AndroidRuntime(240):  at android.app.ActivityThread.main(ActivityThread.java:4363)
12-31 14:32:35.602: E/AndroidRuntime(240):  at java.lang.reflect.Method.invokeNative(Native Method)
12-31 14:32:35.602: E/AndroidRuntime(240):  at java.lang.reflect.Method.invoke(Method.java:521)
12-31 14:32:35.602: E/AndroidRuntime(240):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
12-31 14:32:35.602: E/AndroidRuntime(240):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
12-31 14:32:35.602: E/AndroidRuntime(240):  at dalvik.system.NativeStart.main(Native Method)
12-31 14:32:35.602: E/AndroidRuntime(240): Caused by: java.lang.NullPointerException
12-31 14:32:35.602: E/AndroidRuntime(240):  at android.content.ContextWrapper.getResources(ContextWrapper.java:80)
12-31 14:32:35.602: E/AndroidRuntime(240):  at com.cerealBarApps.FirstLoginActivity.<init>(FirstLoginActivity.java:30)
12-31 14:32:35.602: E/AndroidRuntime(240):  at java.lang.Class.newInstanceImpl(Native Method)
12-31 14:32:35.602: E/AndroidRuntime(240):  at java.lang.Class.newInstance(Class.java:1479)
12-31 14:32:35.602: E/AndroidRuntime(240):  at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
12-31 14:32:35.602: E/AndroidRuntime(240):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2409)
12-31 14:32:35.602: E/AndroidRuntime(240):  ... 11 more
12-31 14:32:36.962: I/dalvikvm(240): threadid=7: reacting to signal 3
12-31 14:32:37.192: I/dalvikvm(240): Wrote stack trace to '/data/anr/traces.txt'
12-31 14:32:40.592: I/Process(240): Sending signal. PID: 240 SIG: 9

This is my listview code

public class FirstLoginActivity extends ListActivity {
    Context mContext;
    List mList;
    String[] testcontacts;

    MessageView aa = null;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        testcontacts = getResources()
                .getStringArray(R.array.testcontacts_array);

        aa = new MessageView();

        ListView lv = getListView();
        lv.setAdapter(aa);
        lv.setTextFilterEnabled(true);

        lv.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();
            }
        });
    }
class MessageView extends ArrayAdapter<String> {
        MessageView() {
            super(FirstLoginActivity.this, android.R.layout.activity_list_item,
                    testcontacts);
            // TODO Auto-generated constructor stub
        }

        public View getView(int position, View convertview, ViewGroup parent) {
            Log.d("Ebz", "inside getView method");
            ViewHolder holder;
            View v = convertview;
            if (v == null) {
                Log.d("Ebz", "if v == null");
                LayoutInflater inflater = getLayoutInflater();
                v = inflater.inflate(R.layout.list_items, null);
                holder = new ViewHolder();
                holder.firstLine = (TextView) v.findViewById(R.id.firstLine);
                holder.secondLine = (TextView) v.findViewById(R.id.secondLine);
                holder.icon1 = (ImageView) v.findViewById(R.id.icon1);
                holder.icon2 = (ImageView) v.findViewById(R.id.icon2);
                v.setTag(holder);
            } else {
                holder = (ViewHolder) v.getTag();
            }
            holder.firstLine.setText(testcontacts[position]);
            holder.secondLine.setText(testcontacts[position]);
            holder.icon1.setImageBitmap(null);
            holder.icon2.setImageBitmap(null);
            // call the images directly?
            return v;
        }

        class ViewHolder {
            TextView firstLine;
            TextView secondLine;
            ImageView icon1;
            ImageView icon2;

        }
    }
}

My XML:

   <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="?android:attr/listPreferredItemHeight"
        android:padding="6dip" >

        <ImageView
            android:id="@+id/icon1"
            android:layout_width="wrap_content"
            android:layout_height="fill_parent"
            android:layout_alignParentBottom="true"
            android:layout_alignParentTop="true"
            android:layout_marginRight="6dip"
            android:src="@drawable/ic_launcher" />

        <TextView
            android:id="@+id/secondLine"
            android:layout_width="fill_parent"
            android:layout_height="26dip"
            android:layout_alignParentBottom="true"
            android:layout_alignParentRight="true"
            android:layout_toRightOf="@id/icon1"
            android:ellipsize="marquee"
            android:singleLine="true"
            android:text="Some more information" />

        <TextView
            android:id="@+id/firstLine"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_above="@id/secondLine"
            android:layout_alignParentTop="true"
            android:layout_alignWithParentIfMissing="true"
            android:layout_toRightOf="@id/icon1"
            android:gravity="center_vertical"
            android:text="Some Information" />

        <ImageView
            android:id="@+id/icon2"
            android:layout_width="wrap_content"
            android:layout_height="fill_parent"
            android:layout_alignParentRight="true"
            android:layout_alignParentTop="true"
            android:layout_marginRight="6dip"
            android:src="@drawable/ic_launcher" />

    </RelativeLayout>
  • 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-27T18:48:21+00:00Added an answer on May 27, 2026 at 6:48 pm

    Your code is terminating in instance initialization for a FirstLoginActivity object.

    Most likely culprit is this line:

    String[] testcontacts = getResources().getStringArray(
            R.array.testcontacts_array);
    

    Move the initialization to the onCreate handler, getResources is probably returning a null at that point – it is too early in the initialization sequence for all the Activity wiring to be in place.

    String[] testcontacts;
    
    ...
    
      // in onCreate
      testcontacts = getResources().getStringArray(R.array.testcontacts_array);
    

    You should hit a second NullPointerException when you reach:

        ListView lv = null;
        lv.setAdapter(aa);
    

    as pointed out in the other answers – you’re missing a findViewById call.

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

Sidebar

Related Questions

I have been trying to get simple YES/NO radio buttons list working but facing
I have been trying for days to get this code to work, but I
may be too simple groovy question but....please help i have a list like this:
I have been trying to get this to work for 12 hrs now and
Okay I have been trying to get this to work for some time now.
I have been trying to get this code to work for a while now
I have been trying for days to get my gitolite work with jenkins so
I have been trying to get around setting navigationitem button's width property but couldn't
Please help! I have been grappling with this error for days and I cannot
Someone please help. I have an interesting issue. I am trying to implement an

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.