Reputation: 3036
I'm trying run a test with JUnit 4 and Robolectric on Eclipse but all time I receive this error:
Invalid layout of java.lang.String at value
#
# A fatal error has been detected by the Java Runtime Environment:
#
# Internal Error (javaClasses.cpp:129), pid=3546, tid=140317899335424
# fatal error: Invalid layout of preloaded class
#
# JRE version: 7.0_07-b10
# Java VM: Java HotSpot(TM) 64-Bit Server VM (23.3-b01 mixed mode linux-amd64 compressed oops)
# Failed to write core dump. Core dumps have been disabled. To enable core dumping, try "ulimit -c unlimited" before starting Java again
#
My test is very easy. It's only for check all work:
@RunWith(RobolectricTestRunner.class)
public class FormatTest {
@Test
public void getFormatElapsedTimeOnSecondsTest(){
assertEquals("3seg","3seg");
}
}
Java installed on my system is:
java version "1.7.0_07"
Java(TM) SE Runtime Environment (build 1.7.0_07-b10)
Java HotSpot(TM) 64-Bit Server VM (build 23.3-b01, mixed mode)
I don't understand what happen.
Upvotes: 11
Views: 15407
Reputation: 340
Same issue encountered to me as well and reason was I added main(String s[]) method in my android project.
So just remove main(String s[]) method from project and run as Android Application.
Upvotes: 0
Reputation: 480
For me was the solution: Run -> Run Configurations... -> at tab Test click Select Preferred Launcher and select Use configuration specific settings with selection Android JUnit Test Launcher.
Delete all entries under JUnit (left column of Run Configurations dialog; RightMouse - Delete).
Then Run as -> JUnit Test and optionally select Use configuration specific settings with Android JUnit Test Launcher.
Upvotes: 3
Reputation: 176
Right click java class with main, run configurations then go to classpath tab, remove the android library there. then run.
I hope this helps.
Upvotes: 1
Reputation: 2044
It goes easier. Got to Run->Configuration and look for JUnit and Android JUnit Tests. Delete your config if it is there. Then the next time you click on Run it will ask about the configuration. You choose first JUnit and then in the next dialog activate "Use configuration specific settings" and then choose Android JUnit Test Laucher.
Upvotes: 0
Reputation: 121
You need to correct your run configuration.
If you want to run an JUnit test with
"right click on test class in the package explorer"->"Run As"->"JUnit Test"
on an android project, you need to set the "Android JUnit Test Launcher" as launcher. You have do use that android launcher even if your launch configuration has the type "JUnit".
You can find it under:
"right click on test class in the package explorer"->"Properties"->"Run/Debug Settings"->"Edit..."
Example:
Test:
import junit.framework.TestCase;
public class ExampleTest extends TestCase{
public ExampleTest(String name){
super(name);
}
protected void setUp() throws Exception{
super.setUp();
}
protected void tearDown() throws Exception{
super.tearDown();
}
public void testFoo(){
fail("Not yet implemented");
}
}
Create run configuration:
"Run"->"Run Configurations..."->"Right click on JUnit"->"New"->"Set project and Test class"->"Select Android JUnit Test Launcher"->"Run"
Notice: If you are using an x86 jdk you will get the following error if your Launcher is set to "Eclipse JUnit Launcher":
Invalid layout of java.lang.String at value
#
# A fatal error has been detected by the Java Runtime Environment:
#
# Internal Error (javaClasses.cpp:129), pid=3844, tid=4828
# fatal error: Invalid layout of preloaded class
#
# JRE version: 7.0_17-b02
# Java VM: Java HotSpot(TM) Client VM (23.7-b01 mixed mode windows-x86 )
# Failed to write core dump. Minidumps are not enabled by default on client versions of Windows
Upvotes: 12
Reputation: 311
This may not be your issue but I was able to get past this by using the Run As -> Android Application.
However, I'm not sure if you are using android or not. Possibly check the Run configuration for other issues.
Upvotes: 21