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 8957963
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T15:06:54+00:00 2026-06-15T15:06:54+00:00

I have recently been giving Java spending a good few months on C#, just

  • 0

I have recently been giving Java spending a good few months on C#, just got caught up on something I’m unsure how to format.

A little example I’ve thrown together to explain my problem.

I am trying to add a an object of type ‘Creature’ to my object of type ‘Player’

Currently like this:

                                                        //Null items are objects
Player newPlayer = new Player("This", "Is", "Here", 1 , 1, 1, null, null, null);        

Creature c = null;                                  //Null items are objects
c = new Creature("Name", "Species",  100, 5.5, 10.5, 1, 100, null, null, null);

newPlayer.addCreature(c);

However the problem I’m getting is java.lang.NullPointException.

The player class can be seen here:

public Player(String Username, String Password, String Email, int Tokens, int Level, int Experience, Vector<Creature> Creature, Vector<Food> Food, Vector<Item> Item) {
    m_username = Username;
    m_password = Password;
    m_email = Email;
    m_tokens = Tokens;
    m_level = Level;
    m_experience = Experience;
    m_creature = Creature;
    m_food = Food;
    m_item = Item;

}   

public void addCreature(Creature c)
{
    m_creature.add(c);      
}

And the creature:

public Creature(String Name, String Species, int Health, double Damage, double Regen, int Level, int Exp, Vector<Effect> ActiveEffect, Vector<Attack> Attack, Vector<Specialisation> Specialisation )
{
    m_name = Name;
    m_species = Species;
    m_health = Health;
    m_damageMultiplier = Damage;
    m_regenRate = Regen;
    m_level = Level;
    m_experience = Exp;
    m_activeEffect = ActiveEffect;      
    m_attack = Attack;
    m_specialisation = Specialisation;      

}

How do I create the instance using this?

  • 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-15T15:06:55+00:00Added an answer on June 15, 2026 at 3:06 pm

    That is because the reference to the vector that you are storing is null. You are passing nulls for the constructor.

    When you pass new vector<Creature>() you are actually passing a reference to a newly constructed vector. It doesn’t contain any creature objects as yet. Earlier it was failing because you were trying to call add(..) function on a reference that was set to null.

    Try this:

    Player newPlayer = new Player("This", "Is", "Here", 1 , 1, 1, new Vector<Creature>(), new Vector<Food>(), new Vector<Item>());
                                                                  ^ new empty vector      ^ new empty vector  ^ new empty vector
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have recently been looking for a tool to generate Java code from a
I have recently been looking into HTTPS, and just how secure it is. I
I have recently been investigating java server-side web frameworks to serve as a rendering
I have recently been working on implementing an ajax based file uploader for my
I have recently been faced with a rather odd task, one result being the
I have recently been working on a Pastebin script (for fun) and I've come
I have recently been rewriting some of my iphone app because a couple of
I have recently been assigned a CSS & design project that's in a CakePHP
I have recently been asked to estimate a piece of work which will provide
I have recently been using WxPython to create a GUI Network simulator like Cisco

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.