2
好的,所以我試圖在我的libGDX遊戲中實現Google Play遊戲服務。我跟着教程這裏:http://helios.hud.ac.uk/u1070589/blog/?p=202libGDX&Google Play遊戲服務「java.lang.RuntimeException:無法實例化活動ComponentInfo」
,當我在我的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();
}
}
您是否在使用任何外部jar文件? –
謝謝你的幫助。我確實有一些與gdx和補間引擎相關的外部jar文件。沒有與谷歌玩遊戲服務有關的罐子。就像我說過的,如果沒有代碼來實現谷歌玩遊戲服務,遊戲就能正常運行。我錯過了什麼? :( – user3412786