Guest User

Untitled

a guest
Feb 25th, 2018
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.25 KB | None | 0 0
  1. com.example.android.javapractice E/AndroidRuntime: FATAL EXCEPTION: main
  2. Process: com.example.android.javapractice, PID: 13735
  3. java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.android.javapractice/com.example.android.javapractice.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.Window$Callback android.view.Window.getCallback()' on a null object reference
  4.  
  5. <TextView
  6. android:id="@+id/test"
  7. android:layout_width="wrap_content"
  8. android:layout_height="wrap_content"
  9. android:text="Hello World!"
  10. app:layout_constraintBottom_toBottomOf="parent"
  11. app:layout_constraintLeft_toLeftOf="parent"
  12. app:layout_constraintRight_toRightOf="parent"
  13. app:layout_constraintTop_toTopOf="parent" />
  14.  
  15. <Button
  16. android:id="@+id/turn_on"
  17. android:layout_width="wrap_content"
  18. android:layout_height="wrap_content"
  19. android:text="button"/>
  20.  
  21. package com.example.android.javapractice;
  22. import android.support.v7.app.AppCompatActivity;
  23. import android.os.Bundle;
  24. import android.view.View;
  25. import android.widget.Button;
  26. import android.widget.TextView;
  27. import java.util.Random;
  28.  
  29. public class MainActivity extends AppCompatActivity {
  30.  
  31. TextView test = findViewById(R.id.test);
  32. Button turn = findViewById(R.id.turn_on);
  33. int count = 1;
  34.  
  35. @Override
  36. protected void onCreate(Bundle savedInstanceState) {
  37. super.onCreate(savedInstanceState);
  38. setContentView(R.layout.activity_main);
  39.  
  40. turn.setOnClickListener(new View.OnClickListener() {
  41. @Override
  42. public void onClick(View view) {
  43. keepRoll();
  44. }
  45. });
  46. }
  47.  
  48. public int rollDice(){
  49. int num = 0;
  50. int roll;
  51. Random randomRoll = new Random();
  52. roll = randomRoll.nextInt(6)+1;
  53. System.out.println("Roll is: "+roll);
  54. num += roll;
  55. return num;
  56. }
  57. public void keepRoll() {
  58. int dice1 = rollDice();
  59. int dice2 = rollDice();
  60. int dice3 = rollDice();
  61. while (!(dice1 == dice2 && dice2 == dice3)){
  62. dice1 = rollDice();
  63. dice2 = rollDice();
  64. dice3 = rollDice();
  65. count += 1;
  66. }
  67. test.setText(count);
  68. }
  69. }
Add Comment
Please, Sign In to add comment