8 Replies - 771 Views - Last Post: 07 June 2010 - 05:39 PM

#1 zim1985  Icon User is offline

  • Grand Inquisitor
  • member icon

Reputation: 74
  • View blog
  • Posts: 568
  • Joined: 19-February 10

Game Review

Posted 06 June 2010 - 03:26 PM

Thus far in my game things have gone off without a hitch. I have gotten tips here, but I was wondering if I could get some more input on how to make things run more efficiently within my game as I have it now.

Also, I am getting some major errors that I can fix. One is just a NullPointer, but I can't quite figure out how to fix it.

Another is my file not being found, and I am pretty sure I wrote the correct directory for the program to find it.

So if I could get some tips on my attached game, that would be much, much appreciated. Remember it's not really done yet. I just want to get this first bit running again.

Attached File(s)



Is This A Good Question/Topic? 0
  • +

Replies To: Game Review

#2 macosxnerd101  Icon User is offline

  • Self-Trained Economist
  • member icon




Reputation: 10596
  • View blog
  • Posts: 39,257
  • Joined: 27-December 08

Re: Game Review

Posted 06 June 2010 - 03:45 PM

I'm going to move this to Share Your Project.

Also, you've been around here long enough to know that "I'm getting a Null Pointer" isn't helpful to us. You need to show us your relevant code, the stack trace, and the offending line for us to be able to better help you. If you want help fixing errors, feel free to use your existing thread or open a new thread (if you feel it is appropriate) in the Java forum. If you want feedback on your game, let's use this thread in Share Your Project. :)
Was This Post Helpful? 0
  • +
  • -

#3 H3R3T1C  Icon User is offline

  • Android Expert
  • member icon

Reputation: 277
  • View blog
  • Posts: 757
  • Joined: 30-March 07

Re: Game Review

Posted 06 June 2010 - 05:14 PM

Ok well it did not work for me. Ran PokemonBananza.class and it errors out.
C:\Users\H3R3T1C\Desktop\My Folder\Downloads\PkmnGame\PokemonGame>java PokemonBa
nanza
Exception in thread "main" java.lang.NoClassDefFoundError: gameFiles/util/Stage
        at java.lang.ClassLoader.defineClass1(Native Method)
        at java.lang.ClassLoader.defineClass(ClassLoader.java:621)
        at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:12
4)
        at java.net.URLClassLoader.defineClass(URLClassLoader.java:260)
        at java.net.URLClassLoader.access$000(URLClassLoader.java:56)
        at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
        at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
Caused by: java.lang.ClassNotFoundException: gameFiles.util.Stage
        at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
        at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
        ... 12 more

I would suggest jarring everything together to make it easier.
Was This Post Helpful? 0
  • +
  • -

#4 zim1985  Icon User is offline

  • Grand Inquisitor
  • member icon

Reputation: 74
  • View blog
  • Posts: 568
  • Joined: 19-February 10

Re: Game Review

Posted 06 June 2010 - 05:53 PM

Ok, so the NullPointerException


import java.util.ArrayList;
import java.util.Random;
import java.util.Scanner;

import java.io.File;
import java.io.FileNotFoundException;

import gameFiles.actor.Pokemon;
import gameFiles.util.Stage;

public class PokemonList
{
    private ArrayList<Pokemon> pkmn = new ArrayList<Pokemon>();
    private Random ranGen = new Random();
    
    public PokemonList(Stage stage)
    {
        try
        {
            Scanner sc = new Scanner(loadFile("Pokemon.txt"));
            while(sc.hasNextLine())
            {
                pkmn.add(new Pokemon(stage, sc.next(), sc.next(), sc.nextInt(), sc.nextInt(), sc.nextBoolean()));
                sc.nextLine();
            }
        }
        catch(FileNotFoundException e)
        {
            System.out.println("File not found!");
        }
    }
    
    /**
     * Gets a random Pokemon from the available Pokemon.
     * @return A random Pokemon.
     */
    public Pokemon getPokemon()
    {
        return pkmn.get(ranGen.nextInt(pkmn.size()));
    }
    
    /**
     * Gets a specific Pokemon from the available Pokemon.
     * @param i The number Pokemon in the encapsulated list of Pokemon to be gotten.
     * @return The Pokemon in the encapsulated list as indicated by the value of the int parameter.
     */
    public Pokemon selectPokemon(int i)
    {
        return pkmn.get(i);
    }
    
