Cannot load .png file using LibGDX Gdx.files.internal

I am trying to load Texture into libGDX and I am getting an exception not found in the file.

Here is the code that is trying to download the .png file.

//Textures private Texture tiles; private TextureRegion grassImage; private TextureRegion dirtImage; private TextureRegion stoneImage; //Entities private Texture entities; private TextureRegion playerImage; public WorldRenderer(World world, boolean debug) { this.world = world; this.camera = new OrthographicCamera(CAMERA_WIDTH, CAMERA_HEIGHT); this.camera.position.set(CAMERA_WIDTH/2f, CAMERA_HEIGHT/2f, 0); this.camera.update(); this.debug = debug; spriteBatch = new SpriteBatch(); loadTextures(); } public void loadTextures() { tiles = new Texture(Gdx.files.internal("tiles.png")); grassImage = new TextureRegion(tiles, 0, 0, 32, 32); dirtImage = new TextureRegion(tiles, 0, 64, 32, 32); stoneImage = new TextureRegion(tiles, 64, 0, 32, 32); entities = new Texture(Gdx.files.internal("entities.png")); playerImage = new TextureRegion(entities, 0, 0, 32, 32); } public void render() { spriteBatch.begin(); drawGrass(); drawDirt(); drawStone(); drawPlayer(); spriteBatch.end(); if (debug) { drawDebug(); } } 

Here is the error message:

 Exception in thread "LWJGL Application" com.badlogic.gdx.utils.GdxRuntimeException: Couldn't load file: tiles.png 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:175) at com.badlogic.gdx.graphics.Texture.create(Texture.java:159) at com.badlogic.gdx.graphics.Texture.<init>(Texture.java:133) at com.badlogic.gdx.graphics.Texture.<init>(Texture.java:122) at com.mr.zen.level.WorldRenderer.loadTextures(WorldRenderer.java:62) at com.mr.zen.level.WorldRenderer.<init>(WorldRenderer.java:58) at com.mr.zen.screens.GameScreen.show(GameScreen.java:29) at com.badlogic.gdx.Game.setScreen(Game.java:62) at com.mr.zen.Zen.create(Zen.java:12) 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: tiles.png (Internal) at com.badlogic.gdx.files.FileHandle.read(FileHandle.java:132) at com.badlogic.gdx.files.FileHandle.length(FileHandle.java:586) at com.badlogic.gdx.files.FileHandle.readBytes(FileHandle.java:220) at com.badlogic.gdx.graphics.Pixmap.<init>(Pixmap.java:137) ... 12 more 

The problem exists in the loadTextures () method. Cannot find file.

  tiles = new Texture(Gdx.files.internal("tiles.png")); 

I definitely put the .png files in the resource folder of the Android project files. I have no idea what it is; I got this to work on other projects, but this time something went wrong. Thanks for any help.

+7
java libgdx
source share
7 answers

Solving the problem "Could not load file" by cleaning the project (Eclipse)

(For this solution, the paths to your image files are expected to be correct.)

Sometimes I have this Unable to upload file when I add new images to my project. I don’t know why, but my desktop version of my LibGDX game does not update the Mygame-desktop / bin / data strong> folder with my new images (which were added to Mygame-android / assets / data strong>) when the project is built . (That is, every time I save a file, Eclipse builds a project, so I set Project> Automatically create .)

It should work because in LibGDX Desktop and HTML projects have a link to the assets folder of the Android project. So, I did not need to manually copy my new images to Mygame-desktop / bin / data strong>.

The Eclipse solution should clear ( Project> Clear ... menu) all LibGDX projects that you use for your game, and then the files in Mygame-android / assets / data will be copied to Mygame-desktop / bin / data strong> .

+10
source share

If you use Gradle, left-click in the package explorer on Aassets -> Gradle -> Refresh All.

What is it =)

+6
source share

create a new data folder in the resource folder of the Android project and then access the file using Gdx.files.internal ("data / tiles.png")

tiles = new Texture(Gdx.files.internal("data/tiles.png"));

+3
source share

Create a data folder in the resource folder and instead

 tiles = new Texture(Gdx.files.internal("tiles.png")); 

try the following:

 tiles = new Texture("data/tiles.png"); 
+1
source share

Left-click in the package explorer in an update or just F5.

This solved my problem.

0
source share

This problem works for me in android studio 2 using the current version of libgdx. When I save as png to psp - cs6 and / or cs15 - it cannot read it. I cannot remember the exact error message, something like io cannot read the stream. So I tried to save it again in Corel paint. Same problem. Then with a simple drawing utility packaged with windows. Not good. Finally I downloaded paint.net. Now my workflow just requires an extra step. Any png created using psp, etc., Almost any png libgdx grumps, I load Paint.net, click "save", and I am good to go.

This is not really a solution, but it does its job.

You seem good, but I hope this helps someone out there. Mark

0
source share

Your PNG profile may not be supported by LibGDX.

I installed it in sRGB-elle-V2-srgbtrc.icc (using Krita) and now it works.

In Crete, go to:

Image> Properties> Profile

0
source share

All Articles