I trying to learn LibGDX, I install all the software listed here with a new Eclipse 4.3 on a fresh formatted mac OS X Maverick.
Everything goes smooth, after a reboot, I download, and execute the gdx-setup.jar, fill the form, and import into Eclipse.
No error, no warning, when I try to run the desktop. (Right click the desktop project, Run As -> Java Application).
I got this error
Exception in thread "LWJGL Application" com.badlogic.gdx.utils.GdxRuntimeException: Couldn't load file: badlogic.jpg
at com.badlogic.gdx.graphics.Pixmap.<init>(Pixmap.java:140)
at com.badlogic.gdx.graphics.glutils.FileTextureData.prepare(FileTextureData.java:64)
at com.badlogic.gdx.graphics.Texture.load(Texture.java:130)
at com.badlogic.gdx.graphics.Texture.<init>(Texture.java:121)
at com.badlogic.gdx.graphics.Texture.<init>(Texture.java:100)
at com.badlogic.gdx.graphics.Texture.<init>(Texture.java:92)
at com.diesel.bugs.DieselBugs.create(DieselBugs.java:21)
at com.badlogic.gdx.backends.lwjgl.LwjglApplication.mainLoop(LwjglApplication.java:136)
at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:114)
Caused by: com.badlogic.gdx.utils.GdxRuntimeException: File not found: badlogic.jpg (Local)
at com.badlogic.gdx.files.FileHandle.read(FileHandle.java:134)
at com.badlogic.gdx.files.FileHandle.readBytes(FileHandle.java:218)
at com.badlogic.gdx.graphics.Pixmap.<init>(Pixmap.java:137)
I found a lot of similar issue here, I try them all without any good result... Last night I found this, very cool I have the latest Java 1.8, a mac, and Eclipse fit perfectly...
But no success, I try with Java 1.6 and 1.7, Always the same error (No file found, I kept Java 1.7)
I begin to do some debug, here my only modification of the original code generated by the importation.
package com.diesel.bugs;
import com.badlogic.gdx.ApplicationAdapter;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
public class DieselBugs extends ApplicationAdapter {
SpriteBatch batch;
Texture imgExternal,imgLocal;
#Override
public void create () {
batch = new SpriteBatch();
String pathLocal = Gdx.files.getLocalStoragePath();
String pathExternal = Gdx.files.getExternalStoragePath();
Boolean isExternal = Gdx.files.isExternalStorageAvailable();
Boolean isLocal = Gdx.files.isLocalStorageAvailable();
imgExternal = new Texture(Gdx.files.external("/Desktop/badlogic.jpg"));
imgLocal = new Texture(Gdx.files.local("badlogic.jpg"));
}
#Override
public void render () {
Gdx.gl.glClearColor(1, 0, 0, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
batch.begin();
batch.draw(imgExternal, 0, 0);
batch.end();
}
}
The weird thing is pathLocal is equal to "". Is it normal for Gdx.files.getLocalStoragePath() to return nothing (empty string)?
Also the
imgExternal = new Texture(Gdx.files.external("/Desktop/badlogic.jpg"));
Works great. only the local one gives the error, also isLocal, and isExternal return true.
And I try a lots of combinations, like /assets/data/badlogic.jpg, /assets/badlogic.jpg, /data/badlogic.jpg, data/badlogic.jpg, and badlogic.jpg.
The image badlogic.jpg is there and I put it in multiple places to be sure.
And now the reason why I'm here for help is I just try all the same step on a PC and everything works great.
What is wrong with my new mac and it's setting?
From libgdx wiki
When you run Desktop Project
The application will fail the first time. Open the Run Configuration you just created and set the working directory to the android/assets/ directory!
link your desktop project to android assets folder?
Go to Run => Run Configurations.. => choose DesktopLauncher, Arguments Tab => Working Directory => Others then browse to yourproject-android/assets/ and click Apply => Run
For those of us using Android Studio or IntelliJ IDEA, you need to follow these steps:
Select Run -> Edit Configurations from the menu
In the "Working Directory:" text box, append "/android/assets" to the path.
Note that if you execute tasks with gradle, this is not an issue. The gradle.build files are configured to use the assets folder from the android module.
Note that the previous answers will not work for users who unchecked the "Android" box on setup. There should really be a default assets folder installed for those who don't care about deploying for Android.
For those using Intellij IDEA:
Run -> Edit Configurations
On the left hand side choose: Application -> DesktopLauncher
In the "Configuration"-Tab, undert "Working directory" choose your android/assets path
This is how you fix it properly without playing around with the working directory:
The problem is that the asset folder is not correctly marked as resources directory for the gradle build. To fix this you have to add the following line in the ./core/build.gradle build file:
sourceSets.main.resources.srcDirs = [ "assets/" ]
My file after a clean setup with the recent libGDX version looks like this:
apply plugin: "java"
sourceCompatibility = 1.6
[compileJava, compileTestJava]*.options*.encoding = 'UTF-8'
sourceSets.main.java.srcDirs = [ "src/" ]
sourceSets.main.resources.srcDirs = [ "assets/" ]
eclipse.project {
name = appName + "-core"
}
I use a different solution.
Instead of creating an application run configuration, create a Gradle build configuration. The task is desktop:run. Once it is executed, the game (should) launch and stay alive without crashing, and the resources should be found.
I am not exactly sure why, but when a Gradle task is run like this, the resources are found. When an application run configuration is used (without modifications like the currently accepted answer) it crashes because it can't find the resources.
I had the same problem in IntelliJ, and I had not generated the libgdx project for Android (Android option was not marked as checked) and I was yet getting the same error. Instead of linking the working directory to "/android/assets/", linked it to "/core/assets" and it worked fine for me.
I haven't Android project. My solution is to add the asset folder to the Java Build Path->Libraries as a Class Folder. Additionally check the asset folder in Java Build Path->Order and Export to include this in other projects.
You can check the path of Assets in working Directory or linked resources .After done check for the file which you are loading .At last clean and refresh the project and enjoy.
Related
Hope you're doing well. I'm creating this simple app where you write text into a TextField and it should write it within a new JSON File in the resources folder. I'm pretty sure that my code is perfectly fine upon checking it with my professors, however, upon importing the library as seen here:
And executing the following code when the button is pushed:
*I have the following imports at the top of my JFRame class (The IDE shows no errors under those lines) :
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
Gson gson = new GsonBuilder().create(); //<-- The error always comes from this line
I get the following error which I have no idea how to fix:
I have read that switching to a Maven project is an alternative but it's not recommended for my practical. Any solutions would be greatly appreciated. I must also further note that the jar file is located in my libs folder and it is there.
Many thanks!
Edit: They asked me how my program was executed and this is what goes into the compiler in vscode (I execute it in the Run -> Run without Debugging):
c:; cd 'c:\ContentBoxFinalPrac\ContentBox'; & 'c:\Users\ytobi\.vscode\extensions\vscjava.vscode-java-debug-0.32.1\scripts\launcher.bat' 'C:\Program Files\AdoptOpenJDK\jdk-15.0.2.7-hotspot\bin\java.exe' '--enable-preview' '-XX:+ShowCodeDetailsInExceptionMessages' '-Dfile.encoding=UTF-8' '#C:\Users\ytobi\AppData\Local\Temp\cp_chdymt7vzhi9in94pnpo6ha1h.argfile' 'ui.HomeScreen'
I download gson-2.8.6.jar from Maven Repository, after adding it to referenced libraries, the code works well:
Please check if your jar misses some parts. Open command palette and choose Java: Clean Java Language Server Workspace then redownload the jar and see if question goes away.
The issue has been fixed for those still searching. I had to install this SDK which I was missing from VSCode -> Here https://dotnet.microsoft.com/download/dotnet/thank-you/sdk-5.0.202-windows-x64-installer?journey=vs-code
and just create a new project in the left hand bottom panel. Then import everything as you should and demonstrated by Molly Wang.
I recently installed Eclipse 2020-06 and am using JDK 10.0.2. I wanted to test Eclipse using a simple Hello world program:
package eclispeTest;
public class eclipseTest {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("Hello");
}
}
But I get the error: Error occurred during initialization of boot layer java.lang.module.FindException: Module eclispeTest not found
One quick fix I see for this to delete the module-info.java file but when I do this I get the error: Error: Could not find or load main class eclispeTest.eclipseTest Caused by: java.lang.ClassNotFoundException: eclispeTest.eclipseTest
I saw one potential fix that told me to go to "Check your project build-path and enable specific output folders for each folder. Go one by one though each source-folder of your project and set the output folder that maven would use."
from: Eclipse - java.lang.ClassNotFoundException
But I am new to Eclipse and have no idea what they are talking about.
I have also noticed that when I open the problems tab at the bottom of Eclipse there is one problem that is repeated about 8 times: Description Resource Path Location Type The project was not built due to "Failed to init ct.sym for C:\Program Files\Java\jre-10.0.2\lib\jrt-fs.jar". Fix the problem, then try refreshing this project and building it since it may be inconsistent eclispeTest Unknown Java Problem
Could someone help me figure out what I should try, with baby steps for how I should do it.
Thank you in advance.
PS in case it helps here is a picture of my Eclipse window after I try to run my code:
EDIT: I made a new java project and below is my java project cration window
(I still got the same error)
Fist of all, In order to work the line " System.out.println("Hello");"
you will require two classes
1)java.lang.System
2)java.io.PrintStream
using above two classes the code runs.you don't have to import these class,because JRE(Java Runtime Environment) automatically does for you.
If you are gettting this error
Error occurred during initialization of boot layer java.lang.module.FindException: Module eclispeTest not found
Which means You didn't setup your "Java project" properly with "JRE"
Let create new project to solve this problem
1)Open Eclipse IDE
2)click FILE (top left most)
3)New
4)java project
5)give you project name (make sure that- "use default location checkbox" clicked)
6)IN JRE section - select use an execution environment JRE(edition as required)
7)Then click finish
This would have solved your problem , go create a Class do your eclipseTest. This time it should work.
java project creation should look like this
I need to write a short test for some Java code. I used CTRL+SHIFT+T to generate one with IntelliJ, and selected "Groovy JUnit" as the testing library, then wrote the following test:
package util
class FibonacciHeapTest extends GroovyTestCase {
FibonacciHeap<Integer> heap
void setUp() {
super.setUp()
heap = new FibonacciHeap<>()
}
void testAddInOrder() {
testForItems 1..1000
}
private void testForItems(Range<Integer> items) {
items.each {heap << it}
assertEquals heap.size, items.to
items.each {assertEquals heap.remove(), it}
}
}
However, when I right click on the test case in the project window, I don't get the "Run All Tests" option that I normally do with JUnit tests, and the compiler throws the following error:
Information:2/4/15 8:15 PM - Compilation completed with 2 errors and 0 warnings in 2 sec
/home/patrick/IdeaProjects/hackerrank/src/test/java/util/FibonacciHeapTest.groovy
Error:(3, 1) Groovyc: unable to resolve class util.FibonacciHeap
Error:(9, 1) Groovyc: unable to resolve class GroovyTestCase
Trying to import GroovyTestCase or FibonacciHeap manually causes the same error. IntelliJ does not add any import statements when I let autocomplete finish the names for me, like it usually would with Java code.
What am I doing wrong?
This worked for me :
Open Gradle window (on right side in my case)
Click on refresh button
Done
I had a similar problem with creating test classes in IntelliJ, and it was solved when creating a new directory outside of the com.company folder (where I had the class I wanted to test).
Create a new directory for the test classes on the same level as your src folder
Right click on your new test directory, and "Mark directory as" --> "Test Resources Root"
Now create a test class, which should automatically be added to your test directory.
Build -> Rebuild project in the IDE itself (as opposed to maven, in my case) did it for me.
In my case, what I did to resolve the issue was rather simple.
Close IntelliJ
Open the attached homepage...
Remove your project by clicking on the x then...
Click on Import Project, Navigate to the build.graddle file of your project and open.
That was it and all the Red highlightings disappeared.
maybe you need add groovy-all rather then groovy,such as :
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
<version>${groovy.version}</version>
</dependency>
You have to configure Groovy SDK first. See the screenshot
More detailed description in the official document: Configuring Global, Project and Module SDKs
As #sman591 pointed out in a comment, if you are getting the error:
groovyc: unable to resolve class groovy.util.GroovyTestCase
and you already have groovy as a dependency then you are probably just missing the junit dependency.
In IntelliJ IDEA I re-imported the project. It worked then.
I closed idea. I removed .idea folder in the project. And I imported the project.
Then I needed to set up Groovy, see previous answers, mark test directory as test source in all modules of my project.
I was selecting the root folder which had build.gradle file in it, but it didn't work.
Steps followed are similar to #Pila
close the project from intellij
remove .idea, log, out folders
go to intellij dashboard
import project from existing resources
select build.gradle file <-- this is important
now you should see all the tasks are getting build in the background, and once build is finished all red lines are gone.
I have successfully create a Android project in IntelliJ 13 and I want to setup the Android Testing Framework. I used the new project wizard to create the android project using Gradle. When I go to add a new module I only have options for "Gradle: Android Module" and "Gradle: Java Library", the "Test Module" option is missing.
How do I generate an Android Test Module? I have read http://www.jetbrains.com/idea/webhelp/testing-android-applications.html but I can never find any "test" option.
If an Android Test Module can not be automatically generated, then how do I configure and use the Android Testing Framework with a Gradle Android Project? Links to examples or documentation is very much appreciated.
Details: IntelliJ 13.1.3
So currently your directory structure should look something like this:
ProjectDirectory/
res/
src/
main/
java/
your.package.name
MyClass.java
All you need to do is add a src directory for androidTest:
ProjectDirectory/
res/
src/
main/
java/
your.package.name
MyClass.java
androidTest/
java/
your.package.name
MyClassTest.java
and then resync your Gradle file with your project, and it should be detected as a test directory. Then you can run the connectedCheck or connectedAndroidTest tasks (I'm unclear on the difference in the two) to run the tests.
If your directory structure differs from the above (if, for instance, you important an Eclipse-style project), you can specify the alternate src directory in your build.gradle script:
android {
sourceSets {
androidTest {
java.srcDirs = ['path/to/test/src']
}
}
}
As an alternative You could try switching to Android Studio, Its built on top of ItelliJ. If you are creating a new project Android Studio creates the test directory automatically for you.
After a lot of tries I've found the way that's definitively good:
Create a test folder under your package.
Create a class (call it ExampleTest would be good) extending InstrumentationTestCase into this folder.
Lets add a simple test which we know will fail:
public class ExampleTest extends InstrumentationTestCase {
public void test() throws Exception {
final int expected = 1;
final int reality = 5;
assertEquals(expected, reality);
}
}
Remeber that all test methods MUST start with the “test-” prefix or Android Studio will not detect them as tests and you will get all kinds of weird errors and nothing will work.
Now that we have a test case which is doomed for failure, we must now run it.
Start by clicking “Run -> Edit Configurations.”
Now select “+ -> Android Tests” from the upper left hand corner and select “Android Tests” and name your new test configuration “test” or something equally relevant.
Select your current module and next select the “All in Package” option and navigate to your “test” folder you just created. You can also select “All in Module” and Android Studio will automatically find any test inside your whole Module! You can also get more specific and select “Class” or even “Method” option to narrow the scope of your testing down further.
Apply, close, and run this configuration! The test will run..!
Information are taken by this link:
http://rexstjohn.com/unit-testing-with-android-studio/
It's written for android studio, but it work for intelliJ 13 too! ;)
have fun!
I've had trouble with creating android projects in Intellij, so now I create projects in Eclipse and then import them into Intellij. It's annoying, but it's an easy fix and it works.
I'm trying to run JUnit4 test cases on Eclipse 3.4.2 but it's not even starting for me. I have the junit-4.7.jar in my build path and the test application.
Here is a simple example that illustrates my problem
package test;
import org.junit.Before;
import org.junit.Test;
public class UTest {
#Test
public void test() {
}
#Before
public void setUp() throws Exception {
}
}
This compiles fine
Then I do "Run JUnit Test case" from Eclipse and I get an error dialog with this message
"Launching UTest' has encountered a problem
An internal error occurred during: "Launching UTest".
java.lang.NullPointerException
What causes these NullPointerExceptions? What am I doing wrong?
What worked for me after trying everything:
Go to help
Install New Software
Work with: Juno
Programming languages (expand it)
Install Java Development Tools
Restart
It works :)
I was able to fix this just by deleting the workspace and the Eclipse directory and starting over.
This worked for me:
create another copy of the test class (CopyOfUTest.java)
run the copy to make sure it passes
go into Run > Run Configurations
under JUnit, find the run configurations for the original class and the copied class
right click and delete the configuration of the original class
rename the configuration of the copied class to the original configuration name
delete the copied class from the project
None of the given answers here worked for me, so I ended up just installing and using InfiniTest instead. It doesn't have this problem, and it also runs the tests automatically so I can focus on my work.
Have you looked in the Eclipse error log? You can see it by opening the "Error Log" view.
http://help.eclipse.org/help32/topic/org.eclipse.pde.doc.user/guide/tools/views/error_log.htm
This error In eclipse can be caused if you are also using the Android Development Kit plugins:
"Launching UTest' has encountered a problem
An internal error occurred during: "Launching UTest".
java.lang.NullPointerException
Can be caused if you are loading a normal Java project into an Eclipse instance with android ADT plugins installed and enabled. In this situation, Eclipse looks for "Android" project files, and doesn't find any. So it says: "NullPointerException".
So to fix it, re-download Eclipse without the ADT Plugin: https://www.eclipse.org/downloads/
Then re-import your project fresh. And the junit tests run without a problem.
Many people hate eclipse for it's enigmatic error messages. It's like we are back in the 1950's punch card world, where there are no error messages. The program just halts and undefined behavior occurs.
Thanks that solved my problem too.
The problem started when i removed an old simulator, and created a new one.
Fix: Like the OP says remove the workspace, make sure to keep the projects inside it :)
then import them back to eclipse
"Sound like a lot of work" ?
Took me less than half a minute !!!
If you are using Android and its associated plugins, then Android only supports JUnit 3.
I resolved the problem by selecting Test Runner as JUnit 3.
In my class, JUnit 4 is added in the build path->libraries.
Then to run the test file, go to: Run As -> Run Configurations then select the corresponding test.java file and select Test Runner accordingly(whether it is JUnit 3 or 4).
Your code works fine for me.
Eclipse
Version: 3.4.1
Build id: M20080911-1700
I right click on the .java file RunAs JUnit Test. This would indicate the problem is caused by an Eclipse configuration problem, not a code problem.
I encountered a similar problem but I am using Python. This is what I did to solve/avoid it:
Removed my .project file and the project from Eclipse.
Created the project again.
Everything was working.
The problem seemed to be in the .project file where there were some references to CDT Builder and were not there in the new .project file.