首页 > 解决方案 > 读取文件时出错:skin\comic-ui.json(内部)即使文件存在,Eclipse 也找不到文件

问题描述

对于我们在小组中开发游戏的学校项目,我们使用 git 来推送和合并我们的代码。昨天我们将我们的代码合并在一起,我们的游戏适用于所有人,但我得到一个错误。

读取文件时出错:skin\comic-ui.json (Internal) 这是我得到的错误文件在资产文件夹中,但在 eclipse 中仍然找不到。`package de.unidue.angryworms.game.screens;

这是使用 json 文件的类

  import com.badlogic.gdx.Gdx;
  import com.badlogic.gdx.Input.Keys;
  import com.badlogic.gdx.graphics.Color;
  import com.badlogic.gdx.graphics.GL20;
  import com.badlogic.gdx.graphics.OrthographicCamera;
  import com.badlogic.gdx.graphics.Texture;
  import com.badlogic.gdx.graphics.g2d.BitmapFont;
  import com.badlogic.gdx.graphics.g2d.TextureAtlas;
  import com.badlogic.gdx.graphics.g2d.TextureRegion;
  import com.badlogic.gdx.scenes.scene2d.Event;
  import com.badlogic.gdx.scenes.scene2d.EventListener;
  import com.badlogic.gdx.scenes.scene2d.InputEvent;
  import com.badlogic.gdx.scenes.scene2d.InputListener;
  import com.badlogic.gdx.scenes.scene2d.Stage;
  import com.badlogic.gdx.scenes.scene2d.ui.ImageButton;
  import com.badlogic.gdx.scenes.scene2d.ui.Label;
  import com.badlogic.gdx.scenes.scene2d.ui.Label.LabelStyle;
  import com.badlogic.gdx.scenes.scene2d.ui.List;
  import com.badlogic.gdx.scenes.scene2d.ui.Skin;
  import com.badlogic.gdx.scenes.scene2d.ui.Table;
  import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
  import com.badlogic.gdx.scenes.scene2d.ui.TextButton.TextButtonStyle;
  import com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable;
  import com.badlogic.gdx.utils.viewport.FitViewport;
  import com.badlogic.gdx.utils.viewport.Viewport;
  import com.kotcrab.vis.ui.VisUI;
  import com.kotcrab.vis.ui.widget.VisTable;

import de.unidue.angryworms.game.SEPGame;
import de.unidue.angryworms.game.gameobjects.EnumWorld;

 public class Menu implements Screen, com.badlogic.gdx.Screen {

private SEPGame sepgame;
private Viewport menuscreen;
public Stage menustage;
OrthographicCamera camera;


public Menu(SEPGame game) {
    this.sepgame = game;


    menustage = new Stage();
    Gdx.input.setInputProcessor(menustage);

    Table table = new Table();
    table.setFillParent(true);
    //stage.addActor(table);


/*  camera = new OrthographicCamera();
    camera.setToOrtho(false, SEPGame.V_WIDTH, SEPGame.V_HEIGHT );
    menuscreen = new FitViewport(SEPGame.V_WIDTH/2, SEPGame.V_HEIGHT/2, 
    camera);
    menustage = new Stage(menuscreen, game.batch);
    Gdx.input.setInputProcessor(menustage);
    */


    Skin mySkin = new Skin(Gdx.files.internal("skin/comic-ui.json"));


    //Table table = new Table();
    //table.debug();

    //table.top();
    //table.setFillParent(true);

    //sepgame.font.getData().setScale(2, 2);






    //LabelStyle lstyle = new Label.LabelStyle(sepgame.font, Color.WHITE);
    //lstyle = mySkin;

    final Label world1nameLabel = new Label("ANGRY WORMS", mySkin);
    world1nameLabel.setFontScale(4);
    Label lbl_karte = new Label("Karte 1 - 4 auswählen", mySkin);
    lbl_karte.setFontScale(2);



    //TextButton button_karte = new TextButton("Karte auswählen",mySkin);
    TextButton button3 = new TextButton("Teams Edtitieren",mySkin);
    TextButton button_starten = new TextButton("Spiel starten",mySkin);
    final List list = new List(mySkin);
  //  MapItem[] myItems = {new MapItem("Karte1", EnumWorld.World1), new 
      MapItem("Karte2", EnumWorld.World1), new MapItem("Karte3", 
      EnumWorld.World1), new MapItem("Karte4",  EnumWorld.World1)};
    list.setItems(EnumWorld.values());

   // button2.debug();
    button_starten.addListener(new InputListener()
    {   
        @Override
        public boolean touchDown (InputEvent event, float x, float y, int 
        pointer, int button) {
            //world1nameLabel.setText("Pressed Text Button");
            sepgame.setScreen(new PlayScreen(sepgame, 
            (EnumWorld)list.getSelected()));
            return true;
        }
    });

    table.add(world1nameLabel).pad(50);
    table.row();
    table.add(lbl_karte);
    table.row();
    table.add(list);
    table.row();
  //  table.add(button2);
    table.row();
    table.add(button3);
    table.row();
    table.add(button_starten);

    Label lblStart = new Label("temp: press S to continue", mySkin);
    lblStart.setFontScale(3);

    table.row();
    table.add(lblStart);





    menustage.addActor(table);
    // table.addActor(world1);

    // table.setDebug(true);
}

@Override
public void show() {
    // TODO Auto-generated method stub

}

@Override
public void render(float fval) {
    Gdx.gl.glClearColor(255, 255, 255, 1);
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
    //camera.update();

    menustage.draw();


}

@Override
public void hide() {
    // TODO Auto-generated method stub

}

@Override
public void resize(int width, int height) {


}

@Override
public void pause() {
    // TODO Auto-generated method stub

}

@Override
public void resume() {
    // TODO Auto-generated method stub

}

@Override
public void dispose() {
    // TODO Auto-generated method stub

}

}

这是错误

Exception in thread "LWJGL Application" com.badlogic.gdx.utils.SerializationException: Error reading file: skin/comic-ui.json
    at com.badlogic.gdx.scenes.scene2d.ui.Skin.load(Skin.java:98)
    at com.badlogic.gdx.scenes.scene2d.ui.Skin.<init>(Skin.java:75)
    at de.unidue.angryworms.game.screens.Menu.<init>(Menu.java:62)
    at de.unidue.angryworms.game.SEPGame.create(SEPGame.java:42)
    at com.badlogic.gdx.backends.lwjgl.LwjglApplication.mainLoop(LwjglApplication.java:149)
    at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:126)
Caused by: com.badlogic.gdx.utils.SerializationException: Error reading file: skin/comic-ui.json
    at com.badlogic.gdx.utils.Json.fromJson(Json.java:711)
    at com.badlogic.gdx.scenes.scene2d.ui.Skin.load(Skin.java:96)
    ... 5 more
Caused by: com.badlogic.gdx.utils.SerializationException: Error parsing file: skin/comic-ui.json
    at com.badlogic.gdx.utils.JsonReader.parse(JsonReader.java:78)
    at com.badlogic.gdx.utils.Json.fromJson(Json.java:709)
    ... 6 more
Caused by: com.badlogic.gdx.utils.GdxRuntimeException: File not found: skin\comic-ui.json (Internal)
    at com.badlogic.gdx.files.FileHandle.read(FileHandle.java:136)
    at com.badlogic.gdx.files.FileHandle.reader(FileHandle.java:163)
    at com.badlogic.gdx.utils.JsonReader.parse(JsonReader.java:76)
    ... 7 more

最后是 json 文件

{
com.badlogic.gdx.graphics.g2d.BitmapFont: {
    button: {
        file: font-button-export.fnt
    }
    font: {
        file: font-export.fnt
    }
    title: {
        file: font-title-export.fnt
    }
}
com.badlogic.gdx.graphics.Color: {
    black: {
        r: 0
        g: 0
        b: 0
        a: 1
    }
    gray: {
        r: 0.7466668
        g: 0.7466668
        b: 0.7466668
        a: 1
    }
    white: {
        r: 1
        g: 1
        b: 1
        a: 1
    }
}
com.badlogic.gdx.scenes.scene2d.ui.Skin$TintedDrawable: {
    cyan: {
        name: white
        color: {
            r: 0.30333334
            g: 0.96412176
            b: 1
            a: 1
        }
    }
}
com.badlogic.gdx.scenes.scene2d.ui.Button$ButtonStyle: {
    default: {
        up: button
        down: button-pressed
        over: button-highlighted
    }
}
com.badlogic.gdx.scenes.scene2d.ui.CheckBox$CheckBoxStyle: {
    default: {
        checkboxOn: checkbox-on
        checkboxOff: checkbox
        font: button
        fontColor: black
    }
    radio: {
        checkboxOn: radio-on
        checkboxOff: radio
        font: button
        fontColor: black
    }
}
com.badlogic.gdx.scenes.scene2d.ui.ImageButton$ImageButtonStyle: {
    default: {
        up: button
        down: button-pressed
        over: button-highlighted
    }
}
com.badlogic.gdx.scenes.scene2d.ui.Label$LabelStyle: {
    default: {
        font: font
        fontColor: black
    }
    narration: {
        font: font
        fontColor: black
        background: narration-box
    }
    big: {
        font: button
        fontColor: black
    }
    title: {
        font: title
        fontColor: white
    }
    alt: {
        font: font
        fontColor: black
        background: window
    }
    half-tone: {
        font: button
        fontColor: black
        background: half-tone-box
    }
}
com.badlogic.gdx.scenes.scene2d.ui.List$ListStyle: {
    default: {
        font: font
        fontColorSelected: black
        fontColorUnselected: black
        selection: cyan
    }
    select-box: {
        font: font
        fontColorSelected: black
        fontColorUnselected: black
        selection: cyan
        background: select-box-list
    }
    select-box-big: {
        font: button
        fontColorSelected: black
        fontColorUnselected: black
        selection: cyan
        background: select-box-big-list
    }
}
com.badlogic.gdx.scenes.scene2d.ui.ProgressBar$ProgressBarStyle: {
    default-horizontal: {
        background: progress-bar
        knobBefore: progress-bar-knob
    }
    default-vertical: {
        background: progress-bar
        knobBefore: progress-bar-knob
    }
}
com.badlogic.gdx.scenes.scene2d.ui.ScrollPane$ScrollPaneStyle: {
    default: {
        hScrollKnob: scrollbar-horizontal
        vScrollKnob: scrollbar-vertical
    }
    select-box: {
        background: select-box-list
        hScrollKnob: scrollbar-horizontal
        vScrollKnob: scrollbar-vertical
    }
}
com.badlogic.gdx.scenes.scene2d.ui.SelectBox$SelectBoxStyle: {
    default: {
        font: font
        fontColor: black
        background: select-box
        scrollStyle: default
        listStyle: select-box
        backgroundOpen: select-box-open
    }
    big: {
        font: button
        fontColor: black
        background: select-box-big
        scrollStyle: default
        listStyle: select-box-big
        backgroundOpen: select-box-big-open
    }
}
com.badlogic.gdx.scenes.scene2d.ui.Slider$SliderStyle: {
    default-horizontal: {
        background: slider
        knob: slider-knob
    }
    default-vertical: {
        background: slider
        knob: slider-knob
    }
}
com.badlogic.gdx.scenes.scene2d.ui.TextButton$TextButtonStyle: {
    default: {
        font: button
        fontColor: black
        up: button
        down: button-pressed
        over: button-highlighted
    }
}
com.badlogic.gdx.scenes.scene2d.ui.TextField$TextFieldStyle: {
    default: {
        font: font
        fontColor: black
        background: text-field
        cursor: cursor
        selection: cyan
        messageFontColor: gray
    }
}
com.badlogic.gdx.scenes.scene2d.ui.TextTooltip$TextTooltipStyle: {
    default: {
        label: alt
    }
    alt: {
        label: narration
    }
}
com.badlogic.gdx.scenes.scene2d.ui.Tree$TreeStyle: {
    default: {
        plus: plus
        minus: minus
        selection: cyan
    }
}
com.badlogic.gdx.scenes.scene2d.ui.Window$WindowStyle: {
    default: {
        background: window
        titleFont: font
    }
    alt: {
        background: narration-box
        titleFont: font
    }
}
}

我希望有人可以帮助我,我搜索了很多,但我发现的东西并没有帮助我。奇怪的是,相同的代码适用于我的朋友,但不适用于我。

标签: javajsonlibgdx

解决方案


尝试通过在包资源管理器中选择它并按 f5 来刷新资产文件夹。


推荐阅读