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

Mohammad Abdur Rahman
Mohammad Abdur Rahman
1,986 Points

emulator & app not working

I have tried everything and I still can't figure it out. I don't think there is problem with the code. when I run the code, its taking too much time to launch the app then showing error : 02/17 23:17:58: Launching app Error while waiting for device: The emulator process for AVD Nexus_5_API_23 was killed.

Then i tried to run on my phone, still not working PLEASE HELP!! package com.example.mac.myapplication;

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;

public class MainActivity extends AppCompatActivity { // Declare view variables private TextView mFactTextView; private Button mFactButton; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mFactTextView = (TextView) findViewById(R.id.factTextView); mFactButton = (Button) findViewById(R.id.factButton);

    View.OnClickListener listener = new View.OnClickListener(){
        @Override
        public void onClick(View v){
            String fact = "";
            // randomly select fact
            Random randomGenerator = new Random();
            int randomNumber = randomGenerator.nextInt(3);
            fact = randomNumber +"";
            // update the screen with dynamic fact
            mFactTextView.setText(fact);
          }

    };
    mFactButton.setOnClickListener(listener);

}

}

1 Answer

Vechnet makuyana
Vechnet makuyana
3,870 Points

are all the files in the studio up to date have you updated them also try to clean your code and try to run again also you should try download and use another emulator like genymotion