overlord20
Gawd
- Joined
- Feb 5, 2010
- Messages
- 623
I have run into this error and can't for the life of me figure out where it is coming from.
Here is the code and the objects listed above (Path, Game, endor). Its large, forgive me.
ENDOR:
GAME:
PATH:
I don't want the answer but I do want help getting there or an complete explanation of things to check. If you need the other three objects let me know.
Help is appreciated, straight up answers aren't. CHEERS!
Enter Map Name: four.txt
Exception in thread "main" java.lang.NullPointerException
at Path.<init>(Path.java:12)
at Game.<init>(Game.java:29)
at endor.main(endor.java:19)
Here is the code and the objects listed above (Path, Game, endor). Its large, forgive me.
ENDOR:
Code:
import java.util.*;
import java.io.*;
public class endor
{
public static void main(String[] args) throws IOException
{
Scanner scan = new Scanner(System.in);
Random gen = new Random();
Scanner file;
String map;
Game play_one;
System.out.print("Enter Map Name: ");
map = scan.next();
file = new Scanner(new FileReader(map));
play_one = new Game(scan, gen, file);
file.close();
}
}
GAME:
Code:
import java.util.*;
public class Game
{
private Scanner _scan;
private Random _gen;
private Polygon[] poly;
private Path route;
// 1) call new route
// 2) fill route with route.
public Game(Scanner scan, Random gen, Scanner file)
{
int i, howmany, sides;
boolean again = true;
howmany = file.nextInt();
poly = new Polygon[howmany];
for (i = 0; i < howmany; i++)
{
sides = file.nextInt();
poly[i] = new Polygon(file, sides);
}
route = new Path(scan);
while (again == true)
{
route.randomPath(gen);
again = detect(poly, route);
}
System.out.println("Congradulations, you made it out of the"
+ " forest!");
}
public boolean detect(Polygon[] polygons, Path route)
{
int i;
for ( i = 0; i < polygons.length; i ++ )
if ( polygons[i].intersect_path(route) )
return true;
return false;
}
}
PATH:
Code:
import java.util.*;
public class Path
{
private Coord[] pathcoord;
public Line[] path;
public Path(Scanner scan)
{
pathcoord = new Coord[8];
pathcoord[0].selectCoord(scan);
pathcoord[7].selectCoord(scan);
}
public void randomPath(Random gen)
{
int i;
for (i = 1; i < 7; i++)
{
pathcoord[i] = new Coord(gen);
}
path = new Line[7];
for (i = 0; i < path.length; i++)
{
path[i] = new Line(pathcoord[i], pathcoord[i+1] );
}
}
}
I don't want the answer but I do want help getting there or an complete explanation of things to check. If you need the other three objects let me know.
Help is appreciated, straight up answers aren't. CHEERS!