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 (2014) Basic Android Programming Adding the onClick() Method

Fun Facts Error?

I have been stuck on this video for 2 days now, My Emulator has been working and after entering the code from the video onto FunFactsActivity.java i am no longer able to run the app?I have also gone back from scratch but i still get the same results.Every time i try and launch it says Fun Facts has stopped working?

package com.example.breyonna.funfacts;

import android.support.v7.app.ActionBarActivity;
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 ActionBarActivity {

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

        //Declare our View variables and assign them the 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 = "Ostriches can run faster than horses.";
                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();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }
}
ayush mittal
ayush mittal
112 Points

I am not able to launch Emulator, however I have followed all steps of setting it up from tutorial.

Code :

<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=".FunFactsActivity">

 <TextView
    android:text="hello world"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />

</RelativeLayout>

Error :

C:\Users\Gourav\AppData\Local\Android\sdk\tools\emulator.exe -avd Android_442 netspeed full -netdelay none emulator: ERROR: Could not initialize OpenglES emulation, use '-gpu off' to disable it. could not get wglGetExtensionsStringARB could not get wglGetExtensionsStringARB could not get wglGetExtensionsStringARB could not get wglGetExtensionsStringARB could not get wglGetExtensionsStringARB could not get wglGetExtensionsStringARB could not get wglGetExtensionsStringARB could not get wglGetExtensionsStringARB getGLES1ExtensionString: Could not find GLES 1.x config! Failed to obtain GLES 1.x extensions string! Could not initialize emulated framebuffer

Please Suggest.....

5 Answers

drizzy drake
PLUS
drizzy drake
Courses Plus Student 2,469 Points

is your id for factTextView TextView for your label in the xml e.g. android:id="@+id/FactTextView" and showFactButton for your Button id e.g. android:id="@+id/showFactButton"

yes it is?

Error:(30, 23) error: method setOnClickListener in class View cannot be applied to given types; required: OnClickListener found: no arguments reason: actual and formal argument lists differ in length

how do I fix this?

Ben Jakuben
Ben Jakuben
Treehouse Teacher

Your code looks totally fine and matches mine. Can you try cleaning and rebuilding your project? If it still gives you the error, zip up your code and post it somewhere and link it here or send it support@teamtreehouse.com and ask them to forward it to me.

Ben Jakuben
STAFF
Ben Jakuben
Treehouse Teacher

You error jumped out at me when I plugged your code into my own project and tried to run it:

Imgur

Do you get that kind of view about the error when you run it?

In this case, it can't find the ID showFactButton. That's because the ID in your layout file has a capital "S": ShowFactButton. Try switching that to lowercase and see if you can now run your app. :)

Thank You Ben, it worked!It took me 2 days and it was as simple as a lower case letter! Thanks Again.