    /**
     * Removes a Pokemon from the available Pokemon.
     * @param name The name of the Pokemon to be found and removed.
     */
    public void removePokemon(String name)
    {
        for(int i = 0; i < pkmn.size(); i++)
        {
            if(pkmn.get(i).getName().equalsIgnoreCase(name))
                pkmn.remove(i);
        }
    }
    
    /**
     * Encapsulated list size getter.
     * @return The length of the encapsulated list.
     */
    public int getSize()
    {
        return pkmn.size();
    }
    
    public File loadFile(String name)
    {
        return new File("resources/files/"+name);
    }
}

java.lang.NullPointerException
	at PokemonList.<init>(PokemonList.java:28)
	at PokemonBananza.<init>(PokemonBananza.java:46)
	at PokemonBananza.main(PokemonBananza.java:321)



The first one is the one I'm worried about, the last two just deal with the object not being able to compile, so it messes up the class that calls it. (I think.)

My other error is the file I'm calling not being found which, I think, has to do with where it is located in my project file, though I can't necessarily post that here, which is why I initially attached a above in my first post.

And I can't jar it up yet, it doesn't run because of these errors. (And I have yet to finish my data file, which I am doing right now.)

EDIT: I figured out the NullPointerException, but now I get these errors:
java.lang.IllegalArgumentException: n must be positive
	at java.util.Random.nextInt(Random.java:250)
	at PokemonList.getPokemon(PokemonList.java:39)
	at PokemonBananza.initWorld(PokemonBananza.java:80)
	at PokemonBananza.game(PokemonBananza.java:297)



Again, the errors here are causing errors throughout the rest of my program, I just can't figure out the first one.

This post has been edited by zim1985: 06 June 2010 - 07:57 PM

Was This Post Helpful? 0
  • +
  • -

#5 zim1985  Icon User is offline

  • Grand Inquisitor
  • member icon

Reputation: 74
  • View blog
  • Posts: 568
  • Joined: 19-February 10

Re: Game Review

Posted 07 June 2010 - 04:08 PM

I am using BlueJ per my teacher's instruction to run my game. Though I write all the code in Eclipse and just transfer it over.

He wants me to jar the game up, but when I do I get this weird folder with the project jarred along with the jar file from my +libs folder.

Help?
Was This Post Helpful? 0
  • +
  • -

#6 KYA  Icon User is offline

  • g++ jameson.cpp -o beverage
  • member icon

Reputation: 3105
  • View blog
  • Posts: 19,144
  • Joined: 14-September 07

Re: Game Review

Posted 07 June 2010 - 04:12 PM

If you intend to ask for assistance in this thread, I'll move it back to Java. This forum is for the display and subsequent discussion of projects.
Was This Post Helpful? 0
  • +
  • -

#7 zim1985  Icon User is offline

  • Grand Inquisitor
  • member icon

Reputation: 74
  • View blog
  • Posts: 568
  • Joined: 19-February 10

Re: Game Review

Posted 07 June 2010 - 04:47 PM

I never really asked for it to get moved here. I had some errors that I needed help with. I just chose not to object...
Was This Post Helpful? 0
  • +
  • -

#8 macosxnerd101  Icon User is offline

  • Self-Trained Economist
  • member icon




Reputation: 10596
  • View blog
  • Posts: 39,257
  • Joined: 27-December 08

Re: Game Review

Posted 07 June 2010 - 04:54 PM

Sorry about that. :) I wasn't sure if this thread was more for Sharing Your Project or getting help about errors since I thought you already had an open thread for help on this project.

Anyways, your problem lies at this line in your getPokemon() method. If pkmn.size() == 0, then it isn't positive, so you will get this Exception. In my opinion, better to return null if pkmn.size() == 0, as there are no elems in the List.
return pkmn.get(ranGen.nextInt(pkmn.size())); 


Was This Post Helpful? 1
  • +
  • -

#9 zim1985  Icon User is offline

  • Grand Inquisitor
  • member icon

Reputation: 74
  • View blog
  • Posts: 568
  • Joined: 19-February 10

Re: Game Review

Posted 07 June 2010 - 05:39 PM

Thanks, I got the file loaded and that fixed the problem.

Now I am having issues jarring the file. When I do, using BlueJ at least, I get a folder with 2 jar files...

I'll attach the project as I have it now in hopes that someone can assist me.

Attached File(s)

  • Attached File  GAME.zip (1.23MB)
    Number of downloads: 99

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1