Inferno
Inferno

Reputation: 13

ExceptionInInitializerError cause by java.lang.RuntimeException

Im trying to some of my classes with Eclipse's JUnit but I'm keeping getting the error:ExceptionInInitializerError. It also says "caused by java.lang.RuntimeException: issues with stringToMap. java.io.FileNotFoundException:TEST.FILES\ephemeral_testing_file.txt(The system cannot find the path specified) . I've never had such type of error in Eclipse, how can I fix it?

Here is the trace followed by the code of some classes:

java.lang.ExceptionInInitializerError
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
    at java.lang.reflect.Constructor.newInstance(Unknown Source)
    at org.junit.runners.BlockJUnit4ClassRunner.createTest(BlockJUnit4ClassRunner.java:195)
    at org.junit.runners.BlockJUnit4ClassRunner$1.runReflectiveCall(BlockJUnit4ClassRunner.java:244)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at org.junit.runners.BlockJUnit4ClassRunner.methodBlock(BlockJUnit4ClassRunner.java:241)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
    at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: java.lang.RuntimeException: issues with stringToMap. java.io.FileNotFoundException: TEST_FILES\ephemeral_testing_file.txt (The system cannot find the path specified)
    at P4Tests.stringToMap(P4Tests.java:329)
    at P4Tests.<clinit>(P4Tests.java:760)
    ... 23 more

import java.io.*;
import java.util.Scanner;
public class Map {

    Spot[][] floorPlan;
    Thing[] things;
    java.io.PrintStream log;

    Map(String fileName, PrintStream log) throws IOException
    {
        String line = "";
        String eachToken = "";
        int cols = 0;
        int rows = 0;
        Scanner data = new Scanner(new File(fileName));
        while(data.hasNext())
        {
            eachToken = data.next();
            if(eachToken != "|" || 
                    eachToken != "a" ||
                    eachToken != "f" || 
                    eachToken != "z" || 
                    eachToken != "g" || 
                    eachToken != "~" ||
                    eachToken != "." || 
                    eachToken != "e" ||
                    eachToken != "^" || 
                    eachToken != ">" ||
                    eachToken != "v" || 
                    eachToken != "<")
            {
                System.exit(0);
            }

            line = data.nextLine();
            cols = line.length();

            rows++;
        }
        floorPlan = new Spot[rows][cols];
        things = new Thing[cols];
        }

    public boolean onMap(Coord c)
    {
        for(int i = 0; i < floorPlan.length; i ++)
            for(int j = 0; j < floorPlan[i].length; j++)
            {
                if(i == c.r && j == c.c)
                    return true;
            }

        return false;
    }

    public Spot spotAt(Coord c)
    {

        for(int i = 0; i < floorPlan.length; i ++)
            for(int j = 0; j < floorPlan[i].length; j++)
            {
                if(i == c.r && j == c.c)
                {
                    if(floorPlan[i][j] == Spot.Open)
                        return floorPlan[i][j];
                    else if(floorPlan[i][j] == Spot.Wall)
                        return floorPlan[i][j];
                    else if(floorPlan[i][j] == Spot.Exit)
                        return floorPlan[i][j];
                    else if(floorPlan[i][j] == Spot.SignN)
                        return floorPlan[i][j];
                    else if(floorPlan[i][j] == Spot.SignE)
                        return floorPlan[i][j];
                    else if(floorPlan[i][j] == Spot.SignS)
                        return floorPlan[i][j];
                    else if(floorPlan[i][j] == Spot.SignW)
                        return floorPlan[i][j];

                }
            }

        return null;
    }

    public int peopeRemaining()
    {

        return -1;
    }

    public void addThing(Thing a)
    {
        int thingSize = things.length;
        Thing[] temp = new Thing[thingSize + 1];
        for (int i = temp.length - 1; i < temp.length; i++)
        {
            temp[i] = a; 
        }
        temp = things;

    }

    public Thing[] thingsAt(Coord c)
    {
        return ;

    }
}
import java.io.PrintStream;

public abstract class Thing implements Representable, Passable {

    private Coord loc;
    private Coord prevLoc;
    public final String repr;
    protected java.io.PrintStream log;
    protected Map map;

    public Thing(Coord c, String repr, Map map, PrintStream log)
    {
        this.loc = c;
        this.prevLoc = c;
        this.repr = repr;
        this.map = map;
        this.log = log;
    }

    public abstract void doAction();

    public Coord getLoc()
    {
        return this.loc;
    }

    public Coord getPrevLoc()
    {
        return this.prevLoc;
    }


    public void setLoc(Coord c)
    {
        this.prevLoc = c;
        this.loc = c;
    }

    @Override
    public String repr()
    {
        return repr;
    }

    @Override
    public String toString()
    {
        return "\"repr()"+"@"+"getLoc()\"";
    }   


}

Upvotes: 1

Views: 10521

Answers (1)

candied_orange
candied_orange

Reputation: 7308

Always look for the Caused by line in a stack trace. It's a bit buried but it often has something helpful to say:

Caused by: java.lang.RuntimeException: issues with stringToMap. java.io.FileNotFoundException: TEST_FILES\ephemeral_testing_file.txt (The system cannot find the path specified)

You fix a file not found error by either providing the file the code is demanding or change the code so it demands something you can give it.

If you can't give it what it wants then you need to look...

at P4Tests.stringToMap(P4Tests.java:329)

I don't see that you've posted P4Tests so all I can tell you is to look at line 329.


Update:

From your comment it sounds like your real question is what the heck called P4Tests. The problem with that is your trace ends with ... That is explained here: https://stackoverflow.com/a/1167917/1493294

That basically says that your "... 23 more" could be replaced with the 23 lines between (not including) the java.lang.ExceptionInInitializerError line and the caused by line. When you catch an exception only to wrap it in another exception you end up with two exceptions blowing up thru the same stack. It's redundant to fully trace them both so they use ... to say "and so on".

They explain it Here

Note the presence of lines containing the characters "...". These lines indicate that the remainder of the stack trace for this exception matches the indicated number of frames from the bottom of the stack trace of the exception that was caused by this exception (the "enclosing" exception). This shorthand can greatly reduce the length of the output in the common case where a wrapped exception is thrown from same method as the "causative exception" is caught.

The problem with this is when you're trying to figure out what happened what you really want is just one stack trace that shows everything in order. Some people can just look at the trace and figure it out. When I'm to tired to deal with it I just copy it to an editor and start pasting lines after the ... until I have one full trace. It lets me use the extra brain cells to work the real problem.

I'll spare you doing it to your stack simply out of length considerations but if I do it to their example it looks like this:

 Caused by: LowLevelException
         at Junk.e(Junk.java:30)
         at Junk.d(Junk.java:27)
         at Junk.c(Junk.java:21)
         ... 3 more
 Caused by: MidLevelException: LowLevelException
         at Junk.c(Junk.java:23)
         at Junk.b(Junk.java:17)
         at Junk.a(Junk.java:11)
         ... 1 more
  HighLevelException: MidLevelException: LowLevelException
         at Junk.a(Junk.java:13)
         at Junk.main(Junk.java:4)

It's not fancy but it works.

Upvotes: 3

Related Questions