致命异常:主要(在java到android项目转换后)

时间:2015-10-25 22:36:17

标签: java android

因此,当我尝试将Java项目转换为Android项目时,每当我尝试运行它时,我的游戏都会在我的手机上崩溃,并且我在log cat中遇到以下错误。我正在尝试集成SDK,以便我可以通过屏幕在游戏中放置广告。

logcat错误:

10-25 15:13:06.580: E/AndroidRuntime(13472): FATAL EXCEPTION: main
10-25 15:13:06.580: E/AndroidRuntime(13472): Process:      com.AustinMagnuson.mygdxgame, PID: 13472
10-25 15:13:06.580: E/AndroidRuntime(13472): java.lang.NoClassDefFoundError: Failed resolution of: Lcom/AustinMagnuson/mygdxgame/FallingFlame;
10-25 15:13:06.580: E/AndroidRuntime(13472):    at com.AustinMagnuson.mygdxgame.MainActivity.onCreate(MainActivity.java:20)
10-25 15:13:06.580: E/AndroidRuntime(13472):    at android.app.Activity.performCreate(Activity.java:6221)
10-25 15:13:06.580: E/AndroidRuntime(13472):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1119)
10-25 15:13:06.580: E/AndroidRuntime(13472):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2614)
10-25 15:13:06.580: E/AndroidRuntime(13472):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726)
10-25 15:13:06.580: E/AndroidRuntime(13472):    at android.app.ActivityThread.access$900(ActivityThread.java:172)
10-25 15:13:06.580: E/AndroidRuntime(13472):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1421)
10-25 15:13:06.580: E/AndroidRuntime(13472):    at android.os.Handler.dispatchMessage(Handler.java:102)
10-25 15:13:06.580: E/AndroidRuntime(13472):    at android.os.Looper.loop(Looper.java:145)
10-25 15:13:06.580: E/AndroidRuntime(13472):    at android.app.ActivityThread.main(ActivityThread.java:5835)
10-25 15:13:06.580: E/AndroidRuntime(13472):    at java.lang.reflect.Method.invoke(Native Method)
10-25 15:13:06.580: E/AndroidRuntime(13472):    at java.lang.reflect.Method.invoke(Method.java:372)
10-25 15:13:06.580: E/AndroidRuntime(13472):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399)
10-25 15:13:06.580: E/AndroidRuntime(13472):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194)
10-25 15:13:06.580: E/AndroidRuntime(13472): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.AustinMagnuson.mygdxgame.FallingFlame" on path: DexPathList[[zip file "/data/app/com.AustinMagnuson.mygdxgame-1/base.apk"],nativeLibraryDirectories=[/data/app/com.AustinMagnuson.mygdxgame-1/lib/arm, /vendor/lib, /system/lib]]
10-25 15:13:06.580: E/AndroidRuntime(13472):    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
10-25 15:13:06.580: E/AndroidRuntime(13472):    at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
10-25 15:13:06.580: E/AndroidRuntime(13472):    at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
10-25 15:13:06.580: E/AndroidRuntime(13472):    ... 14 more
10-25 15:13:06.580: E/AndroidRuntime(13472):    Suppressed: java.lang.ClassNotFoundException: com.AustinMagnuson.mygdxgame.FallingFlame
10-25 15:13:06.580: E/AndroidRuntime(13472):        at java.lang.Class.classForName(Native Method)
10-25 15:13:06.580: E/AndroidRuntime(13472):        at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
10-25 15:13:06.580: E/AndroidRuntime(13472):        at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
10-25 15:13:06.580: E/AndroidRuntime(13472):        at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
10-25 15:13:06.580: E/AndroidRuntime(13472):        ... 15 more
10-25 15:13:06.580: E/AndroidRuntime(13472):    Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available

(从Java转换为Android项目)

FallingFlame.Java:

package com.AustinMagnuson.mygdxgame;

import java.util.Iterator;

import com.AustinMagnuson.camera.OrthoCamera;
import com.badlogic.gdx.ApplicationListener;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.audio.Music;
import com.badlogic.gdx.audio.Sound;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.GL10;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
import com.badlogic.gdx.math.MathUtils;
import com.badlogic.gdx.math.Rectangle;
import com.badlogic.gdx.math.Vector2;
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.Label;
import com.badlogic.gdx.scenes.scene2d.ui.Label.LabelStyle;
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton.TextButtonStyle;
import com.badlogic.gdx.utils.Array;
import com.badlogic.gdx.utils.TimeUtils;

public class FallingFlame implements ApplicationListener {

