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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T12:16:33+00:00 2026-06-01T12:16:33+00:00

I have a ListActivity which has an adapter that crashes. Here is the code

  • 0

I have a ListActivity which has an adapter that crashes. Here is the code that crashes the program:

Question q = new Question ();
q.setQuestion( "" );

questions.add(q);       

adapter = new ArrayAdapter<Question>(this, R.layout.user_question_list, 
        R.id.label,  questions);

Here is how I create the adapter:

ArrayAdapter<Question> adapter; 

ArrayList<Question> questions = new ArrayList <Question>( );        

and the list xml is like this:

<?xml version="1.0" encoding="utf-8"?>

<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:padding="10dp"
    android:textSize="16sp" >
</TextView>    

and the overall Activity xml is like this:

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


<TextView
    android:id="@+id/question_label"    
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="Loading your questions..."
    />     

    <ListView
    android:id="@android:id/list"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@+id/label"
        android:textSize="20px" >        
    </ListView>

        <Button  
            android:id="@+id/add_question"  
            android:layout_height="wrap_content"  
            android:text="Ask a Question"
            android:onClick="sendFeedback"  
            android:layout_width="fill_parent">  
        </Button>     

</LinearLayout>

Any idea why the code where I try to update the adapter results in the NullPointerException?

Here is the error log:

04-06 18:43:19.626: D/AndroidRuntime(2564): Shutting down VM
04-06 18:43:19.626: W/dalvikvm(2564): threadid=1: thread exiting with uncaught exception (group=0x409c01f8)
04-06 18:43:19.686: E/AndroidRuntime(2564): FATAL EXCEPTION: main
04-06 18:43:19.686: E/AndroidRuntime(2564): java.lang.NullPointerException
04-06 18:43:19.686: E/AndroidRuntime(2564):     at android.widget.ArrayAdapter.createViewFromResource(ArrayAdapter.java:394)
04-06 18:43:19.686: E/AndroidRuntime(2564):     at android.widget.ArrayAdapter.getView(ArrayAdapter.java:362)
04-06 18:43:19.686: E/AndroidRuntime(2564):     at android.widget.AbsListView.obtainView(AbsListView.java:2033)
04-06 18:43:19.686: E/AndroidRuntime(2564):     at android.widget.ListView.measureHeightOfChildren(ListView.java:1244)
04-06 18:43:19.686: E/AndroidRuntime(2564):     at android.widget.ListView.onMeasure(ListView.java:1155)
04-06 18:43:19.686: E/AndroidRuntime(2564):     at android.view.View.measure(View.java:12723)
04-06 18:43:19.686: E/AndroidRuntime(2564):     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4698)
04-06 18:43:19.686: E/AndroidRuntime(2564):     at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1369)
04-06 18:43:19.686: E/AndroidRuntime(2564):     at android.widget.LinearLayout.measureVertical(LinearLayout.java:660)
04-06 18:43:19.686: E/AndroidRuntime(2564):     at android.widget.LinearLayout.onMeasure(LinearLayout.java:553)
04-06 18:43:19.686: E/AndroidRuntime(2564):     at android.view.View.measure(View.java:12723)
04-06 18:43:19.686: E/AndroidRuntime(2564):     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4698)
04-06 18:43:19.686: E/AndroidRuntime(2564):     at android.widget.FrameLayout.onMeasure(FrameLayout.java:293)
04-06 18:43:19.686: E/AndroidRuntime(2564):     at android.view.View.measure(View.java:12723)
04-06 18:43:19.686: E/AndroidRuntime(2564):     at android.widget.LinearLayout.measureVertical(LinearLayout.java:812)
04-06 18:43:19.686: E/AndroidRuntime(2564):     at android.widget.LinearLayout.onMeasure(LinearLayout.java:553)
04-06 18:43:19.686: E/AndroidRuntime(2564):     at android.view.View.measure(View.java:12723)
04-06 18:43:19.686: E/AndroidRuntime(2564):     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4698)
04-06 18:43:19.686: E/AndroidRuntime(2564):     at android.widget.FrameLayout.onMeasure(FrameLayout.java:293)
04-06 18:43:19.686: E/AndroidRuntime(2564):     at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2092)
04-06 18:43:19.686: E/AndroidRuntime(2564):     at android.view.View.measure(View.java:12723)
04-06 18:43:19.686: E/AndroidRuntime(2564):     at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1064)
04-06 18:43:19.686: E/AndroidRuntime(2564):     at android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2442)
04-06 18:43:19.686: E/AndroidRuntime(2564):     at android.os.Handler.dispatchMessage(Handler.java:99)
04-06 18:43:19.686: E/AndroidRuntime(2564):     at android.os.Looper.loop(Looper.java:137)
04-06 18:43:19.686: E/AndroidRuntime(2564):     at android.app.ActivityThread.main(ActivityThread.java:4424)
04-06 18:43:19.686: E/AndroidRuntime(2564):     at java.lang.reflect.Method.invokeNative(Native Method)
04-06 18:43:19.686: E/AndroidRuntime(2564):     at java.lang.reflect.Method.invoke(Method.java:511)
04-06 18:43:19.686: E/AndroidRuntime(2564):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
04-06 18:43:19.686: E/AndroidRuntime(2564):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
04-06 18:43:19.686: E/AndroidRuntime(2564):     at dalvik.system.NativeStart.main(Native Method)

and here is how the beginning of the Activity looks like:

public class MyQuestionsActivity extends ListActivity
{
    ArrayAdapter<Question> adapter;     

    ArrayList<Question> questions = new ArrayList <Question>( );        

    @Override
    public void onCreate(Bundle savedInstanceState) 
    {   
        super.onCreate(savedInstanceState);
        setContentView(R.layout.users_questions);

        // Make sure the user is logged in
        SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences( MyQuestionsActivity.this);
        final String user_id = prefs.getString( "user_id" , null );     

        // If the user is not logged in, send them to log in
        if ( user_id == null )
        {
            sendEmail("My Questions Error", "User id is empty but they chose the my-questions button. They should be logged in before they see this button. Here is their user_id: " + user_id );       

            Intent loginIntent = new Intent( MyQuestionsActivity.this, LoginActivity.class);
            MyQuestionsActivity.this.startActivity(loginIntent);            
        }          

        final TextView question_label = (TextView) findViewById(R.id.question_label);

        Question q = new Question ();
        q.setQuestion( "" );

        questions.add(q);       

        adapter = new ArrayAdapter<Question>(this, R.layout.user_question_list, 
                R.id.label,  questions);

        setListAdapter ( adapter );

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

Here are the fields for the Question class:

public String questionId;
public String question;
public ArrayList <QuestionComment>  questionComments;
public String questionByMemberId;
public String authorName;

Thanks!!

  • 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-01T12:16:35+00:00Added an answer on June 1, 2026 at 12:16 pm

    Just try this,

    adapter = new ArrayAdapter<Question>(this, R.layout.user_question_list, questions);
    

    And let me know what happen..

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

Sidebar

Related Questions

I have an activity which extends ListActivity. It has many things but amongst them
I've got a Question. I have a ListActivity in which i can't access over
I have a ListActivity in which i have used a SimpleAdapter to create a
I have two ListActivity classes that I want to pass into into a third
I have a main class which extends Activity which should spawn a ListActivity and
I have a customized TabView which displays a ListActivity , but everytime I click
I have a Contact Activity which is derived from ListActivity, which displays list of
I have the below code which is suppose to show a list of contact
I have a ListActivity which I want to show when the phone's orientation is
I have a ListView that has some minor visual preferences that are set in

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.