sasunatu's Profile User Rating: -----

Reputation: -6 Shunned
Group:
New Members
Active Posts:
4 (0.01 per day)
Joined:
30-January 13
Profile Views:
135
Last Active:
User is offline Jan 31 2013 03:31 PM
Currently:
Offline

Previous Fields

Dream Kudos:
0
Icon   sasunatu has not set their status

Posts I've Made

  1. In Topic: card deck null pointer exception

    Posted 30 Jan 2013

    View PostGregBrannon, on 30 January 2013 - 03:40 PM, said:

    I assume that quoting yourself multiple times is your way of bumping your thread. If you've changed your code, post the updated code. There's little point in helping you with old code when you're working on a newer version with new problems.


    View Postsasunatu, on 30 January 2013 - 05:45 PM, said:

    View PostGregBrannon, on 30 January 2013 - 03:40 PM, said:

    I assume that quoting yourself multiple times is your way of bumping your thread. If you've changed your code, post the updated code. There's little point in helping you with old code when you're working on a newer version with new problems.

    The new problem I had had nothing to do with the old one. Anyway I fixed all my problens and its running great..next time u offer shiity advice why dont u try sticking it back up ur ass.
  2. In Topic: card deck null pointer exception

    Posted 30 Jan 2013

    View Postsasunatu, on 30 January 2013 - 12:01 PM, said:

    View Postsasunatu, on 30 January 2013 - 11:35 AM, said:

    OK. So I've been working on a project and cannot seem to get on why the code is giving me the following error message:

    "Exception in thread "main" java.lang.NullPointerException
    at Card.getSuit(CardDeck.java:105)
    at Card.toString(CardDeck.java:121)
    at CardDeck.shuffle(CardDeck.java:33)
    at CardDeck.<init>(CardDeck.java:16)
    at CardDeck.main(CardDeck.java:70)"

    import java.util.*;
    import java.lang.NullPointerException;
    import java.util.Random;
    
    public class CardDeck {
    
    	private Card[] deck = new Card[52];
    
    	public CardDeck() {
    		for (int i = 0; i < 13; i++) {
    			deck[i] = new Card(i + 1, "DIAMOND");
    			deck[i + 13] = new Card(i + 1, "SPADE");
    			deck[i + 26] = new Card(i + 1, "CLUB");
    			deck[i + 39] = new Card(i + 1, "HEARTS");
    		}
    		shuffle(0); //error
    		getTopCard();
    		cutDeck(0);
    
    	}
    
    	public void shuffle(int randomSeed) {
    		Card[] temp = new Card[2];
    		for (int i = 0; i < 20; i++) {
    			Random b = new Random();
    			Random a = new Random();
    			temp[0] = deck[b.nextInt(51)];
    			deck[b.nextInt(51)] = deck[a.nextInt(51)];
    			deck[a.nextInt(51)] = temp[0];
    		}
    		System.out.print("Shuffled:");
    		for (int i = 0; i < deck.length; i++) {
    			System.out.print(deck[i].toString()); //error
    			System.out.println("\n");
    		}
    	}
    
    	private Card getTopCard() {
    		return deck[0];
    	}
    
    	public void cutDeck(int location) {
    		Random cut = new Random();
    		int depth = cut.nextInt(51);
    		Card[] top = new Card[depth];
    
    		for (int i = 0; i < depth; i++) {
    			top[i] = deck[i];
    		}
    		// copy all cards after and including the pivot to
    		// the beginning of the array
    		for (int i = 0; i < (deck.length - depth); i++) {
    			deck[i]  = deck[depth + i];
    		}
    		// copy the cards from the temp array to the end of the array
    		for (int i = 0; i < depth; i++) {
    			deck[deck.length - depth + i] = top[i];
    		}
    		// return that it worked
    		System.out.println("Cut with : ");
    		System.out.println(depth);
    		for (int i = 0; i < deck.length; i++) {
    			System.out.print(deck[i].toString());
    			System.out.println("\n");
    		}
    
    	}
    
    	public static void main(String args[]) {
    		CardDeck launch = new CardDeck();	//error
    	}
    }
    
    class Card {
    	private static enum Suits {
    		SPADE, CLUB, DIAMOND, HEART
    	};
    
    	private int value; // default does not make sense!
    	// public Suits suit;
    	private Suits suit;
    
    	public Card(int aValue, String aSuit) {
    		value = aValue;
    
    		aSuit = aSuit.toUpperCase();
    
    		if (aSuit.compareTo("SPADE") == 0)
    			suit = Suits.SPADE;
    		if (aSuit.compareTo("CLUB") == 0)
    			suit = Suits.CLUB;
    		if (aSuit.compareTo("DIAMOND") == 0)
    			suit = Suits.DIAMOND;
    		if (aSuit.compareTo("HEART") == 0)
    			suit = Suits.HEART;
    
    
    	} // constructor
    
    	public int getValue() {
    		return value;
    	}
    
    	public String getSuit() {
    		switch (this.suit) {   //error
    
    		case SPADE:
    			return "SPADE";
    		case CLUB:
    			return "CLUB";
    		case DIAMOND:
    			return "DIAMOND";
    		case HEART:
    			return "HEART";
    		}
    
    		return null;
    	}
    
    	public String toString() {
    		return "<" + this.getValue() + " " + this.getSuit() + ">"; //error
    	}
    }
    
    




    It works when I compile and run it however it throws the exception at the end. It does not give me any errors before I try to run it, it just states that exception. How can I get rid of it? Any help is greatly appreciated.


    OK so now it does not compile, just throws the exception. BTW when it was compiling, it did not print out all the cards in the deck.

    OK so now it does not compile, just throws the exception. BTW when it was compiling, it did not print out all the cards in the deck.
  3. In Topic: card deck null pointer exception

    Posted 30 Jan 2013

    View Postsasunatu, on 30 January 2013 - 11:35 AM, said:

    OK. So I've been working on a project and cannot seem to get on why the code is giving me the following error message:

    "Exception in thread "main" java.lang.NullPointerException
    at Card.getSuit(CardDeck.java:105)
    at Card.toString(CardDeck.java:121)
    at CardDeck.shuffle(CardDeck.java:33)
    at CardDeck.<init>(CardDeck.java:16)
    at CardDeck.main(CardDeck.java:70)"

    import java.util.*;
    import java.lang.NullPointerException;
    import java.util.Random;
    
    public class CardDeck {
    
    	private Card[] deck = new Card[52];
    
    	public CardDeck() {
    		for (int i = 0; i < 13; i++) {
    			deck[i] = new Card(i + 1, "DIAMOND");
    			deck[i + 13] = new Card(i + 1, "SPADE");
    			deck[i + 26] = new Card(i + 1, "CLUB");
    			deck[i + 39] = new Card(i + 1, "HEARTS");
    		}
    		shuffle(0); //error
    		getTopCard();
    		cutDeck(0);
    
    	}
    
    	public void shuffle(int randomSeed) {
    		Card[] temp = new Card[2];
    		for (int i = 0; i < 20; i++) {
    			Random b = new Random();
    			Random a = new Random();
    			temp[0] = deck[b.nextInt(51)];
    			deck[b.nextInt(51)] = deck[a.nextInt(51)];
    			deck[a.nextInt(51)] = temp[0];
    		}
    		System.out.print("Shuffled:");
    		for (int i = 0; i < deck.length; i++) {
    			System.out.print(deck[i].toString()); //error
    			System.out.println("\n");
    		}
    	}
    
    	private Card getTopCard() {
    		return deck[0];
    	}
    
    	public void cutDeck(int location) {
    		Random cut = new Random();
    		int depth = cut.nextInt(51);
    		Card[] top = new Card[depth];
    
    		for (int i = 0; i < depth; i++) {
    			top[i] = deck[i];
    		}
    		// copy all cards after and including the pivot to
    		// the beginning of the array
    		for (int i = 0; i < (deck.length - depth); i++) {
    			deck[i]  = deck[depth + i];
    		}
    		// copy the cards from the temp array to the end of the array
    		for (int i = 0; i < depth; i++) {
    			deck[deck.length - depth + i] = top[i];
    		}
    		// return that it worked
    		System.out.println("Cut with : ");
    		System.out.println(depth);
    		for (int i = 0; i < deck.length; i++) {
    			System.out.print(deck[i].toString());
    			System.out.println("\n");
    		}
    
    	}
    
    	public static void main(String args[]) {
    		CardDeck launch = new CardDeck();	//error
    	}
    }
    
    class Card {
    	private static enum Suits {
    		SPADE, CLUB, DIAMOND, HEART
    	};
    
    	private int value; // default does not make sense!
    	// public Suits suit;
    	private Suits suit;
    
    	public Card(int aValue, String aSuit) {
    		value = aValue;
    
    		aSuit = aSuit.toUpperCase();
    
    		if (aSuit.compareTo("SPADE") == 0)
    			suit = Suits.SPADE;
    		if (aSuit.compareTo("CLUB") == 0)
    			suit = Suits.CLUB;
    		if (aSuit.compareTo("DIAMOND") == 0)
    			suit = Suits.DIAMOND;
    		if (aSuit.compareTo("HEART") == 0)
    			suit = Suits.HEART;
    
    
    	} // constructor
    
    	public int getValue() {
    		return value;
    	}
    
    	public String getSuit() {
    		switch (this.suit) {   //error
    
    		case SPADE:
    			return "SPADE";
    		case CLUB:
    			return "CLUB";
    		case DIAMOND:
    			return "DIAMOND";
    		case HEART:
    			return "HEART";
    		}
    
    		return null;
    	}
    
    	public String toString() {
    		return "<" + this.getValue() + " " + this.getSuit() + ">"; //error
    	}
    }
    
    




    It works when I compile and run it however it throws the exception at the end. It does not give me any errors before I try to run it, it just states that exception. How can I get rid of it? Any help is greatly appreciated.


    OK so now it does not compile, just throws the exception. BTW when it was compiling, it did not print out all the cards in the deck.

    OK so now it does not compile, just throws the exception. BTW when it was compiling, it did not print out all the cards in the deck.

My Information

Member Title:
New D.I.C Head
Age:
Age Unknown
Birthday:
Birthday Unknown
Gender:

Contact Information

E-mail:
Click here to e-mail me

Friends

sasunatu hasn't added any friends yet.

Comments

sasunatu has no profile comments yet. Why not say hello?