    private static Texture dropImage;
    private Texture bounds1;
    private static Texture Tree;
    private Texture Background;
    private Rectangle bounds;
    private SpriteBatch batch;
    Player player;
    private Array<Rectangle> raindrops;
    private Array<Rectangle> trees;
    private long lastTreeTime;
    private long lastDropTime;
    public static int WIDTH = 1080, HEIGHT =720;
    float stateTime;
    String movement;
    float gravity = 0.0f;
    private OrthoCamera camera;
    private int score;
    private String yourScoreName;
    private String yourScoreName2;
    BitmapFont yourBitmapFontName;
    BitmapFont yourBitmapFontName2;
    boolean GameOver = false;
    Stage stage;
    Label label;
    LabelStyle style;
    BitmapFont font;
    TextureAtlas buttonAtlas;
    TextButtonStyle buttonStyle;
    TextButton button;
    Skin skin;
    private Music FFmusic;
    private Sound treeSound;
    private Sound waterSound;

    private void spawnRaindrop(){
        Rectangle  raindrop = new Rectangle();
        raindrop.x = MathUtils.random(FallingFlame.WIDTH, FallingFlame.WIDTH);
        raindrop.y = MathUtils.random(0, FallingFlame.WIDTH - FallingFlame.dropImage.getWidth());
        raindrop.width = 40;
        raindrop.height = 70;
        raindrops.add(raindrop);
        lastDropTime = TimeUtils.nanoTime();
    }

    private void spawnTree(){
        Rectangle tree = new Rectangle();
        tree.x = MathUtils.random(FallingFlame.WIDTH, FallingFlame.WIDTH * 1);
        tree.y = MathUtils.random(0, FallingFlame.WIDTH - FallingFlame.Tree.getWidth());
        tree.width = 40;
        tree.height = 40;
        trees.add(tree);
        lastTreeTime = TimeUtils.nanoTime();
    }

    @Override
    public void create() {

        score = 0;
        yourScoreName = "Score:  0";
        yourScoreName2 = "";
        yourBitmapFontName = new BitmapFont();
        yourBitmapFontName2 = new BitmapFont();

        camera = new OrthoCamera();
        camera.setToOrtho(false, 1080, 720);

        waterSound = Gdx.audio.newSound(Gdx.files.internal("Water.mp3"));
        treeSound = Gdx.audio.newSound(Gdx.files.internal("Tree.mp3"));
        FFmusic = Gdx.audio.newMusic(Gdx.files.internal("Music.mp3"));
        Background = new Texture(Gdx.files.internal("Background.png"));
        bounds1 = new Texture(Gdx.files.internal("bounds.png"));
        dropImage = new Texture(Gdx.files.internal("Water2.png"));
        Tree = new Texture(Gdx.files.internal("Tree.png"));
        bounds = new Rectangle();
        bounds.x = 350;
        bounds.y = 800;
        bounds.width = 35;
        bounds.height = 0;

        FFmusic.setLooping(true);
        FFmusic.play();


        player = new Player (new Vector2(Gdx.graphics.getWidth() / 2, Gdx.graphics.getHeight() /2), "");

        raindrops = new Array<Rectangle>();
        spawnRaindrop();

        trees = new Array<Rectangle>();
        spawnTree();

        player.setPosition(new Vector2(300, 660));



        stage = new Stage(Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), true);
        font = new BitmapFont(Gdx.files.internal("font.fnt"), false);
        style = new LabelStyle(font, Color.WHITE);
        skin = new Skin();
        buttonAtlas = new TextureAtlas("buttons/button.pack");
        skin.addRegions(buttonAtlas);

        Gdx.input.setInputProcessor(stage);

