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 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