Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

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

Mateo Cuervo
Mateo Cuervo
2,511 Points

Tried solving my problem with answers from others still getting: java.lang.NullPointerException

this is my error log:

23881-23881/com.cooervo.sunnyrainy E/AndroidRuntime﹕ FATAL EXCEPTION: main java.lang.NullPointerException at android.widget.AbsListView.obtainView(AbsListView.java:2269) at android.widget.ListView.measureHeightOfChildren(ListView.java:1244) at android.widget.ListView.onMeasure(ListView.java:1156) at android.view.View.measure(View.java:15172) at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:617) at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:399) at android.view.View.measure(View.java:15172) at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4814) at android.widget.FrameLayout.onMeasure(FrameLayout.java:310) at android.view.View.measure(View.java:15172) at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4814) at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1390) at android.widget.LinearLayout.measureVertical(LinearLayout.java:681) at android.widget.LinearLayout.onMeasure(LinearLayout.java:574) at android.view.View.measure(View.java:15172) at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4814) at android.widget.FrameLayout.onMeasure(FrameLayout.java:310) at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2148) at android.view.View.measure(View.java:15172) at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:1848) at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1100) at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1273) at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:998) at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4212) at android.view.Choreographer$CallbackRecord.run(Choreographer.java:725) at android.view.Choreographer.doCallbacks(Choreographer.java:555) at android.view.Choreographer.doFrame(Choreographer.java:525) at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:711) at android.os.Handler.handleCallback(Handler.java:615) at android.os.Handler.dispatchMessage(Handler.java:92) at android.os.Looper.loop(Looper.java:137) at android.app.ActivityThread.main(ActivityThread.java:4745) 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:786) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553) at dalvik.system.NativeStart.main(Native Method)

My link for github repo: https://github.com/cooervo/sunnyrainy

please help!!!

Mateo Cuervo
Mateo Cuervo
2,511 Points

just wanted to add that this happens when pressing (7 days or Daily button in my case) button for DailyActivity

4 Answers

Jon Kussmann
PLUS
Jon Kussmann
Courses Plus Student 7,254 Points

Hi Mateo,

I'm sorry for the late reply. For some reason TeamTreehouse notifications have not been working for me the past couple of days.

I noticed in your DayAdapter class in the getView() method you are returning 'null' . Can you change that to 'convertView'. I hope this helps, if not let me know!

Mateo Cuervo
Mateo Cuervo
2,511 Points

Hey Jon thanks so much for your help and patience finally you got the bug.

This solved the problem so happy I can finally continue :D

Have a great day!!!

Jon Kussmann
PLUS
Jon Kussmann
Courses Plus Student 7,254 Points

Hi Mateo,

Could you try changing the width/height of your ListView in your activity_daily_forecast.xml to match_parent instead of wrap_content?

Let me know if this doesn't work.

Mateo Cuervo
Mateo Cuervo
2,511 Points

Hey Jon, Thanks for the help but I'm getting somewhat a similar error log to the past time:

2035-2035/com.cooervo.sunnyrainy E/AndroidRuntime﹕ FATAL EXCEPTION: main
    java.lang.NullPointerException
            at android.widget.AbsListView.obtainView(AbsListView.java:2269)
            at android.widget.ListView.makeAndAddView(ListView.java:1769)
            at android.widget.ListView.fillDown(ListView.java:672)
            at android.widget.ListView.fillFromTop(ListView.java:733)
            at android.widget.ListView.layoutChildren(ListView.java:1622)
            at android.widget.AbsListView.onLayout(AbsListView.java:2102)
            at android.view.View.layout(View.java:13754)
            at android.view.ViewGroup.layout(ViewGroup.java:4362)
            at android.widget.RelativeLayout.onLayout(RelativeLayout.java:948)
            at android.view.View.layout(View.java:13754)
            at android.view.ViewGroup.layout(ViewGroup.java:4362)
            at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
            at android.view.View.layout(View.java:13754)
            at android.view.ViewGroup.layout(ViewGroup.java:4362)
            at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1649)
            at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1507)
            at android.widget.LinearLayout.onLayout(LinearLayout.java:1420)
            at android.view.View.layout(View.java:13754)
            at android.view.ViewGroup.layout(ViewGroup.java:4362)
            at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
            at android.view.View.layout(View.java:13754)
            at android.view.ViewGroup.layout(ViewGroup.java:4362)
            at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:1866)
            at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1687)
            at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:998)
            at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4212)
            at android.view.Choreographer$CallbackRecord.run(Choreographer.java:725)
            at android.view.Choreographer.doCallbacks(Choreographer.java:555)
            at android.view.Choreographer.doFrame(Choreographer.java:525)
            at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:711)
            at android.os.Handler.handleCallback(Handler.java:615)
            at android.os.Handler.dispatchMessage(Handler.java:92)
            at android.os.Looper.loop(Looper.java:137)
            at android.app.ActivityThread.main(ActivityThread.java:4745)
            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:786)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
            at dalvik.system.NativeStart.main(Native Method)```

This is the the activity_daily_forecast.xml as you recommended me to change:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" android:paddingBottom="@dimen/activity_vertical_margin" tools:context="com.cooervo.sunnyrainy.GUI.DailyForecastActivity" android:background="#fffc970b">

<ListView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@android:id/list"
    android:layout_alignParentTop="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"/>

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@android:id/empty"
    android:layout_centerVertical="true"
    android:layout_centerHorizontal="true"
    android:text="@string/no_daily_forecast_data"
    android:textColor="#ffffff"/>

</RelativeLayout>```

Hope you might help me as I really need to finish this project very useful for employeers!

Kane Stoboi
Kane Stoboi
21,919 Points

You may need to change your onClickListener to be set on the onCreate method and then have the intent created in startDailyActivity method.

mDailyButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(MainActivity.this, DailyForecastActivity.class);
                intent.putExtra(DAILY_FORECAST, mForecast.getDailyForecast());
                startActivity(intent);

            }
        });

I don't know if this applies to anyone else, but I had implemented vectors instead of arrays previously in the project which lead to this same error when using arrays in the DailyForecastActivity class. Using arrays throughout the project solved the issue for me, although I suppose trying to implement a parcelable vector would have been a good learning experience. I just didn't want to get tripped up later in the project.

I'd also recommend downloading the project files (you can find it from the lecture page by teacher's note under downloads, and see if you can find differences between that code and yours after you have pinpointed the crash location with debugging tools.

Cheers!