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 Build a Simple Android App (2014) Basic Android Programming Empty Strings

error on my android studio but did not put the codes

Hie am getting the errors below am not sure where this is from

Error:(55, 13) error: class, interface, or enum expected Error:(58, 5) error: class, interface, or enum expected Error:Execution failed for task ':app:compileDebugJava'.

Compilation failed; see the compiler error output for details.

2 Answers

Hi there,

I don't know what you're trying to do here, however, there's good code in there that seems to be related to the part of your code you have a problem with. This is perfect, assuming the button is called showFactButton in your xml:

Button showFactButton = (Button) findViewById(R.id.showFactButton);

However, this isn't quite correct:

    @Override
    private View findViewById(int showFactButton) {
        return null;
    }

If you can let me know what you want this to do, I can help you out.

Is this a code challenge as part of one of the tracks? If so, let me know which one and I'll try to walk you through the solution you need.

Steve.

I found the challenge and you've done it! The first line of code above is all you need to do. So just have:

Button showFactButton = (Button) findViewById(R.id.showFactButton);

in the place indicated completes the challenge. The other bit you've added can be deleted.

Hope that helps.

Steve.

Can you post the files you have written code in? I think you'll just have one, FunFactsActivity - let's have a look at the code in there.

Thanks.

Steve.

@Override
    private View findViewById(int showFactButton) {
        return null;
    }
}

Can you post the whole file, please?

Steve.

package com.example.msfuser.funfacts;

import android.app.Activity;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class FunFactsActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_fun_facts);

        // Declare our View variables and assign them views from the layout file
        final TextView factlabel = (TextView) findViewById(R.id.factTextView);
        Button showFactButton = (Button) findViewById(R.id.showFactButton);
        View.OnClickListener listener = new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                // The button was clicked, so update the fact label with a new fact
                String fact = "";
                // Randomly select a fact
                Random randomGenerator = new Random (); // Construct number generator
                int randomNumber = randomGenerator.nextInt(3);
                fact = randomNumber + "";

                // Update the label with our dynamic fact
                factlabel.setText(fact);
            }
        };
        showFactButton.setOnClickListener(listener);
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.fun_facts, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();
        if (id == R.id.action_settings) {
            return true;
        }
        return super.onOptionsItemSelected(item);
    }
}

    @Override
    private View findViewById(int showFactButton) {
        return null;
    }
}