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 Basic Android Programming Generating a Random Number

Nyle Cohen
Nyle Cohen
448 Points

"Fun Facts keeps stopping" error on my emulator

If I try to run the app on the emulator It will say "Fun Facts stopped" and underneath a button that sais open app again. If I try this it will say "Fun Facts keeps stopping" and a button saying close app. I don't know if this is something to do with the app or the emulator and If it will effect it if the app gets published

6 Answers

Hi Nyle,

If you find the 'LogCat' - it's usually at the bottom of the Android Studio screen when the app runs - you'll find a load of red coloured text when your app throws an error. In there, it'll give you (in a roundabout way) the reason for the issue.

Copy that in here and we can get it fixed. Maybe post your code too as there's likely to be a small issue causing the code to stop. The error log will let us know what that is.

Steve.

angel duran
angel duran
Courses Plus Student 2,098 Points

Hi Steve Hunter I am having to same problem what should I do.

Hi Angel,

Post your code and your error messages. We can go from there!

Steve.

angel duran
PLUS
angel duran
Courses Plus Student 2,098 Points
package coolfactsfun.funfacts;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import java.util.Random;

import static coolfactsfun.funfacts.R.id.showFactButton;

public class FunFactsActivity extends AppCompatActivity {
    //Declare our View veriables
    private TextView factTextView;
    private Button showFactButton;

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

        // Assign the VIew form the layout file to the corresponding variables
        factTextView = (TextView) findViewById(R.id.factTextView);
        showFactButton = (Button) findViewById(R.id.showFactButton);


        View.OnClickListener listener = new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String[]  facts = {
                        "Ants stretch when they wake up in the morning.",
                        "Ostriches can run faster than horses.",
                        "Olympic gold medals are actually made mostly of silver.",
                        "You are born with 300 bones; by the time you are an adult you will have 206.",
                        "It takes about 8 minutes for light from the Sun to reach Earth.",
                        "Some bamboo plants can grow almost a meter in just one day.",
                        "The state of Florida is bigger than England.",
                        "Some penguins can leap 2-3 meters out of the water.",
                        "On average, it takes 66 days to form a new habit.",
                        "Mammoths still walked the earth when the Great Pyramid was being built.",
                        "Tree house is not actually in a tree."};


             // The button was clicked, so update the fact TextView with a new fact
                // Randomly select a fact
                Random randomGenerator = new Random();
                int randomNumber =randomGenerator.nextInt(facts.length);
                String fact = facts[randomNumber];

                // Update the screen with our new fact
                factTextView.setText(fact);
            }
        };
        showFactButton.setOnClickListener(listener);


    }
}

This is the error code//Unexpected error while executing: am start -n "coolfactsfun.funfacts/coolfactsfun.funfacts.FunFactsActivity" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER Error while Launching activity

Is that the whole error output? There should be more explicit error messages.

angel duran
PLUS
angel duran
Courses Plus Student 2,098 Points

10/16 17:08:22: Launching app $ adb install-multiple -r C:\Users\Angel Duran\AndroidStudioProjects\FunFacts\app\build\intermediates\split-apk\debug\slices\slice_5.apk C:\Users\Angel Duran\AndroidStudioProjects\FunFacts\app\build\intermediates\split-apk\debug\slices\slice_4.apk C:\Users\Angel Duran\AndroidStudioProjects\FunFacts\app\build\intermediates\split-apk\debug\slices\slice_3.apk C:\Users\Angel Duran\AndroidStudioProjects\FunFacts\app\build\intermediates\split-apk\debug\slices\slice_6.apk C:\Users\Angel Duran\AndroidStudioProjects\FunFacts\app\build\intermediates\split-apk\debug\slices\slice_0.apk C:\Users\Angel Duran\AndroidStudioProjects\FunFacts\app\build\intermediates\split-apk\debug\slices\slice_1.apk C:\Users\Angel Duran\AndroidStudioProjects\FunFacts\app\build\intermediates\split-apk\debug\slices\slice_2.apk C:\Users\Angel Duran\AndroidStudioProjects\FunFacts\app\build\intermediates\split-apk\debug\dep\dependencies.apk C:\Users\Angel Duran\AndroidStudioProjects\FunFacts\app\build\intermediates\split-apk\debug\slices\slice_8.apk C:\Users\Angel Duran\AndroidStudioProjects\FunFacts\app\build\intermediates\split-apk\debug\slices\slice_7.apk C:\Users\Angel Duran\AndroidStudioProjects\FunFacts\app\build\intermediates\split-apk\debug\slices\slice_9.apk C:\Users\Angel Duran\AndroidStudioProjects\FunFacts\app\build\outputs\apk\app-debug.apk Split APKs installed $ adb shell am start -n "coolfactsfun.funfacts/coolfactsfun.funfacts.FunFactsActivity" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER Client not ready yet..Waiting for process to come online Connected to process 3382 on device Nexus_5X_API_25 [emulator-5554]

I only just noticed that you have an import line relating to a resource. You need to move that.

The line:

import static... showFactButton... 

Delete it for now. Let's see what that does.

Steve.

angel duran
angel duran
Courses Plus Student 2,098 Points

it didn't work can you give me your code that you use in the video

I don't have access to signed off code. I'm a moderator not staff.

What error do you get after deleting that import line. Post the Logcat again. The error should have moved.

Are you running this on a device or the emulator?

Steve.

OK - in your errors, you can filter those to do with your process, or app. Some are red - try to capture those. In the error feed you posted last, Android Studio installed the app on your emulated device and then waited for it to come online. It did that and the process connected.

At that point your copy/paste stopped but I suspect your error came after that, possibly as your main activity was launched. Try to find the red error messages and do two things. Update me on the current code you are running and paste the red errors.

Thanks,

Steve.

angel duran
PLUS
angel duran
Courses Plus Student 2,098 Points

I will send the code later on but I also wanted to know what type of coding language I would need to know to make security and data base programs.

For data security stuff, I would recommend looking at installing a partition to boot into Kali Linux. Within there, you have tools like Metasploit and NMap, to name two. The languages you need to learn within those are bash scripts and Lua.

Shout when you have your code - or post a Github repo as that's way easier!