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

  • Home
  • SEARCH
  • 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 6711349
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T08:07:45+00:00 2026-05-26T08:07:45+00:00

I am getting IllegalArgumentException: Can’t have a viewTypeCount < 1 for my listview some

  • 0

I am getting

IllegalArgumentException: Can’t have a viewTypeCount < 1

for my listview some times. I know it is for the list.size(). But this does not happen frequently, only some times I get this error and application crashes. I din’t get the solution for this yet, do any body know this?

Update: This is what I am getting

10-17 05:34:49.103: ERROR/AndroidRuntime(1683): FATAL EXCEPTION: main
10-17 05:34:49.103: ERROR/AndroidRuntime(1683): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.racontrs/com.racontrs.Racontours.City}: java.lang.IllegalArgumentException: Can't have a viewTypeCount < 1
10-17 05:34:49.103: ERROR/AndroidRuntime(1683):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
10-17 05:34:49.103: ERROR/AndroidRuntime(1683):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
10-17 05:34:49.103: ERROR/AndroidRuntime(1683):     at android.app.ActivityThread.access$1500(ActivityThread.java:117)
10-17 05:34:49.103: ERROR/AndroidRuntime(1683):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
10-17 05:34:49.103: ERROR/AndroidRuntime(1683):     at android.os.Handler.dispatchMessage(Handler.java:99)
10-17 05:34:49.103: ERROR/AndroidRuntime(1683):     at android.os.Looper.loop(Looper.java:130)
10-17 05:34:49.103: ERROR/AndroidRuntime(1683):     at android.app.ActivityThread.main(ActivityThread.java:3683)
10-17 05:34:49.103: ERROR/AndroidRuntime(1683):     at java.lang.reflect.Method.invokeNative(Native Method)
10-17 05:34:49.103: ERROR/AndroidRuntime(1683):     at java.lang.reflect.Method.invoke(Method.java:507)
10-17 05:34:49.103: ERROR/AndroidRuntime(1683):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
10-17 05:34:49.103: ERROR/AndroidRuntime(1683):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
10-17 05:34:49.103: ERROR/AndroidRuntime(1683):     at dalvik.system.NativeStart.main(Native Method)
10-17 05:34:49.103: ERROR/AndroidRuntime(1683): Caused by: java.lang.IllegalArgumentException: Can't have a viewTypeCount < 1
10-17 05:34:49.103: ERROR/AndroidRuntime(1683):     at android.widget.AbsListView$RecycleBin.setViewTypeCount(AbsListView.java:4387)
10-17 05:34:49.103: ERROR/AndroidRuntime(1683):     at android.widget.ListView.setAdapter(ListView.java:460)
10-17 05:34:49.103: ERROR/AndroidRuntime(1683):     at com.racontrs.Racontours.City.onCreate(City.java:66)
10-17 05:34:49.103: ERROR/AndroidRuntime(1683):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
10-17 05:34:49.103: ERROR/AndroidRuntime(1683):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
10-17 05:34:49.103: ERROR/AndroidRuntime(1683):  
   ... 11 more

And for this line I am getting

objTourListAdapter = new TourListAdapter(tourList, this);

listView.setAdapter(objTourListAdapter); // getting this when I try to add the adapter

Inside TourListAdapter,

public class TourListAdapter extends BaseAdapter {

    protected static final Context TourListAdapter = null;

    private ArrayList<Tour> tourList;

    private OnClickListener clickListener;
    private LayoutInflater mInflater;
    ViewHolder holder;
    City city;

    public TourListAdapter(ArrayList<Tour> tourList, City city) {
        this.city = city;
        this.tourList = tourList;
        mInflater = LayoutInflater.from(city);
        clickListener = (OnClickListener) city;
    }

    @Override
    public int getViewTypeCount() {
        return tourList.size();
    }

    @Override
    public int getItemViewType(int position) {
        return position;
    }

    @Override
    public int getCount() {
        return this.tourList.size();
    }

