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 Build a Simple Android App (retired 2014) Getting Started with Android Accessing Views in Code

Accessing Views in Code - Output Error

I've emailed support, but they have redirected me to the forums with this problem. Can anyone please tell me what I am doing wrong here? Is it looking for the listener as well?

The question: It's asking me to initialize the getAnswerButton with the view button1.

My solution:

package com.example.crystal.ball;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class MainActivity extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        // Declare our view variables
        TextView answerLabel = (TextView) findViewById(R.id.textView1);     
        Button getAnswerButton = (Button) findViewById(R.id.button1);
    }
}

Error Output:

JavaTester.java:2: package android.os does not exist
import android.os.Bundle;
                 ^
./com/example/crystal/ball/MainActivity.java:3: package android.app does not exist
import android.app.Activity;
                  ^
./com/example/crystal/ball/MainActivity.java:4: package android.os does not exist
import android.os.Bundle;
                 ^
./com/example/crystal/ball/MainActivity.java:5: package android.view does not exist
import android.view.View;
                   ^
./com/example/crystal/ball/MainActivity.java:6: package android.widget does not exist
import android.widget.Button;
                     ^
./com/example/crystal/ball/MainActivity.java:7: package android.widget does not exist
import android.widget.TextView;
                     ^
./com/example/crystal/ball/MainActivity.java:9: cannot find symbol
symbol: class Activity
public class MainActivity extends Activity {
                                  ^
./com/example/crystal/ball/MainActivity.java:12: cannot find symbol
symbol  : class Bundle
location: class com.example.crystal.ball.MainActivity
    public void onCreate(Bundle savedInstanceState) {
                         ^
JavaTester.java:25: cannot find symbol
symbol  : class Bundle
location: class JavaTester
activity.onCreate(new Bundle());
                      ^
JavaTester.java:27: cannot find symbol
symbol  : variable findViewByIdCallCount
location: class com.example.crystal.ball.MainActivity
if (activity.findViewByIdCallCount < 2) {
            ^
JavaTester.java:30: cannot find symbol
symbol  : variable lastFoundViewId
location: class com.example.crystal.ball.MainActivity
else if (activity.lastFoundViewId != R.id.button1) {
                 ^
./com/example/crystal/ball/MainActivity.java:13: cannot find symbol
symbol  : variable super
location: class com.example.crystal.ball.MainActivity
        super.onCreate(savedInstanceState);
        ^
./com/example/crystal/ball/MainActivity.java:14: cannot find symbol
symbol  : method setContentView(int)
location: class com.example.crystal.ball.MainActivity
        setContentView(R.layout.activity_main);
        ^
./com/example/crystal/ball/MainActivity.java:17: cannot find symbol
symbol  : class TextView
location: class com.example.crystal.ball.MainActivity
        TextView answerLabel = (TextView) findViewById(R.id.textView1);     
        ^
./com/example/crystal/ball/MainActivity.java:17: cannot find symbol
symbol  : class TextView
location: class com.example.crystal.ball.MainActivity
        TextView answerLabel = (TextView) findViewById(R.id.textView1);     
                                ^
./com/example/crystal/ball/MainActivity.java:17: cannot find symbol
symbol  : method findViewById(int)
location: class com.example.crystal.ball.MainActivity
        TextView answerLabel = (TextView) findViewById(R.id.textView1);     
                                          ^
./com/example/crystal/ball/MainActivity.java:18: cannot find symbol
symbol  : class Button
location: class com.example.crystal.ball.MainActivity
        Button getAnswerButton = (Button) findViewById(R.id.button1);
        ^
./com/example/crystal/ball/MainActivity.java:18: cannot find symbol
symbol  : class Button
location: class com.example.crystal.ball.MainActivity
        Button getAnswerButton = (Button) findViewById(R.id.button1);
                                  ^
./com/example/crystal/ball/MainActivity.java:18: cannot find symbol
symbol  : method findViewById(int)
location: class com.example.crystal.ball.MainActivity
        Button getAnswerButton = (Button) findViewById(R.id.button1);
                                          ^
./com/example/crystal/ball/MainActivity.java:11: method does not override or implement a method from a supertype
    @Override
    ^
20 errors

2 Answers

Nathan Williams
seal-mask
.a{fill-rule:evenodd;}techdegree
Nathan Williams
Python Web Development Techdegree Student 6,851 Points

Hi Shawn,

Thanks for posting this, and sorry for any inconvenience this may have caused.

We're in the process of rolling out some improvements to our code-challenge system to provide more reliablility and faster feedback on code submissions, and we've been running the new system in tandem with the old system tonight for testing before taking it live.

It looks like some of the challenges may have been having some trouble on the new system, so we shut them down while we investigated. This issue should be fixed now, and I confirmed I was able to pass the challenge with your provided code sample.

Thanks again for bringing this to our attention, and happy coding!

Regards,

Nathan W

Erin Kabbash
Erin Kabbash
5,210 Points

I think you have an error on the first line of your package name.. try changing package com.example.crystal.ball; to package com.example.crystalball; usually the package names are com.something.nameofproject so that extra . looks suspicious. I am still learning as well but worth a try! Let me know if it helps!

Thanks for your response Erin.

Changing "com.example.crystal.ball" to package "com.example.crystalball" gives me the following error:

JavaTester.java:24: cannot access com.example.crystal.ball.MainActivity
bad class file: RegularFileObject[./com/example/crystal/ball/MainActivity.java]
file does not contain class com.example.crystal.ball.MainActivity
Please remove or make sure it appears in the correct subdirectory of the classpath.
      MainActivity activity = new MainActivity();
      ^
1 error

It looks like the correct package name may indeed be "com.example.crystal.ball".