Jump to content

  • Log In with Google      Sign In   
  • Create Account

Stubborn libgdx problems!

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
10 replies to this topic

#1   Members   -  Reputation: 118


Posted 05 June 2014 - 09:22 AM

Hello! A few weeks ago I was working on Android game in eclipse (without ADT or any additional tools) when I found out my app was comepletely useless without SDK.
Then I bought got a book from a library from Andreas Oelkhe about java android programming and started playing around with LibGdx. Well, playing around isn't really what I'm trying to say as I'm still trying to find out how to run the damn app when my HTC Wildfire S is connected to my PC directly.

First problem I had (when running desktop version) was that the app was constantly throwing an error because it couldn't fin the badlogic.jpg which was there, but I somehow fixed it (it was a directory thing, can't really remember everything).

Then, I tried to start the app while my phone was plugged in with debugging enabled and it DOES start (the screen flips to landscape position) but then it creashes right away!
I thought it was the picture problem, so I put it in a comment section temporarily, but it still happens.
The screen flips and then, MyDemo.java (or something) has stopped.
I was so pissed, and I still can't find the right answer. I came here to you guys hoping some of you had experienced the same problem before.

Oh, my Android version is 4.4.2, it is a bit unstable, but all the apps seem to be working quite well, some system processes sometimes crash, but that's it. Thanks in advance!

#2   Members   -  Reputation: 118


Posted 05 June 2014 - 09:30 AM

Okay, I got to the source of the problem.
Let me first coppy the code and highlight all the spots causing it

package com.packtub.libgdx.demo;

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 MyDemo extends ApplicationAdapter {
    SpriteBatch batch;
    Texture img;<<<<<<<<<<<<<<<<<<
    public void create () {
        batch = new SpriteBatch();
        img = new Texture("assets/badlogic.jpg");<<<<<<<<<<<<<<<<<<<

    public void render () {
        Gdx.gl.glClearColor(1, 0, 0, 1);
        batch.draw(img, 0, 0);<<<<<<<<<<<<<<<<<<<<<

When I try to run the app with these three lines put under comment section, the app starts with red background, when I put them back together, the app crashes. Under error section, it says something like badlogic.jpg cant be found but I got it in assets folder in demo, android and desktop version!


#3   GDNet+   -  Reputation: 9122


Posted 05 June 2014 - 10:23 AM

"assets/badlogic.jpg" should probably be "assets//badlogic.jpg".

You need to escape the '/' character in the string.

Edited by Lactose!, 05 June 2014 - 11:39 AM.

Hello to all my stalkers.

#4   Members   -  Reputation: 658


Posted 05 June 2014 - 10:47 AM

Isn't the escape character '\'  blink.png  ??

That would apply to a win32 path like "assets\\badlogic.jpg"


I'd say it's more like a working directory problem. 

Edited by alkisbkn, 05 June 2014 - 10:47 AM.

#5   GDNet+   -  Reputation: 9122


Posted 05 June 2014 - 11:39 AM

Oops, yes. Disregard my post.

Hello to all my stalkers.

#6   Members   -  Reputation: 118


Posted 05 June 2014 - 12:59 PM

Wait, so, what's seems to be the problem then?

#7   Members   -  Reputation: 118


Posted 06 June 2014 - 03:46 AM


#8   Moderators   -  Reputation: 40163


Posted 06 June 2014 - 12:02 PM

My guess (without the exact error message) is that the file cannot be found for some reason. Maybe it isn't in exactly the right place. Maybe the file is corrupt. Maybe thre is some other problem. Give the exact error message.

Check out my book, Game Development with Unity, aimed at beginners who want to build fun games fast.

Also check out my personal website at bryanwagstaff.com, where I occasionally write about assorted stuff.

#9   Members   -  Reputation: 118


Posted 06 June 2014 - 12:20 PM

I'll send you, I gotta get some stuff done on the faculty and I'll get back to you as soon as I get a chance.

#10   Members   -  Reputation: 118


Posted 08 June 2014 - 07:12 AM

Hello, sorry for not getting back sooner!

OK, I updated everything on my eclipse, I downloaded newest libgdx, created new project, didn't mess around with the code and I tried starting the application (Desktop version)
On my guess, the same error is stopping dektop and android version from starting.
So...Here's the 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.badlogic.gdx.graphics.Texture.<init>(Texture.java:88)
	at com.imstudios.demo.Main.create(Main.java:16)
	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 (Internal)
	at com.badlogic.gdx.files.FileHandle.read(FileHandle.java:136)
	at com.badlogic.gdx.files.FileHandle.readBytes(FileHandle.java:220)
	at com.badlogic.gdx.graphics.Pixmap.<init>(Pixmap.java:137)
	... 9 more

#11   Members   -  Reputation: 118


Posted 08 June 2014 - 07:41 AM


I dug around a little bit more and here's how I fixed the problem, not sure if only one step or all of them together so I'm going to list everything I did!

1. Go to help in Eclipse and Update Software (Update everything you can!).
2.Download latest LibGdx setup file (last one was out few days ago)
3. Rebuild the project you want to make
4. IF you run the desktop or android app the first time, it's gonna fail (on PC and your android phone both)
5. Go to Run->Run Configurations->Desktop Launcher->Arguments tab. Then click other in the working directory tab and choose Android/assets folder as the default working directory
6. Run your apps and the app should be working fine on both platforms (it is for me)

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.