    @Override
    public Object getItem(int position) {
        return this.tourList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            convertView = mInflater.inflate(R.layout.listbox, null);
            convertView.setOnClickListener(clickListener);

            holder = new ViewHolder();
            holder.view1 = (TextView) convertView.findViewById(R.id.listText);
            holder.desc = (TextView) convertView.findViewById(R.id.editText1);
            holder.index = (TextView) convertView.findViewById(R.id.index);
            holder.desc.setVisibility(View.GONE);
            holder.priceBtn = (Button) convertView.findViewById(R.id.prcBtn);
            holder.icon = (ImageView) convertView.findViewById(R.id.listIcon);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        holder.view1.setText((String) tourList.get(position).getObjtourName());
        holder.desc.setText((String) tourList.get(position).getDescription());

        holder.priceBtn.setText((String) tourList.get(position).getObjPrice());
        holder.priceBtn.setOnClickListener(clickListener);

        holder.index.setText(String.valueOf(position));

        holder.icon.setImageBitmap(BitmapFactory
                .decodeFile((RaconTours.PATH + RaconTours.city + File.separator
                        + tourList.get(position).getObjtourName()
                        + File.separator + tourList.get(position)
                        .getThumbnailImageName()).replace(" ", "_")));

        return convertView;
    }
}

This is my activity onCreate code

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.city);
    Bundle bundle = getIntent().getExtras();
    tourList = (ArrayList<Tour>) bundle.get("arrayTour");
    citytextView = (TextView) findViewById(R.id.tourcity);
    ImageButton btnBack = (ImageButton) findViewById(R.id.btnBack);
    btnBack.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            setResult(RESULT_OK);
            finish();
        }
    });
    btnMap = (ImageButton) findViewById(R.id.btnMap);
    btnMap.setOnClickListener(this);
    btnUt = (ImageButton) findViewById(R.id.utBtn);
    btnUt.setOnClickListener(this);
    // setting the City Name
    citytextView.setText(RaconTours.city);
    /**** Identifying a listView ****/
    ListView listView = (ListView) findViewById(R.id.tourList);
    /**** Creating a new List Adapter class for binding the values ****/
    objTourListAdapter = new TourListAdapter(tourList, this);
    listView.setAdapter(objTourListAdapter);
    listView.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
    metrics = getResources().getDisplayMetrics();
    float dpForIcon = 60f;
    heightIcon = (int) (metrics.density * dpForIcon + 0.5f);
    if (null != RaconTours.dialog) {
        RaconTours.dialog.dismiss();
    }
}
  • 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-26T08:07:46+00:00Added an answer on May 26, 2026 at 8:07 am

    So I am not sure what you want to do, but understand that getViewTypeCount() is only called once when you call setAdapter on the list view. So if the list is null or empty at that point, your application will fail. The value returned here should be thought of as more of a constant.

    ViewTypes are used in View Recycling. Basically by specifying it as the length of the list, you are saying that every entity in the list would not be able to reuse any other view that the others in the list have used. If this is really true then this behavior is fine, but the minimum value has to at all times be 1. Also this cannot change after calling setAdapter until you create a new adapter to be set on the list view with the new content (this is just hot the view recycler in lister adapter works).

    I would assume you could get by with a viewtypeCount of 1 since all your objects are of the same type. So just don’t override getItemViewType or getItemViewCount(). These default to 0 and 1 respectively which will suffice for the adapter code you posted and still make efficient use of the view recycler.

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

Sidebar

Related Questions

I'm getting an IllegalArgumentException , but I can't figure out why. The function I'm
new Date(05-MAY-09 03.55.50) is any thing wrong with this ? i am getting illegalArgumentException
I'm doing some simple HTTP authentication and am getting a java.lang.IllegalArgumentException: Illegal character(s) in
I have a problem that I am getting IllegalArgumentException while reading a video file
I have inherited some code and am getting an error when I try to
Ok, I'm getting an IllegalArgumentException at a point where it shouldn't. I have a
Getting started with NHibernate How can I generate identity fields in nHibernate using Hilo
Getting this error: 2009-09-03 12:44:02.307 xcodebuild[307:10b] warning: compiler 'com.apple.compilers.llvm.clang.1_0.analyzer' is based on missing compiler
Getting a rendering error for this form: 'NoneType' object has no attribute 'widget' http://dpaste.com/88585/
Getting this error with jquery & jquery.form. Site has been live for awhile..upgraded 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.