I'm using libGDX and I got a huge problem with the split method. I'm working on a skillsystem for a game right now in which the player can choose 2 skills at the beginning of the game. The 2 chosen skills are displayed ingame as a button.
So here's my code which works fine for the desktop version but crashes if I reach the code in my android app:
AbstractTextureButton.java
protected void initButton(Skin skin) {
texture = new Texture(Gdx.files.internal(getTexturePath())); //line 49
TextureRegion textureRegion = new TextureRegion(texture);
button = new Button(new Image(textureRegion), skin, "default");
button.setBounds(getXPos(), getYPos(), button.getWidth(), button.getHeight());
button.addListener(getInputListener());
}
Skill2Button.java
@Override
protected String getTexturePath() {
//this string for e.g. is com.blub.skills.Slowmotion or com.blub.skills.Burst
String selectedSkill = SkillManager.getInstance().getSelectedSkillName2();
//split it at the .
String[] splitResult = selectedSkill.split("\\."); // --> CRASH!*
//get the last element in my string
String skillName = splitResult[splitResult.length - 1];
//return texturepath for the selected skill
return "graphics/skills/skill_" + skillName + ".png";
}
Same crash happens if I'm using lastIndexOf() instead of split().
Logcat log:
10-17 12:20:05.631: E/AndroidRuntime(32132): at com.deinemudda.hoernchenattack.core.ui.buttons.AbstractTextureButton.initButton(AbstractTextureButton.java:49)
10-17 12:20:05.631: E/AndroidRuntime(32132): at com.deinemudda.hoernchenattack.core.ui.buttons.AbstractBaseButton.<init>(AbstractBaseButton.java:33)
10-17 12:20:05.631: E/AndroidRuntime(32132): at com.deinemudda.hoernchenattack.core.ui.buttons.AbstractTextureButton.<init>(AbstractTextureButton.java:31)
10-17 12:20:05.631: E/AndroidRuntime(32132): at com.deinemudda.hoernchenattack.core.ui.buttons.Skill2Button.<init>(Skill2Button.java:29)
10-17 12:20:05.631: E/AndroidRuntime(32132): at com.deinemudda.hoernchenattack.core.ui.screens.GameScreen.create(GameScreen.java:143)
10-17 12:20:05.631: E/AndroidRuntime(32132): at com.deinemudda.hoernchenattack.core.ui.screens.GameScreen.resume(GameScreen.java:347)
10-17 12:20:05.631: E/AndroidRuntime(32132): at com.deinemudda.hoernchenattack.core.Hoernchenattack.setCurrentScreen(Hoernchenattack.java:104)
10-17 12:20:05.631: E/AndroidRuntime(32132): at com.deinemudda.hoernchenattack.core.ui.buttons.LevelButton$1.touchUp(LevelButton.java:50)
10-17 12:20:05.641: E/EmbeddedLogger(593): App crashed! Process: com.deinemudda.hoernchenattack.android
10-17 12:20:05.641: E/EmbeddedLogger(593): App crashed! Package: com.deinemudda.hoernchenattack.android v1 (1.0)
What's the problem? Works perfectly for the desktop application... I tried to use '\.' instead of "\." and I tried to use Pattern.quote(".") as well -> no way :| I'm using the libGDX version 0.9.9 android version is 2.1.2