        batch = new SpriteBatch();  

    }


    @Override
    public void dispose() {

        batch.dispose();

    }

    public void render1() {

        buttonStyle = new TextButtonStyle();
        buttonStyle.up = skin.getDrawable("button");
        buttonStyle.over = skin.getDrawable("buttonpressed");
        buttonStyle.down = skin.getDrawable("buttonpressed");
        buttonStyle.font = font;

        button = new TextButton(" ", buttonStyle);
        stage.addActor(button);
        button.setPosition(800, 2);


        button.addListener(new InputListener(){
            public boolean touchDown(InputEvent event, float x, float y, int pointer, int button){

                FFmusic.dispose();
                GameOver = false;
                create();
                return true;

            }

        });


        yourScoreName2 = "GAME OVER";

        Background = new Texture(Gdx.files.internal("Background1.png"));

        player.update();
        camera.update();        
        stage.act();

        batch.setProjectionMatrix(camera.combined);
        batch.begin();
        batch.draw(Background, 0, 0);
        yourBitmapFontName.setColor(1.0f, 1.0f, 1.0f, 1.0f);
        yourBitmapFontName.draw(batch, yourScoreName, 50, 700);
        yourBitmapFontName2.setColor(1.0f, 1.0f, 1.0f, 1.0f);
        yourBitmapFontName2.draw(batch, yourScoreName2, 470, 700);
        batch.draw(bounds1, bounds.x, bounds.y);
        batch.draw(player.getCurrentFrame(), player.getPosition().x, player.getPosition().y);

        stage.draw();
        batch.end();


    }

    @Override
    public void render() {

        if(GameOver){
             render1();
             return;
            }

        Gdx.gl.glClearColor(0, 0, 0, 1);
        Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);


        if(TimeUtils.nanoTime() - lastTreeTime > 1000000000) spawnTree();
        if(TimeUtils.nanoTime() - lastDropTime > 900000000) spawnRaindrop();

        bounds.set(bounds.x, bounds.y, bounds.getWidth(), gravity);

        if(stateTime < .7)
        {
            stateTime += Gdx.graphics.getDeltaTime();
        }
        else
        {
            stateTime = 0;
        }

        float max_y = 670;
        float min_y = 12;
        float virtual_y = bounds.y; 

        if(Gdx.input.isTouched())
        {

            virtual_y += 6.5;
            gravity = 13.5f;

            movement = "up";
        }
        else
        {
            if (gravity > 0 )
            {
                virtual_y += gravity;
                gravity -= 0.3;
            }

            virtual_y -= 7;

            movement = "down";
        }

        if (virtual_y > max_y)
        {
            bounds.y = max_y ;
        }
        else
        {
            bounds.y = virtual_y;
        }
        if (bounds.y < min_y)
        {
            bounds.y = min_y;
        }

        Iterator<Rectangle> iter = trees.iterator();
        while(iter.hasNext()){
            Rectangle tree = iter.next();
            tree.x -= 200 * Gdx.graphics.getDeltaTime();
            if(tree.x + 64 < 0) iter.remove();

            if(tree.overlaps(bounds)){
                treeSound.play();
                score++;
                yourScoreName = "Score:  " + score;
                iter.remove();
            }

        Iterator<Rectangle> iterator = raindrops.iterator();
        while(iterator.hasNext()){
            Rectangle raindrop = iterator.next();
            raindrop.x -= 20 * Gdx.graphics.getDeltaTime();
            if(raindrop.x + 64 < 0) iterator.remove();

            if(raindrop.overlaps(bounds)){
                waterSound.play();
                GameOver = true;

            }
        }

        }

        player.update();
        camera.update();

        batch.setProjectionMatrix(camera.combined);
        batch.begin();
        batch.draw(Background, 0, 0);
        yourBitmapFontName.setColor(1.0f, 1.0f, 1.0f, 1.0f);
        yourBitmapFontName.draw(batch, yourScoreName, 50, 700);
        yourBitmapFontName2.setColor(1.0f, 1.0f, 1.0f, 1.0f);
        yourBitmapFontName2.draw(batch, yourScoreName2, 500, 500);
        batch.draw(bounds1, bounds.x, bounds.y);
        batch.draw(player.getCurrentFrame(), player.getPosition().x, player.getPosition().y);

        for(Rectangle tree: trees){
            batch.draw(Tree, tree.x, tree.y);
        }

        for(Rectangle raindrop: raindrops) {
            batch.draw(dropImage, raindrop.x, raindrop.y);
        }

        batch.end();

    }

    @Override
    public void resize(int width, int height) {
//      camera.resize();
    }

    @Override
    public void pause() {
    }

    @Override
    public void resume() {
    }
}

的Manifest.xml:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.AustinMagnuson.FallingFlame"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
    android:minSdkVersion="15"
    android:targetSdkVersion="15" />

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
</application>

(Android项目,其主要活动包括Java(转换为Android)项目)

MainActivity.Java:

package com.AustinMagnuson.mygdxgame;

import android.os.Bundle;

import com.badlogic.gdx.backends.android.AndroidApplication;
import com.badlogic.gdx.backends.android.AndroidApplicationConfiguration;

public class MainActivity extends AndroidApplication {


    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        AndroidApplicationConfiguration cfg = new AndroidApplicationConfiguration();
        cfg.useGL20 = true;
        cfg.useAccelerometer = false;
        cfg.useCompass = false;

        initialize(new FallingFlame(), cfg);
    }

}

的Manifest.xml:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.AustinMagnuson.mygdxgame"
    android:versionCode="1"
    android:versionName="1.0" >

   <uses-sdk android:minSdkVersion="15" android:targetSdkVersion="15" />

    <application
        android:icon="@drawable/ff_launcher"
        android:label="FireBud" >

        <activity
            android:name=".MainActivity"
            android:label="FireBud"
            android:screenOrientation="landscape"
            android:configChanges="keyboard|keyboardHidden|orientation|screenSize">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

1 个答案:

答案 0 :(得分:0)

检查清单文件 在第一个清单中:

package="com.AustinMagnuson.FallingFlame"

但在FallingFlame.java档案中

package com.AustinMagnuson.mygdxgame;