libGDX& Google Play游戏服务" java.lang.RuntimeException:无法实例化活动ComponentInfo"

时间:2014-03-14 04:07:28

标签: android libgdx google-play-games

好的,我正试图在我的libGDX游戏中实施Google Play游戏服务。我按照教程:http://helios.hud.ac.uk/u1070589/blog/?p=202

当我在我的nexus上运行我的游戏时,它强制关闭并且logcat给出了这个致命异常:

java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.ggtized.bb/com.ggtized.bb.MainActivity}: java.lang.ClassNotFoundException: Didn't find class "com.ggtized.bb.MainActivity" on path: DexPathList...

没有实现,我的游戏运行正常。但该教程似乎对许多人来说都是成功的,我也想要GPGS。

导致此错误的原因。我不知道..有人可以帮忙,可能会告诉我这是什么问题吗?谢谢你的回复!!

这是我的androidmanifest.xml

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

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

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >

        <meta-data
            android:name="com.google.android.gms.version"
            android:value="@integer/google_play_services_version" />
        <meta-data
            android:name="com.google.android.gms.games.APP_ID"
            android:value="@string/app_id" />


        <activity
            android:name="com.ggtized.bb.MainActivity"
            android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
            android:label="@string/app_name"
            android:screenOrientation="portrait" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name="com.google.android.gms.ads.AdActivity"
            android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" />
    </application>

</manifest>

这是我的主要Android活动:

    package com.ggtized.bb;

import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.RelativeLayout;
import com.badlogic.gdx.backends.android.AndroidApplication;
import com.badlogic.gdx.backends.android.AndroidApplicationConfiguration;
//import com.google.android.gms.ads.AdListener;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdSize;
import com.google.android.gms.ads.AdView;
import com.google.android.gms.games.leaderboard.Leaderboard;
import com.google.android.gms.games.leaderboard.LeaderboardScoreBuffer;
import com.google.android.gms.games.leaderboard.OnLeaderboardScoresLoadedListener;
import com.google.example.games.basegameutils.GameHelper;
import com.google.example.games.basegameutils.GameHelper.GameHelperListener;
import com.ggtized.bb.GoogleInterface;
import com.ggtized.bb.BGame;

