i have been trying to a cards game with java but some how it keeps falling. this game an odd number of players and each of them has a queue of cards the first player that is card queue is empty wins. every time i compile it keep giving me java.lang.NullPointerException error. thank you for helping.  package cardgame; import unit4.collectionsLib.Queue;//importing the queue  public class Main {  public static boolean checkIsEmpty(Queue&lt;Player&gt; p){     boolean is=false;     p.insert(null);     while(p.head()!=null){         if(p.head().getC().isEmpty()){             is=false;             p.insert(p.remove());         }     }     p.remove();     return is; } public static int whoWin(Queue&lt;Player&gt; p){  p.insert(null);  while(p.head()!=null){      if(p.head().getC().isEmpty()){          return p.head().getIndex();      }  }  return 0; }  public static void main(String[] args) {   Queue&lt;Player&gt; players = new Queue(); //queue of players    for(int i=0;i&lt;5;i++){   players.insert(new Player());   }    boolean isOver=false;    while(!isOver)       //the game is over when one player finished his cards   {       Player p = players.remove();       if(p.getC().head().greater(players.head().getC().head())==1){           p.getC().remove();           players.insert(p);           players.insert(players.remove());        }       else if(p.getC().head().greater(players.head().getC().head())==2){         players.head().getC().remove();         players.insert(p);         players.insert(players.remove());         }       else{         players.head().getC().remove();         p.getC().remove();         players.insert(p);         players.insert(players.remove());        }       if(checkIsEmpty(players)){         isOver=true;           System.out.println("the winner in this game is player number :"+whoWin(players));       }      }    }    }         package cardgame; import unit4.collectionsLib.Queue;   public class Player {  static int autonum=1; private Queue&lt;Card&gt; c; private int index;  public Player() { for(int i=0;i&lt;7;i++){ c.insert(new Card());} this.index=autonum; autonum++;  }  /**  * @return the c  */ public Queue&lt;Card&gt; getC() {     return c; }  /**  * @param c the c to set  */ public void setC(Queue&lt;Card&gt; c) {     this.c = c; }  public int getIndex(){     return this.index; }  }     package cardgame; import java.util.Random;  public class Card { private int num ;  private int shape;  public Card() { Random r = new Random(); this.num = r.nextInt(9)+1; this.shape = r.nextInt(4)+1; }  public int greater(Card c){  if(c.getNum()&lt;this.num)      return 1;  else {      if(c.getNum()&gt;this.num){          return 2;       }      else{          if(c.getShape()&gt;c.shape){              return 2;          }          else{              if(c.getShape()&lt;c.shape){                  return 1;              }              else{                  return 0;              }                 }         }         }  }  /**  * @return the num  */ public int getNum() {     return num; }  /**  * @param num the num to set  */ public void setNum(int num) {     this.num = num; }  /**  * @return the shape  */ public int getShape() {     return shape; }  /**  * @param shape the shape to set  */ public void setShape(int shape) {     this.shape = shape; }  }
129
What are Null Pointer Exceptions (java.lang.NullPointerException) and what causes them?  What methods/tools can be used to determine the cause so that you stop the exception from causing the program to terminate prematurely?
61801
I'm new to Ubuntu, using 18.04 and trying to install Netbeans or Eclipse but neither of them works.  At first my java was version 10. Searching for solutions I found many suggestions to install version 8 so I installed that and changed my default java to 8, but I'm getting new errors.  Here is the error of eclipse which is in its configuration folder (after running eclipse from terminal, eclipse guided me there to see the error):  !SESSION Sat Jun 09 15:21:19 CEST 2018 ----------------------------------------- !ENTRY org.eclipse.equinox.launcher 4 0 2018-06-09 15:21:19.382 !MESSAGE Exception launching the Eclipse Platform: !STACK java.lang.ClassNotFoundException: org.eclipse.core.runtime.adaptor.EclipseStarter     at java.net.URLClassLoader.findClass(URLClassLoader.java:381)     at java.lang.ClassLoader.loadClass(ClassLoader.java:424)     at java.lang.ClassLoader.loadClass(ClassLoader.java:357)     at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:626)     at org.eclipse.equinox.launcher.Main.basicRun(Main.java:584)     at org.eclipse.equinox.launcher.Main.run(Main.java:1438)     at org.eclipse.equinox.launcher.Main.main(Main.java:1414)   Netbeans doesn't even give error messages - it just can't load.  Again I searched to see what is wrong it seems these applications even need older versions of java but I can't find any older version. (java doesn't support them)  Can someone please help?
7576
I have a lookup to a custom object called Project on my Opportunity object. I am trying to write a trigger that updates an Active, Awarded, and Title on the Project object whenever the Active, Awarded, or Title field is updated on Opportunity based some on more logic that isn't in my code below. This is my first trigger and needing a little help due to a NullPointerException where I try to set Project__r.Active__c = true. Any thoughts?      trigger ProjectFieldsTrigger on Opportunity (before insert, before update) {       //List&lt;Opportunity&gt; opp = [SELECT Name, Active__c, Funded__c, Title__c, Project__r.Name, Project__r.Active__c, Project__r.Awarded__c      //  FROM Opportunity WHERE Id IN :Trigger.New];      for(Opportunity o: Trigger.New){          if(o.Project__c != null){              if(o.Active__c == 'Y'){                 o.Project__r.Active__c = true;             }      }  }
68403
I have this controller but I am getting this error      System.QueryException: List has no rows for assignment to SObject   public class MyController {     private final Account account;      public MyController() {         account = [SELECT Id, Name, Site FROM Account                     WHERE Id = :ApexPages.currentPage().getParameters().get('id')];             }      public Account getAccount() {         return account;     }      public PageReference save() {         update account;         return null;     } }
8434
I have a very simple problem.  Lets assume that I have a well shuffled deck of 52 cards. I start drawing the top card always and when the card matches its rank I lose. J=11 Q=12 K=13.  If there were only 13 cards I could easily use the $\ \frac{!n}{n!}$ for derangements in order to solve this. The problem is that there are 52 cards so when I pass 13 I start from 1 again so I don't know what is the probability to win. Example of the game     1st card: 4 - Continue   2nd Card: A - continue   3rd Card: K - Continue   4th Card: K - Continue   5th Card: 6 - Continue   6th Card: 9 - Continue   7th Card: 10 - Continue   8th Card: A - Continue   9th Card: J - Continue   10th Card: 3 - Continue   11th Card: 2 - Continue   12th Card: 8 - Continue   13th Card: A - Continue   1st card: 5 - Continue   2nd Card 2 LOSE   So actually I have to count from 1 to 13 4 times and if I draw all 52 cards then I win. What's the probability?
78122
Please take a look on the following pseudo-code:  boolean blocked[2]; int turn; void P(int id) {       while(true) {              blocked[id] = true;              while(turn != id) {                     while(blocked[1-id])                     /* do nothing */;                     turn = id;              }              /* critical section */              blocked[id] = false;              /* remainder */       } } void main() {       blocked[0] = false;       blocked[1] = false;       turn = 0;       parbegin(P(0), P(1)); //RUN P0 and P1 parallel }   I thought that a could implement a simple Mutual - Exclution solution using the code above. But it's not working. Has anyone got an idea why?  Any help would really be appreciated!
112025
I am trying to spawn one gameobject from a list of gameobjects each time I touch the trigger with the controller.  But when I do this, all the game objects from the list spawn together at the same time. I couldn't figure out how to solve this problem and make them spawn one at a time instead, where the next touch spawns the next object in the list, and so on.    using System.Collections; using System.Collections.Generic; using UnityEngine;  public class Trigger : MonoBehaviour {      public Transform spawnPoint;     //public GameObject Prefab;     public List&lt;GameObject&gt; items = new List&lt;GameObject&gt;();      void OnTriggerEnter(Collider other)     {         //GameObject Prefab = new GameObject("prefab");          for (int i = 0; i &lt; items.Count; i++)         {             Instantiate(items[i], spawnPoint.position, spawnPoint.rotation);             Debug.Log("Hello World" +i);         }      }  }
52560
I am getting "Error System.QueryException: List has no rows for assignment to SObject".   Line 1: Account ac = [select id from Account where name='testaccount' limit 1] Line 2: if(ac != null) {           //do something         }   I got the above error in line 2 if there is no record.   Any help?
68208
Based on   I am building a card-game where cards can have side-effects be triggered under different circumstances.  I was given a good idea on how to handle different phases by having hooks (events) that different cards can be triggered to do something, like when a card is played, draw an additional card, etc.  I am not sure how I should compose all these things to work together, I have a GameState object which handles the state of the game (who's turn, player objects, timers) checking if a move is legal etc.  I am having a Card class that currently just has a type and a name getter/setters and properties. I believe the best way to store cards would be to use .JSON files, because that would let you simply write a new card.  To achieve side-effects I am thinking of having "components" that is configured through a cards JSON-file.  {     "name": "Ocean Humans",     "type": "Creature",     "components": {     } }   However, I am not sure how I should compose these JSON-files to some actually working object. How do I call these components when I invoke a hook_event (draw a card, phase begin). And make sure right components are run?
116653
I have this:  If String.IsNullOrEmpty(editTransactionRow.pay_id.ToString()) = False Then     stTransactionPaymentID = editTransactionRow.pay_id 'Check for null value End If   Now, when editTransactionRow.pay_id is Null Visual Basic throws an exception. Is there something wrong with this code?
52652
I don’t know how to handle this 3 players case, may anyone give a hand? Thanks!     When playing card game, there are 3 players playing 32 cards, each   receive 10 cards, 2 remind on the table. Overall are 4 aces and 4   kings in the game. How likely is P (E | D)? D = "The table remains 2   aces" E = "I (at least) get one king".   I guess I should have steps as follows.   P(E) = P(1King)+P(2K)+P(3K)+P(4K) P(D) = (4/32) * (4/32) = 1/256 P (E | D) = P(E) + P(D)   Equations may be used:  Counting combinations      The number of combinations of n objects taken r at a time is     nCr = n(n - 1)(n - 2) . . . (n - r + 1)/r! = n! / r!(n - r)!                 Number of favorable outcomes P(I) =     Total number of possible outcome
73226
I'm having trouble restarting a 2D game when the user presses the "New Game" button.  Structure of my game:  The game has several 'screens': Opening screen, instructions screen, main game screen, and a game-over screen.  Each screen is an instance of a class: OpeningScreen class, GameScreen class, etc.  There is a class named Main. This class has three roles.   It's the JFrame (the window) of the program. It has the main method - first class to run. It has a method that change's screens.   When the program starts, this class runs. When it first runs:   Creates a new instance of itself (it's a JFrame-type class). Creates an instance of every 'screen-class'. The constructor of each 'screen-class' takes the instance of Main as an argument: (aka: GameOverScreen gameOverScreen = new GameOver(this)). Creates a new JPanel named mainPanel, and adds it to the JFrame. Any screen to be displayed will be contained in this JPanel (The screens are also JPanel-type classes).   How the changeScreen() method works:  The signature of changeScreen() is this: changeScreen(JPanel from, JPanel to).  Whenever a screen needs to be changed, the current screen that is displayed calls this method, like so: main.changeScreen(this, main.InstructionsScreen). It removes the previous screen from mainPanel and adds the new screen to mainPanel. As said, these screens are created when the program launches.  This is the method that changes screens:   public void changeScreen(JPanel from, JPanel to){      mainPanel.remove(from);     mainPanel.add(to);      mainPanel.revalidate();     mainPanel.repaint();  }   My problem:  After a game is finished, the Game class calls the changeScreen method: main.changeScreen(this, main.GameOverScreen) .  This replaces the game screen with a game over screen. Pressing the "New Game" button in the game-over screen, calls main.changeScreen(this, main.GameScreen) .  The problem: Pressing the "New Game" button in the game-over screen, indeed displays once again the instance of the Game class. But this is the old instance, so the game is not restarted. It's already finished.  I tried to do the following changes in changeScreen():  public void changeScreen(JPanel from, JPanel to){      mainPanel.remove(from);      if(to.equals(gameScreen)){         gameScreen = null;         gameScreen = new GameScreen(this);     }     mainPanel.add(gameScreen);      mainPanel.revalidate();     mainPanel.repaint();  }   This should reset the gameScreen object. But this creates a delay of about 10 seconds when pressing the "New Game" button.  What would be a good way of restarting the game?  Thank you
110516
I am trying to perform two operations. First I want to increase the size of a GameObject and then delay for 0.1s before returning it back to its original size. However, when I try using StartCoroutine(), it keeps giving me the error :  An object reference is required to access not-static members   even though I made my Delay() function static. Can somebody please tell me what I'm doing wrong?  public static void MoveSelected(int choice) {     GameObject rock1 = GameObject.Find("Rock1");     GameObject paper1 = GameObject.Find("Paper1");     GameObject scissors1 = GameObject.Find("Scissors1");      Vector3 scl;      if (choice == 1)     {         scl = rock1.transform.localScale;         scl.x *= 1.1f;         scl.y *= 1.1f;         rock1.transform.localScale = scl;          StartCoroutine(Delay());          scl.x /= 1.1f;         scl.y /= 1.1f;         rock1.transform.localScale = scl;     }     else if (choice == 2)     {         scl = paper1.transform.localScale;         scl.x *= 1.1f;         scl.y *= 1.1f;         paper1.transform.localScale = scl;          StartCoroutine(Delay());          scl.x /= 1.1f;         scl.y /= 1.1f;         rock1.transform.localScale = scl;     }     else if (choice == 3)     {         scl = scissors1.transform.localScale;         scl.x *= 1.1f;         scl.y *= 1.1f;         scissors1.transform.localScale = scl;          StartCoroutine(Delay());          scl.x /= 1.1f;         scl.y /= 1.1f;         rock1.transform.localScale = scl;     }  }  static IEnumerator Delay() {     yield return new WaitForSeconds(0.1f); }
31499
Does assigning an unused object reference to null in Java improve the garbage collection process in any measurable way?  My experience with Java (and C#) has taught me that is often counter intuitive to try and outsmart the virtual machine or JIT compiler, but I've seen co-workers use this method and I am curious if this is a good practice to pick up or one of those voodoo programming superstitions?
120685
It seems to me that a lot of my debugging time is spent chasing down null-reference exceptions in complex statements. For instance:  For Each game As IHomeGame in _GamesToOpen.GetIterator()   Why, when I get a NullReferenceException, can I get the line number in the stack trace, but not the name of the object that equals null. In other words, why:  Object reference not set to an instance of an object.   instead of  _GamesToOpen is not set to an instance of an object.   or  Anonymous object returned by _GamesToOpen.GetIterator() is null.   or  game was set to null.   Is this strictly a design choice, meant to protect the anonymity of the code or is there a compelling reason in compiler design not to include this information in the debug-time exception?
22087
This is a poll of sorts about common concurrency problems in Java.  An example might be the classic deadlock or race condition or perhaps EDT threading bugs in Swing.  I'm interested both in a breadth of possible issues but also in what issues are most common.  So, please leave one specific answer of a Java concurrency bug per comment and vote up if you see one you've encountered.
90357
I am trying to tidy up some really bad legacy code from an old developer and I'm trying to get rid of these nested for loops. The code below shows what I'm currently working with. I've fixed this before with nested SOQL queries but nothing like this. How would this need to look to remove these for loops (except Trigger.New)? Would I use Maps? How would I do that?  map&lt;Id,SObject&gt; mapProperyIdBudDetail = util.GetObjFields(setPropertyId, 'Property'); map&lt;Id,SObject&gt; mapSpaceIdBudDetail = util.GetObjFields( PropertyMap.keyset(), 'Space');  for ( Lease__c l: Trigger.New ) {      if(mapProperyIdBudDetail.get(PropertyMap.get(l.space__c))!=null) {          lProperties = new List&lt;SObject&gt;{mapProperyIdBudDetail.get(PropertyMap.get(l.space__c))};              for ( SObject p: lProperties ) {                  for ( String fm: FieldMap.keyset() ) {                      if ( p.get(FieldMap.get(fm)) != Null) {                         l.put(fm,p.get(FieldMap.get(fm)));                     }                  }             }     } }