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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T18:45:03+00:00 2026-06-15T18:45:03+00:00

Hi there stackoverflow , Now I ran into another problem ,I am working on

  • 0

Hi there stackoverflow ,
Now I ran into another problem ,I am working on a ListActivity from a custom ArrayAdapter so I can fully customize my Listview to include TextViews , switches , checkboxes …. I got a NullPointerException without I know from where its originating ! Here is my current code :

public class MenuActivity extends SherlockListActivity {
    ListView scroll;
    int time;


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


        try {
            scroll = this.getListView();



            this.setListAdapter(new MyAdapter(this.getApplicationContext()));
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            finish();
        }




    }




    public View find(int x){

        return findViewById(x);

    }


    @Override
    protected void onListItemClick(ListView l, View v, int position, long id) {
        // TODO Auto-generated method stub


        super.onListItemClick(l, v, position, id);



        switch (position){
        case (0):{
            Toast.makeText(getApplicationContext(), "Hello you just chose \"Splash\"", Toast.LENGTH_SHORT).show();
        }break;
        case (1):{
            Toast.makeText(getApplicationContext(), "Its another one here !", Toast.LENGTH_SHORT).show();
        }break;
        case (2):{
            Toast.makeText(getApplicationContext(), String.valueOf(id) +" and "+ position, Toast.LENGTH_SHORT).show();

        }break;
        }


    }

    public void showToast(String toast){
        Toast.makeText(getApplicationContext(), toast, Toast.LENGTH_SHORT).show();
    }



}

class MyAdapter extends ArrayAdapter<String>{


    LayoutInflater inf = LayoutInflater.from(this.getContext());

    public MyAdapter(Context context) {
        super(context , 0 ,stringArray);
        inf.from(context);
        // TODO Auto-generated constructor stub
    }


    public static String[] stringArray= new String[]{"Splash"   , "Another Example" , "Future Checkable"};


    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        // TODO Auto-generated method stub

        if (convertView == null){
            inf.inflate(R.layout.normal_row, parent , false);
        }
        switch(position){
        case(0):
            convertView = (LinearLayout) inf.inflate(R.layout.row_switch, parent,false);

            break;
        }


        return convertView;
    }




}

And My StackTrace :

