Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7928703
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T19:49:08+00:00 2026-06-03T19:49:08+00:00

When running next code I get a error Exception in thread main java.lang.NullPointerException I

  • 0

When running next code I get a error “Exception in thread “main” java.lang.NullPointerException“

I think it has to do with the filling of deck[i2]
What i try to do is adding a value each time the for loop is run.

Can someone tell me what’s going wrong?

public class Deck {
    private Cards cards;
    private String[] suits;
    private String[] ranks;
    private String[] deck;
    private int i2;


    public void Deck() {
        //Instantiate class Cards
        cards = new Cards();
        //run method to get cards / suits
        suits = cards.getSuits();
        ranks = cards.getRanks();

        //Build an array (deck) and fill it with all possible cards
        i2 = 1;
        for (int i = 0; i < suits.length; i++) {

            //Run through ranks
            for (int i1 = 0; i1 < ranks.length; i1++) {
                deck[i2] = suits[i] + ranks[i1];
                2++;
            }
       }
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T19:49:10+00:00Added an answer on June 3, 2026 at 7:49 pm

    You never initialized ‘deck’. Should be something like:

    deck = new String[ranks.length * suits.length];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Running the following code, I get a StackOverflowError at the getPackage() line. How can
I am getting an exception when running the following code. Public Function getSongs() As
Im running into this error that I can't work out Im writing some code
Running the static analyzer on this piece of code: - (id) readForeignPref { CFPropertyListRef
Why is there an error in my code? I'm calling two classes in same
I am running windows 7 and I am trying to get this IDE to
Whenever a user reports an error such as System.Runtime.InteropServices.SEHException - External component has thrown
I'm running heavvy background work with Parallel.Invoke, after all processing has completed I return
I'm running some code on Mac OSX 10.6.6 and XCode 3.2.4 and I have
I'm running a program that using jai_imageio.jar and then validating if I can get

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.