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 Seeing It in Action

Matteo Stara
PLUS
Matteo Stara
Courses Plus Student 1,564 Points

Non-static method cannot be referenced from static context.

** From the ContentProvider course **

When implementing updateList(), the line:

LinearLayout.addView(textView);

It's going to generate an error (the one in the subject). We have never defined the LinearLayout, so it's basically saying: you can't call this method via the class, you need an instance of it (i.e. cannot use a static approach).

The way I have fixed it (and it works app-wise)

LinearLayout linearLayout = findViewById(R.id.linearLayout);
                linearLayout.addView(textView);

Hope this helps!

1 Answer

Matteo Stara
PLUS
Matteo Stara
Courses Plus Student 1,564 Points

Actually, there is no need for this line:

LinearLayout linearLayout = findViewById(R.id.linearLayout);

We have already defined

LinearLayout linearLayout;

So simply use:

linearLayout.addView(textView);

The video is correct, sorry LOL

Happens to the best of us ;)