Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Android Android Lists and Adapters (2015) Using Parcelable Data Retrieving Parcelable Data

Scott Laughlin
Scott Laughlin
22,402 Points

It seems I get an error when I call setListAdapter(adapter); Any Ideas?

Any idea what could be going wrong here? When I press the 7 DAY button, it crashes with the message "Unfortunately, Stormy has stopped." Here is the LogCat dump:

03-19 03:32:32.549 8962-8962/com.inspirationindustry.stormy E/AndroidRuntime﹕ FATAL EXCEPTION: main java.lang.RuntimeException: Unable to start activity ComponentInfo{com.inspirationindustry.stormy/com.inspirationindustry.stormy.ui.DailyForecastActivity}: java.lang.IllegalArgumentException: Can't have a viewTypeCount < 1 at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230) at android.app.ActivityThread.access$600(ActivityThread.java:141) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:137) at android.app.ActivityThread.main(ActivityThread.java:5041) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:511) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560) at dalvik.system.NativeStart.main(Native Method) Caused by: java.lang.IllegalArgumentException: Can't have a viewTypeCount < 1 at android.widget.AbsListView$RecycleBin.setViewTypeCount(AbsListView.java:6170) at android.widget.ListView.setAdapter(ListView.java:468) at android.app.ListActivity.setListAdapter(ListActivity.java:265) at com.inspirationindustry.stormy.ui.DailyForecastActivity.onCreate(DailyForecastActivity.java:31) at android.app.Activity.performCreate(Activity.java:5104) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)             at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)             at android.app.ActivityThread.access$600(ActivityThread.java:141)             at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)             at android.os.Handler.dispatchMessage(Handler.java:99)             at android.os.Looper.loop(Looper.java:137)             at android.app.ActivityThread.main(ActivityThread.java:5041)             at java.lang.reflect.Method.invokeNative(Native Method)             at java.lang.reflect.Method.invoke(Method.java:511)             at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)             at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)             at dalvik.system.NativeStart.main(Native Method)

It looks like it may be the same issue here: http://stackoverflow.com/questions/24854861/java-lang-illegalargumentexception-cant-have-a-viewtypecount-1

If not, can you post your adapter code?

2 Answers

Scott Laughlin
Scott Laughlin
22,402 Points

It turns out that I was returning the wrong object in my adapter code. Fixed it thanks!

Ian Z
Ian Z
14,584 Points

im having this same problem, your saying you returned the wrong object from DayAdapter.java? mine returns convertView just like Bens, what does yous return?

Ian Z
Ian Z
14,584 Points

i had same problem but the solution was in daily_list_item.xml needed to make android:id="@+id/TemperatureLabel" be android:id="@+id/temperatureLabel"