Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I am having a problem with a libGDX project reading the assets folder when compiling the Android or IOS build. While trying to access a file in the assets folder under the android module, I always seem to get a FileNotFoundException in IOS or Android, but not when running it on the Desktop. My desktop config points the android asset directory like it should.

When executing the following code :

 public void readGameMap() throws IOException
    {
        readGameMap("gameMap.txt");
    }

    public void readGameMap(String path) throws IOException
    {

        Scanner s = new Scanner(Gdx.files.internal(path).file());


        int i = 0;


        while ((s.hasNextLine()))
        {

            String str = s.nextLine();

            if (str.length() < maze.length)
                throw new IOException("Incorrect game_map.txt structure");

            for (int j = 0; j < str.length(); j++)
            {

                Object temp;

                switch (str.charAt(j))
                {
                    case '1':
                        temp = new Wall();
                        break;

                    case '3':
                        temp = new Dot();
                        break;

                    default:
                        temp = new Object();
                        break;
                }

                maze[j][i] = temp;

            }

            i++;
        }

        s.close();

    }

The file not found exception is thrown. My folder structure is as follows:

-Android
  -assets
    -gameMap.txt
-Desktop
-IOS
-HTML
-core
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
520 views
Welcome To Ask or Share your Answers For Others

1 Answer

In case if you are using Android Studio, select edit config... In case if you are using Android Studio, select edit config...

Change 'Desktop Application' -> 'Working Directory' to your android asset forlder Change 'Desktop Application' -> 'Working Directory' to your android asset forlder


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share

548k questions

547k answers

4 comments

86.3k users

...