public class MainActivity extends AndroidApplication implements
        GameHelperListener, GoogleInterface {
    // ****AdMob
    private AdView adView; // small ad

    // First Ad Code
    private static final String ADCODE = "ca-app-pub-6026787001894298/9413212162";
    // First time an Ad is loaded
    boolean firstTime = true;

    // *************GPGS
    private GameHelper aHelper;

    private OnLeaderboardScoresLoadedListener theLeaderboardListener;

    public MainActivity() {
        aHelper = new GameHelper(this);
        aHelper.enableDebugLog(true, "MYTAG");

        // create a listener for getting raw data back from leaderboard
        theLeaderboardListener = new OnLeaderboardScoresLoadedListener() {

            public void onLeaderboardScoresLoaded(int arg0, Leaderboard arg1,
                    LeaderboardScoreBuffer arg2) {
                System.out.println("In call back");

                for (int i = 0; i < arg2.getCount(); i++) {
                    System.out.println(arg2.get(i).getScoreHolderDisplayName()
                            + " : " + arg2.get(i).getDisplayScore());
                }
            }
        };
    }

    // *************GPGS end

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

        // ****AdMob
        AndroidApplicationConfiguration cfg = new AndroidApplicationConfiguration();
        cfg.useGL20 = false;

        // *************GPGS
        aHelper.setup(this);
        // *************GPGS end

        // initialize(new Game(), cfg);

        this.getWindow().addFlags(
                WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

        final RelativeLayout layout = new RelativeLayout(this);

        requestWindowFeature(Window.FEATURE_NO_TITLE); // no title is needed

        // Do the stuff that initialize() would do for you
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);
        getWindow().clearFlags(
                WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);

        // here we need to create the proper AdViews: one for the banner, and
        // one for the full screen one
        adView = new AdView(this);
        adView.setAdSize(AdSize.SMART_BANNER);
        adView.setAdUnitId(ADCODE); // Put in your secret key here

        // Here we create the instance of the MyApp and we pass it the
        // RequestHandler which implements the IReqHandler interface
        View gameView = initializeForView(new BGame(null, this), cfg);

        // Optionally populate the ad request builder.
        AdRequest adRequest = new AdRequest.Builder()
                .addTestDevice(AdRequest.DEVICE_ID_EMULATOR) // Emulator
                .addTestDevice("775A90563E174E374BC2617A3FD652B1") // testdevice

                .build();

        adView.loadAd(adRequest);

        // Add the libgdx view
        layout.addView(gameView);

        // Add the AdMob view
        final RelativeLayout.LayoutParams adParams = new RelativeLayout.LayoutParams(
                RelativeLayout.LayoutParams.WRAP_CONTENT,
                RelativeLayout.LayoutParams.WRAP_CONTENT);

        adParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
        adParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);

        /*
         * // Setting the ad listener to check if the ad is loaded before adding
         * // view, solves the problem of skipping the first draw
         * adView.setAdListener(new AdListener() {
         * 
         * @Override public void onAdLoaded() {
         * 
         * if (firstTime) { firstTime = false; layout.addView(adView, adParams);
         * } } });
         */
        layout.addView(adView, adParams);

        // Setting the background adview to transparant also solves the problem
        // of skipping the ad draw
        adView.setBackgroundColor(Color.TRANSPARENT);

        // Hook it all up
        setContentView(layout);

        // **************AdMob end


    }

    @Override
    public void onResume() {
        super.onResume();

        if (adView != null) {
            adView.resume();
        }

    }

    @Override
    public void onPause() {

        // Pause the AdView.
        if (adView != null) {
            adView.pause();
        }
        super.onPause();
    }

    /** Called before the activity is destroyed. */
    @Override
    public void onDestroy() {
        // Destroy the AdView.
        if (adView != null) {
            adView.destroy();
        }
        super.onDestroy();
    }

    // ****************GPGS

     @Override
        public void onStart(){
            super.onStart();
            aHelper.onStart(this);
        }

        @Override
        public void onStop(){
            super.onStop();
            aHelper.onStop();
        }

        @Override
        public void onActivityResult(int request, int response, Intent data) {
            super.onActivityResult(request, response, data);
            aHelper.onActivityResult(request, response, data);
        }

        public void onSignInFailed() {
            System.out.println("sign in failed");
        }

        public void onSignInSucceeded() {
            System.out.println("sign in succeeded");
        }

        public void Login() {
            try {
            runOnUiThread(new Runnable(){

                //@Override
                public void run(){
                    aHelper.beginUserInitiatedSignIn();
                }
                });
            }catch (final Exception ex){

            }
        }

        public void LogOut() {
            try {
            runOnUiThread(new Runnable(){

                //@Override
                public void run(){
                    aHelper.signOut();
                }
                });
            }catch (final Exception ex){

            }

        }

        public boolean getSignedIn() {
            return aHelper.isSignedIn();
        }

        public void submitScore(int _score) {
            System.out.println("in submit score");
            aHelper.getGamesClient().submitScore(getString(R.string.leaderBoardID), _score);    
        }

        public void getScores() {
            startActivityForResult(aHelper.getGamesClient().getLeaderboardIntent(getString(R.string.leaderBoardID)), 105);  
        }

        public void getScoresData() {
            aHelper.getGamesClient().loadPlayerCenteredScores(theLeaderboardListener,
                    getString(R.string.leaderBoardID), 
                    1, 
                    1, 
                    25) ;
        }
        // *************GPGS end
}

这是我的主要游戏类

    package com.ggtized.bb;

import com.badlogic.gdx.ApplicationListener;
import com.badlogic.gdx.Game;
import com.ggtized.Screens.SplashScreen;
import com.ggtized.BHelpers.AssetLoader;
import com.ggtized.BHelpers.IReqHandler;

public class BGame extends Game implements ApplicationListener {

    // Code for Ads
    public static IReqHandler ExternalHandler;

    // *****GPGS
    private GoogleInterface platformInterface;

    public BGame(IReqHandler irh, GoogleInterface aInterface) {

        BGame.ExternalHandler = irh;

        platformInterface = aInterface;
        platformInterface.Login();
    }

    @Override
    public void create() {
        AssetLoader.load();
        setScreen(new SplashScreen(this));
    }

    @Override
    public void dispose() {
        super.dispose();
        AssetLoader.dispose();
    }

}

1 个答案:

答案 0 :(得分:0)

我终于找到了解决问题的方法。在你的BaseGameUtils Build Path ---&gt; Librairies中,你通常有一个android-support-v4.jar(或类似的.jar)。从构建路径中删除它(您已经在主应用程序的构建路径中将其删除,在这种情况下似乎存在冲突)。