12-09 17:52:55.631: E/AndroidRuntime(11921): FATAL EXCEPTION: main
12-09 17:52:55.631: E/AndroidRuntime(11921): java.lang.NullPointerException
12-09 17:52:55.631: E/AndroidRuntime(11921):    at android.widget.AbsListView.obtainView(AbsListView.java:2161)
12-09 17:52:55.631: E/AndroidRuntime(11921):    at android.widget.ListView.makeAndAddView(ListView.java:1831)
12-09 17:52:55.631: E/AndroidRuntime(11921):    at android.widget.ListView.fillDown(ListView.java:674)
12-09 17:52:55.631: E/AndroidRuntime(11921):    at android.widget.ListView.fillFromTop(ListView.java:735)
12-09 17:52:55.631: E/AndroidRuntime(11921):    at android.widget.ListView.layoutChildren(ListView.java:1652)
12-09 17:52:55.631: E/AndroidRuntime(11921):    at android.widget.AbsListView.onLayout(AbsListView.java:1994)
12-09 17:52:55.631: E/AndroidRuntime(11921):    at android.view.View.layout(View.java:14003)
12-09 17:52:55.631: E/AndroidRuntime(11921):    at android.view.ViewGroup.layout(ViewGroup.java:4375)
12-09 17:52:55.631: E/AndroidRuntime(11921):    at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
12-09 17:52:55.631: E/AndroidRuntime(11921):    at android.view.View.layout(View.java:14003)
12-09 17:52:55.631: E/AndroidRuntime(11921):    at android.view.ViewGroup.layout(ViewGroup.java:4375)
12-09 17:52:55.631: E/AndroidRuntime(11921):    at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1663)
12-09 17:52:55.631: E/AndroidRuntime(11921):    at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1521)
12-09 17:52:55.631: E/AndroidRuntime(11921):    at android.widget.LinearLayout.onLayout(LinearLayout.java:1434)
12-09 17:52:55.631: E/AndroidRuntime(11921):    at android.view.View.layout(View.java:14003)
12-09 17:52:55.631: E/AndroidRuntime(11921):    at android.view.ViewGroup.layout(ViewGroup.java:4375)
12-09 17:52:55.631: E/AndroidRuntime(11921):    at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
12-09 17:52:55.631: E/AndroidRuntime(11921):    at android.view.View.layout(View.java:14003)
12-09 17:52:55.631: E/AndroidRuntime(11921):    at android.view.ViewGroup.layout(ViewGroup.java:4375)
12-09 17:52:55.631: E/AndroidRuntime(11921):    at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:1892)
12-09 17:52:55.631: E/AndroidRuntime(11921):    at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1711)
12-09 17:52:55.631: E/AndroidRuntime(11921):    at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:989)
12-09 17:52:55.631: E/AndroidRuntime(11921):    at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4351)
12-09 17:52:55.631: E/AndroidRuntime(11921):    at android.view.Choreographer$CallbackRecord.run(Choreographer.java:749)
12-09 17:52:55.631: E/AndroidRuntime(11921):    at android.view.Choreographer.doCallbacks(Choreographer.java:562)
12-09 17:52:55.631: E/AndroidRuntime(11921):    at android.view.Choreographer.doFrame(Choreographer.java:532)
12-09 17:52:55.631: E/AndroidRuntime(11921):    at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:735)
12-09 17:52:55.631: E/AndroidRuntime(11921):    at android.os.Handler.handleCallback(Handler.java:725)
12-09 17:52:55.631: E/AndroidRuntime(11921):    at android.os.Handler.dispatchMessage(Handler.java:92)
12-09 17:52:55.631: E/AndroidRuntime(11921):    at android.os.Looper.loop(Looper.java:137)
12-09 17:52:55.631: E/AndroidRuntime(11921):    at android.app.ActivityThread.main(ActivityThread.java:5039)
12-09 17:52:55.631: E/AndroidRuntime(11921):    at java.lang.reflect.Method.invokeNative(Native Method)
12-09 17:52:55.631: E/AndroidRuntime(11921):    at java.lang.reflect.Method.invoke(Method.java:511)
12-09 17:52:55.631: E/AndroidRuntime(11921):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
12-09 17:52:55.631: E/AndroidRuntime(11921):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
12-09 17:52:55.631: E/AndroidRuntime(11921):    at dalvik.system.NativeStart.main(Native Method)
  • 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-15T18:45:04+00:00Added an answer on June 15, 2026 at 6:45 pm

    Change this:

    if (convertView == null){
         inf.inflate(R.layout.normal_row, parent , false);
    }
    

    to:

    if (convertView == null){
         convertView = inf.inflate(R.layout.normal_row, parent , false);
    }
    

    Also, regarding having two types of rows in the ListView you should look at implementing the getViewTypeCount() and getItemViewType() methods of the adapter(as your current code will not work that well).

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

Sidebar

Related Questions

I have a simple file uploader, which thanks to stackoverflow is now fully working,
There are a lot of SQL Top N questions on stackoverflow but I can't
I recently ran into a quite complex problem and after looking around a lot
There are, as of now, 3,898 posts in StackOverflow regarding mouse click coordinates. They
I've heard now from several sources (stackoverflow.com, cocoa-dev, the documentation, blogs, etc) that it
I have searched on google and stackoverflow for this problem there are several questions
I am playing with the StackOverflow datadump. Now I have a T-SQL Problem: I
i search a lot about this question in stackoverflow..there are same problem as me
Hi there good people of StackOverflow, I have a problem and I was hoping
For stackoverflow.com there is a stat for how many views for a question. How

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.