Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/319.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/198.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/gwt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java GdxRuntimeException:读取文件时出错_Java_Android_Libgdx - Fatal编程技术网

Java GdxRuntimeException:读取文件时出错

Java GdxRuntimeException:读取文件时出错,java,android,libgdx,Java,Android,Libgdx,我正在学习并使用libgdx为android编程一个游戏,我已经被这个错误困扰了很长一段时间。我已附上下列内容 密码 我用来访问资源的命令 在android上调试代码时包含错误的屏幕截图 我的包浏览器的屏幕截图 所有可能的组合,我试图让代码工作 1.守则 package com.me.mygdxgame; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.assets.AssetErrorListener; import com.

我正在学习并使用libgdx为android编程一个游戏,我已经被这个错误困扰了很长一段时间。我已附上下列内容

  • 密码
  • 我用来访问资源的命令
  • 在android上调试代码时包含错误的屏幕截图
  • 我的包浏览器的屏幕截图
  • 所有可能的组合,我试图让代码工作
  • 1.守则

    package com.me.mygdxgame;
    
    import com.badlogic.gdx.Gdx;  
    import com.badlogic.gdx.assets.AssetErrorListener;  
    import com.badlogic.gdx.assets.AssetManager;  
    import com.badlogic.gdx.graphics.Texture;  
    import com.badlogic.gdx.graphics.Texture.TextureFilter;    
    import com.badlogic.gdx.graphics.g2d.TextureAtlas;  
    import com.badlogic.gdx.utils.Disposable;
    
    public class Gameassetloader implements Disposable, AssetErrorListener {
    
    public static final String TAG = Gameassetloader.class.getName();
    public static Gameassetloader instance = new Gameassetloader();
    private AssetManager assetManager;
    
    /** Load the appropriate texture for the respective entities **/
    public AssetCharacter boy;
    public AssetRock rock;
    public AssetShield shield;
    
    /** singleton: prevent instantiation from other classes **/
    
    private Gameassetloader(){}
    public void init(AssetManager assetManager)
     {
        this.assetManager = assetManager;
    
        //set asset manager error handler
        assetManager.setErrorListener(this);
    
        //load texture atlas
        assetManager.load(Gameconstants.TEXTURE_ATLAS_OBJECTS,TextureAtlas.class);
    
        //start loading assets and wait until finished
        assetManager.finishLoading();
    
        Gdx.app.debug(TAG, "# of assets loaded:" + assetManager.getAssetNames().size);
    
        for (String a : assetManager.getAssetNames())
            Gdx.app.debug(TAG, "asset:" + a);
    
        TextureAtlas atlas = assetManager.get(Gameconstants.TEXTURE_ATLAS_OBJECTS);
    
        //enable texture filtering for pixel smoothing
        for(Texture t : atlas.getTextures())
            t.setFilter(TextureFilter.Linear,TextureFilter.Linear);
    
        //create game resource objects
    
        boy = new AssetCharacter(atlas);
        rock = new AssetRock(atlas);
        shield = new AssetShield(atlas);
    }
    
    public void dispose() { assetManager.dispose(); }
    
    
     @Override
     public void error(String fileName, Class type, Throwable throwable) 
      {
        Gdx.app.error(TAG, "Couldn't load asset' " + fileName + "'", (Exception)throwable); 
      }
    
    }  
    
    2.命令

     public static final String TEXTURE_ATLAS_OBJECTS ="gdxgame-android/assets/packed/packed.png";
    
    3.软件包浏览器屏幕截图

    4.错误日志截图(Android DDMS)

    5.我尝试过的所有可能的组合

     "/gdxgame-android/assets/packed/packed.png";
     "gdxgame-android/assets/packed/packed.png";
     "/assets/packed/packed.png";
     "assets/packed/packed.png";
     "/packed/packed.png";
     "packed/packed.png";
     "/packed.png";
     "packed.png";
    
     public static FileHandle location = Gdx.files.internal("assets/packed.png");
     public static final TEXTURE_ATLAS_OBJECT = location.toString();
    
     //this caused shutdown of emulator
     public static FileHandle location = Gdx.files.internal("assets/packed.png");
     public static final TEXTURE_ATLAS_OBJECT = location.readString();
    
     // I even tried setting the build path of the asset folder as source folder
     // Also tried placing the image in the data folder.
     // Tried using the absolute path too , i.e Gdx.files.absolute("the absolute");
     // Tried passing the absolute path directly as string
    

    对我来说似乎什么都不管用。

    问题很简单,问题在于libgdx和文档的不同版本。下面解释的答案仅适用于libgdx版本0.9.8

    (注意:Texturepacker GUI用于打包纹理&而不是libgdx库中的方法)

    首先,必须向“assetManager”提供一个文件,其中包含图像的坐标,这是一个错误,因为我正在提供压缩图像

    GL20应该能够解析NPOT图像,但它无法解析,原因仍然未知,因此我必须将纹理打包到POT中,这是通过在GUI中选择POT选项完成的。完成此操作后,我能够使用以下代码轻松加载新的POT图像

    /**Mention only the folder/file under the asset dir**/
    
    public class Gameconstants { public static final String location = "packed/packed.txt" }
    
    /**access the same using the following command**/
    
    private AssetManager assetManager;
    assetManager.load(Gameconstants.location,Texture.class);
    
    这个答案可能不是很有说服力,但它确实解决了我的问题


    感谢所有帮助过你的人:)

    猜猜看,试试使用
    Gdx.files.classpath(“assets/packed.png”)。非工作伙伴:(,读取文件时仍然出错我认为您为
    Gdx.files.internal
    指定的位置都是错误的,包括fjle句柄和纹理\u atlas\u对象常量,请检查是否将其与\assets\data\对齐…设置是否重要。将资产放置在data下,然后通过命令Gdx.files.internal(“data/***.png”)使用它)仍然会产生错误,是的,自从我使用eclipse以来,我一直在刷新文件夹。我正在传递一个带路径的字符串,无论我是使用另一个变量还是直接传递它,我认为这都不重要,因为即使是方法load()所需的第一个参数也是一个字符串。我仍将尝试使用它,并尝试使用其他随机图像,以确保图像文件没有问题。