I'm building a game in LibGDX and have began adding visual aspects of the game such as the logo. Considering that I've been using the default libgdxXXX.png files as placeholders for my logo, and that I'm replacing them with my logo, I didn't feel it had any more purpose in my program. I decide to delete it; but it decide to not compile and come up with this error:
Exception in thread "LWJGL Application" com.badlogic.gdx.utils.GdxRuntimeException: Couldn't load file: assets/libgdx128.png
at com.badlogic.gdx.graphics.Pixmap.<init>(Pixmap.java:148)
at com.badlogic.gdx.backends.lwjgl.LwjglGraphics.setupDisplay(LwjglGraphics.java:196)
at com.badlogic.gdx.backends.lwjgl.LwjglApplication.mainLoop(LwjglApplication.java:142)
at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:124)
Caused by: com.badlogic.gdx.utils.GdxRuntimeException: File not found: assets/libgdx128.png (Internal)
at com.badlogic.gdx.files.FileHandle.read(FileHandle.java:136)
at com.badlogic.gdx.files.FileHandle.readBytes(FileHandle.java:222)
at com.badlogic.gdx.graphics.Pixmap.<init>(Pixmap.java:145)
... 3 more
Somehow, when I return the files from the Trash (I use Linux), it works again! I have checked my code and found nothing I wrote referred to those files. When I deleted the files 1 by 1, the error changes from libgdx128.png to libgdx64.png to libgdx32.png to libgdx16.png respectively. I have changed all the references from libgdx128.png to my logo.png in my code; yet when I try to delete the libgdx logo and run my program, it fails to compile! Any ideas?
I found out my problem. I forgot all about this code at DesktopLauncher.java:
for (int size : new int[] { 128, 64, 32, 16 }) {
configuration.addIcon("assets/libgdx" + size + ".png", FileType.Internal);
}
I did not know it was referencing to the files I have deleted. The configuration.addIcon(); was the code setting the program icon - similar to how a favicon works. I will be adding my own icon now that I know what the code does.
Hope this helps anyone else confused about the error.
Related
I tried to access codes of my deleted app by apk got from emulator. I accessed classes.dex but there is a problem making it jar by dex2jar. This is really important for me, how to fix that?
The error file below:
Summary
version: reader-1.15, translator-0.0.9.15, ir-1.12
there are 2 error methods
options: -d
t0.txt
java.lang.NullPointerException
at com.googlecode.dex2jar.ir.ts.LocalSplit.transform(LocalSplit.java:255)
at com.googlecode.dex2jar.v3.V3MethodAdapter.visitEnd(V3MethodAdapter.java:215)
at com.googlecode.dex2jar.v3.V3ClassAdapter$2.visitEnd(V3ClassAdapter.java:320)
at com.googlecode.dex2jar.reader.DexFileReader.acceptMethod(DexFileReader.java:691)
at com.googlecode.dex2jar.reader.DexFileReader.acceptClass(DexFileReader.java:436)
at com.googlecode.dex2jar.reader.DexFileReader.accept(DexFileReader.java:323)
at com.googlecode.dex2jar.v3.Dex2jar.doTranslate(Dex2jar.java:85)
at com.googlecode.dex2jar.v3.Dex2jar.to(Dex2jar.java:261)
at com.googlecode.dex2jar.v3.Dex2jar.to(Dex2jar.java:252)
at com.googlecode.dex2jar.tools.Dex2jarCmd.doCommandLine(Dex2jarCmd.java:110)
at com.googlecode.dex2jar.tools.BaseCmd.doMain(BaseCmd.java:174)
at com.googlecode.dex2jar.tools.Dex2jarCmd.main(Dex2jarCmd.java:34)
DexMethodVisitor mv=cv.visitMethod(ACC_PRIVATE, new Method("Lcom/android/tools/fd/runtime/Server;","handleHotSwapPatch",new String[]{ "I","Lcom/android/tools/fd/runtime/ApplicationPatch;"},"I"));
t1.txt
java.lang.NullPointerException
at com.googlecode.dex2jar.ir.ts.LocalSplit.transform(LocalSplit.java:255)
at com.googlecode.dex2jar.v3.V3MethodAdapter.visitEnd(V3MethodAdapter.java:215)
at com.googlecode.dex2jar.v3.V3ClassAdapter$2.visitEnd(V3ClassAdapter.java:320)
at com.googlecode.dex2jar.reader.DexFileReader.acceptMethod(DexFileReader.java:691)
at com.googlecode.dex2jar.reader.DexFileReader.acceptClass(DexFileReader.java:441)
at com.googlecode.dex2jar.reader.DexFileReader.accept(DexFileReader.java:323)
at com.googlecode.dex2jar.v3.Dex2jar.doTranslate(Dex2jar.java:85)
at com.googlecode.dex2jar.v3.Dex2jar.to(Dex2jar.java:261)
at com.googlecode.dex2jar.v3.Dex2jar.to(Dex2jar.java:252)
at com.googlecode.dex2jar.tools.Dex2jarCmd.doCommandLine(Dex2jarCmd.java:110)
at com.googlecode.dex2jar.tools.BaseCmd.doMain(BaseCmd.java:174)
at com.googlecode.dex2jar.tools.Dex2jarCmd.main(Dex2jarCmd.java:34)
DexMethodVisitor mv=cv.visitMethod(ACC_PUBLIC, new Method("Landroid/support/v4/app/FragmentManagerImpl;","allocBackStackIndex",new String[]{ "Landroid/support/v4/app/BackStackRecord;"},"I"));
addition: I got the apk from installed project by pull command and it doesnt signed. Normally, I have not even seen this error with signed apks.
So I have recently started learning libgdx in Android Studio. I am using some extensions like box2d. To create some nice borders around the object, I am using Physics Body Editor. So, as there were many errors in my own code, i have just copied one from here: Code Sample. But still, I keep getting an error on the following line:
BodyEditorLoader loader = new BodyEditorLoader(Gdx.files.internal("tankA.json"));
The file tankA.json is in my assets folder.
Here is my error:
02-12 08:27:52.216 13720-13734/com.tynibattles04.game.android E/AndroidRuntime﹕ FATAL EXCEPTION: GLThread 6581
Process: com.tynibattles04.game.android, PID: 13720
com.badlogic.gdx.utils.GdxRuntimeException: Error reading file: tankA.json (Internal)
at com.badlogic.gdx.backends.android.AndroidFileHandle.read(AndroidFileHandle.java:77)
at com.badlogic.gdx.files.FileHandle.length(FileHandle.java:605)
at com.badlogic.gdx.backends.android.AndroidFileHandle.length(AndroidFileHandle.java:220)
at com.badlogic.gdx.files.FileHandle.estimateLength(FileHandle.java:233)
at com.badlogic.gdx.files.FileHandle.readString(FileHandle.java:198)
at com.badlogic.gdx.files.FileHandle.readString(FileHandle.java:191)
at aurelienribon.bodyeditor.BodyEditorLoader.<init>(BodyEditorLoader.java:41)
at com.tynibattles04.game.TinyBattles.createBottle(TinyBattles.java:127)
at com.tynibattles04.game.TinyBattles.create(TinyBattles.java:74)
at com.badlogic.gdx.backends.android.AndroidGraphics.onSurfaceChanged(AndroidGraphics.java:241)
at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1512)
at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1240)
Caused by: java.io.FileNotFoundException: tnkA.json
at android.content.res.AssetManager.openAsset(Native Method)
at android.content.res.AssetManager.open(AssetManager.java:355)
at android.content.res.AssetManager.open(AssetManager.java:329)
at com.badlogic.gdx.backends.android.AndroidFileHandle.read(AndroidFileHandle.java:75)
Do you know what could i do with all that?
Thanks in advance!
I have accidentally misspelled tankA.json in the error code - thanks to Angel Angel. But I still keep getting the same error. Maybe that's be cause something wrong this the BodyEditorLoader?
Check the file name and the name you use to load, then you say:
BodyEditorLoader loader = new BodyEditorLoader(
Gdx.files.internal("tankA.json"));
But in stack says:
com.badlogic.gdx.utils.GdxRuntimeException:
Error reading file:
tnkA.json (Internal)
maybe this is an error in the file name: tnkA.json
note: maybe in your code use, tnkA.json and not tankA.json as you think.
hope it helps.
I clearly stored my "background.png" in the assets folder under android.
I also checked that it was there in Finder.
I am working with Android Studio.
However, upon trying to access the image:
public Background() {
textureRegion = new TextureRegion(new Texture("background.png"));
textureRegionBounds1 = new Rectangle(0 - Constants.APP_WIDTH / 2, 0, Constants.APP_WIDTH, Constants.APP_HEIGHT);
textureRegionBounds2 = new Rectangle(Constants.APP_WIDTH / 2, 0, Constants.APP_WIDTH, Constants.APP_HEIGHT);
}
I get this error:
Exception in thread "LWJGL Application" com.badlogic.gdx.utils.GdxRuntimeException: Couldn't load file: background.png
at com.badlogic.gdx.graphics.Pixmap.<init>(Pixmap.java:140)
at com.badlogic.gdx.graphics.TextureData$Factory.loadFromFile(TextureData.java:98)
at com.badlogic.gdx.graphics.GLTexture.createTextureData(GLTexture.java:185)
at com.badlogic.gdx.graphics.Texture.<init>(Texture.java:103)
at com.badlogic.gdx.graphics.Texture.<init>(Texture.java:95)
at com.badlogic.gdx.graphics.Texture.<init>(Texture.java:91)
at com.com.waylonhuang.game.actors.Background.<init>(Background.java:21)
at com.com.waylonhuang.game.stages.GameStage.setUpBackground(GameStage.java:66)
at com.com.waylonhuang.game.stages.GameStage.setUpWorld(GameStage.java:59)
at com.com.waylonhuang.game.stages.GameStage.<init>(GameStage.java:51)
at com.mygdx.game.GameScreen.<init>(GameScreen.java:16)
at com.mygdx.game.DrifterGame.create(DrifterGame.java:11)
at com.badlogic.gdx.backends.lwjgl.LwjglApplication.mainLoop(LwjglApplication.java:137)
at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:114)
Caused by: com.badlogic.gdx.utils.GdxRuntimeException: File not found: background.png (Internal)
at com.badlogic.gdx.files.FileHandle.read(FileHandle.java:136)
at com.badlogic.gdx.files.FileHandle.readBytes(FileHandle.java:222)
at com.badlogic.gdx.graphics.Pixmap.<init>(Pixmap.java:137)
... 13 more......
What am I missing?
EDIT
Also, my current path for the Desktop launcher for the Working Directory is : AndroidStudioProjects/libGDXGame
However, upon changing it to: AndroidStudioProjects/libGDXGame/android/assets
I get a new error like such:
Exception in thread "LWJGL Application" java.lang.NullPointerException
at com.com.waylonhuang.game.stages.GameStage.draw(GameStage.java:134)
at com.mygdx.game.GameScreen.render(GameScreen.java:25)
at com.badlogic.gdx.Game.render(Game.java:46)
at com.badlogic.gdx.backends.lwjgl.LwjglApplication.mainLoop(LwjglApplication.java:208)
at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:114)
try using this:
textureRegion = new TextureRegion(new Texture(
Gdx.files.internal("background.png")));
if it does not work review, case sensitive, of the file name.
Edit: look that is a copy of the file, not a link, once he happened to someone so wrong
You shouldn't load assets in a constructor directly because Gdx.files is null. Either load the assets outside of the constructor or use the AssetsManager.
I can't understand why I'm getting this error: java.lang.RuntimeException: Resource not found I'm trying to make a simple 2d game using Slick and LWJGL libraries, I followed this guide http://www.youtube.com/playlist?list=PLaNw_AbDFccGkU5gnFYquQ0PNQPmmD-Q7 and I managed to make even some more by myself.
The thing is that I am receiving this error even though the image does exist in the specified location. The game runs completely fine and suddenly quits with the error I already mentioned.
The error:
Wed Nov 27 14:43:46 PST 2013 ERROR:Resource not found:
/home/tomtam/workspace/Game/gfx/world/object/blockgreen.png
java.lang.RuntimeException: Resource not found:
/home/tomtam/workspace/Game/gfx/world/object/blockgreen.png
at org.newdawn.slick.util.ResourceLoader.getResourceAsStream(ResourceLoader.java:69)
at org.newdawn.slick.opengl.InternalTextureLoader.getTexture(InternalTextureLoader.java:273)
at org.newdawn.slick.Image.<init>(Image.java:270)
at org.newdawn.slick.Image.<init>(Image.java:244)
at org.newdawn.slick.Image.<init>(Image.java:232)
at org.newdawn.slick.Image.<init>(Image.java:198)
at tomtam.game.object.BlockGreen.render(BlockGreen.java:18)
at tomtam.game.main.World.render(World.java:447)
at tomtam.game.state.PlayState.render(PlayState.java:76)
at org.newdawn.slick.state.StateBasedGame.render(StateBasedGame.java:207)
at org.newdawn.slick.GameContainer.updateAndRender(GameContainer.java:703)
at org.newdawn.slick.AppGameContainer.gameLoop(AppGameContainer.java:456)
at org.newdawn.slick.AppGameContainer.start(AppGameContainer.java:361)
at tomtam.game.main.Main.main(Main.java:36)
Wed Nov 27 14:43:46 PST 2013 ERROR:Game.render() failure - check the game code.
org.newdawn.slick.SlickException: Game.render() failure - check the game code.
at org.newdawn.slick.GameContainer.updateAndRender(GameContainer.java:706)
at org.newdawn.slick.AppGameContainer.gameLoop(AppGameContainer.java:456)
at org.newdawn.slick.AppGameContainer.start(AppGameContainer.java:361)
at tomtam.game.main.Main.main(Main.java:36)
So the error points to this part of the code (image):
public void render(GameContainer gc, Graphics g) throws SlickException
{
super.render(gc, g);
image = new Image("/home/tomtam/workspace/Game/gfx/world/object/blockgreen.png");
}
I am not a skilled programmer, but I guess that this error is because the image is getting rendered nonstop, even if it's location or other information haven't changed. That may produce some lag spikes, right..? So, I tried to change it to:
try
{
image = new Image("/home/tomtam/workspace/Game/gfx/world/object/blockgreen.png");
}
catch (RuntimeException npe)
{
}
I know that it's a bad thing to do it like this, however, this way I am not receiving any errors and everything works fine for some time. After some time some images starts blinking and the more I wait, the less time they are showing up until finally disappearing.
The code is kinda long, but I can post it, just ask. Any help will be appreciated.
Usually a "java.lang.RuntimeException: Resource not found" occurs when your resources (images now) are not in your CLASSPATH and generally it is a classpath issue.
This may also help you.
I found this java source code for a brick breaker game online. I downloaded it and tried to run it but it gives me a NullPointerException. What is giving this exception and how do I fix it? Thanks.
http://zetcode.com/tutorials/javagamestutorial/breakout/
Here is the stacktrace:
Exception in thread "main" java.lang.NullPointerException
at javax.swing.ImageIcon.<init>(ImageIcon.java:181)
at Ball.<init>(Ball.java:16)
at Board.gameInit(Board.java:48)
at Board.addNotify(Board.java:43)
at java.awt.Container.addNotify(Container.java:2578)
at javax.swing.JComponent.addNotify(JComponent.java:4685)
at java.awt.Container.addNotify(Container.java:2578)
at javax.swing.JComponent.addNotify(JComponent.java:4685)
at java.awt.Container.addNotify(Container.java:2578)
at javax.swing.JComponent.addNotify(JComponent.java:4685)
at javax.swing.JRootPane.addNotify(JRootPane.java:739)
at java.awt.Container.addNotify(Container.java:2578)
at java.awt.Window.addNotify(Window.java:663)
at java.awt.Frame.addNotify(Frame.java:470)
at java.awt.Window.show(Window.java:859)
at java.awt.Component.show(Component.java:1584)
at java.awt.Component.setVisible(Component.java:1536)
at java.awt.Window.setVisible(Window.java:842)
at Breakout.<init>(Breakout.java:14)
at Breakout.main(Breakout.java:18)
Exception in thread "Timer-0" java.lang.NullPointerException
at Board$ScheduleTask.run(Board.java:110)
at java.util.TimerThread.mainLoop(Timer.java:512)
at java.util.TimerThread.run(Timer.java:462)
Apparently this code is supposed to work, but it isn't.
You probably didn't download the images as well, or at least didn't put them in the right folder. Make sure you put the images here:
Browse to Ball.java, go two folder levels up, create there a folder called images and put there your images.