2

我已经向 Nook 开发者门户网站提交了一个应用程序。它在我根深蒂固的角落颜色和所有不同的模拟器以及 Play 商店中的数千种设备上运行良好。问题是当我提交它时,它无法在他们的任何设备上启动。下面是我的清单和我的启动活动,它说它是由以下原因引起的:java.lang.ClassNotFoundException: com.bfreq.dice.SplashScreen in loader dalvik.system.PathClassLoader[/data/app/com.bfreq.dice-1。 APK]

是找不到我的主类还是找不到 SplashScreen 加载的类?

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.bfreq.dice"
    android:installLocation="auto"
    android:versionCode="11"
    android:versionName="1.0" >

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

    <supports-screens
        android:anyDensity="true"
        android:largeScreens="true"
        android:normalScreens="true"
        android:resizeable="true"
        android:smallScreens="true"
        android:xlargeScreens="true" />

    <meta-data
        android:name="ADMOB_ALLOW_LOCATION_FOR_ADS"
        android:value="true" />

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

    <application
        android:icon="@drawable/icon"
        android:label="@string/app_name" >
        <activity
            android:name=".SplashScreen"
            android:label="@string/app_name"
            android:theme="@style/Theme.Sherlock" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name=".ViewPagerMain"
            android:label="@string/app_name"
            android:theme="@style/Theme.Sherlock"
            android:windowSoftInputMode="stateHidden" >
            <intent-filter>
                <action android:name="com.bfreq.dice.VPM" />

                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>
        <activity
            android:name=".CustomDiceHandler"
            android:label="@string/app_name"
            android:windowSoftInputMode="stateHidden|adjustPan" >
            <intent-filter>
                <action android:name="com.bfreq.dice.CDH" />

                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>
        <activity
            android:name=".AdProvider"
            android:label="@string/app_name"
            android:theme="@android:style/Theme.Wallpaper"
            android:windowSoftInputMode="stateHidden|adjustPan" >
            <intent-filter>
                <action android:name="com.bfreq.dice.ADP" />

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

</manifest>

这是我的启动画面

package com.bfreq.dice;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

import com.actionbarsherlock.app.ActionBar;
import com.actionbarsherlock.app.SherlockActivity;

import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.DialogInterface.OnCancelListener;
import android.content.pm.ActivityInfo;
import android.content.res.Configuration;
import android.os.Bundle;
import android.util.Log;
import android.view.WindowManager;

public class SplashScreen extends SherlockActivity {

    AdProvider adTime = new AdProvider();
    DicePreferences prefs = new DicePreferences();
    static int ori = 0;
    static int time = 1000;
    static boolean firstLoad = true;

    Thread splashThread = new Thread() {
        @Override
        public void run() {
            try {
                int waited = 0;
                while (waited < time) {
                    sleep(100);
                    waited += 100;
                }
                Log.d("Hi", "I'm your thread, you should only see me once");
            } catch (InterruptedException e) {
                // do nothing
            } finally {
                Intent intent = new Intent("com.bfreq.dice.VPM");
                intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                startActivity(intent);
                Log.d("Finished", "I just launch your intent, yay!");
                finish();
            }
        }
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        ActionBar actionbar = getSupportActionBar();
        actionbar.setTitle("D&D Dice");
        actionbar.setSubtitle("by b.freq");
        actionbar.hide();
        this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);

        prefs.loadArrayLists(this);
        prefs.loadStrings(this);
        prefs.loadSettings(this);
        prefs.loadDemo(this);

        if (adTime.getCurrentTime() > ViewPagerMain.endDemo
                && VersionCheck.demo) {
            VersionCheck.demo = false;
            ViewPagerMain.startDemo = 0;
            ViewPagerMain.endDemo = 0;
            prefs.saveDemo(this);
        }
        if (DialogFonts.sizeMain < 10 || DialogFonts.sizeDL < 10) {
            DialogFonts.sizeMain = 20;
            DialogFonts.sizeDL = 15;
            prefs.saveSettings(this);
        }

        // This is for manually changing orientation
        if (firstLoad) {
            prefs.loadOrientation(this);
            ViewPagerMain.ori = ori;
        }
        switch (ViewPagerMain.ori) {
        case 0:
            setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_NOSENSOR);
            break;
        case 1:
            setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
            break;
        case 2:
            setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
            break;
        }

        setContentView(R.layout.splash);

        // Dumping assets into their sdcard
        try {
            copyStream("CustomSheet - BlankSheet.csv", this);
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        // This stops hardware keyboard orientation change
        if (((getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) < 3)
                & (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE)) {
            // setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
            AlertDialog alertDialog = new AlertDialog.Builder(this).create();
            alertDialog.setTitle("Orientation not Supported on your device!!!");
            alertDialog.setMessage("Close your KEYBOARD!!!");
            alertDialog.show();
            alertDialog.setOnCancelListener(new OnCancelListener() {
                @Override
                public void onCancel(DialogInterface dialog) {
                    finish();
                }
            });
        } else {
            splashThread.start();
        }

    }

最后,这是他们发给我的错误日志。

Files: Rejected: NOOK Color, NOOK Tablet, NOOK HD, NOOK HD+
Your app has failed to launch or crashed. Please see the log that is
attached for more information.
1. Install and boot the app.
Result: The app fails to boot and displays the message " Unfortunately,
D&D Dice by b.freq has stopped."

10-10 12:57:50.670 I/ActivityManager(  958): Starting activity: Intent {
act=android.intent.action.MAIN
dat=content://applications/applications/com.bfreq.dice/com.bfreq.dice.SplashScreen
flg=0x14000000
cmp=com.android.providers.applications/.ApplicationLauncher (has extras)
}

10-10 12:57:50.720 I/ApplicationLauncher( 3546): Launching
ComponentInfo{com.bfreq.dice/com.bfreq.dice.SplashScreen}

10-10 12:57:50.732 I/ActivityManager(  958): Starting activity: Intent {
act=android.intent.action.MAIN flg=0x10200000
cmp=com.bfreq.dice/.SplashScreen }

10-10 12:57:50.763 I/SurfaceFlinger(  958):


10-10 12:57:50.763 I/SurfaceFlinger(  958):
SurfaceFlinger::createSurface() : layer->mIdentity=244, LayerName=
Starting com.bfreq.dice

10-10 12:57:50.763 I/SurfaceFlinger(  958):
SurfaceFlinger::createSurface() : layer->clientIndex=1,
surfaceHandle->mToken=0x1

10-10 12:57:50.826 I/ActivityManager(  958): Start proc com.bfreq.dice
for activity com.bfreq.dice/.SplashScreen: pid=5006 uid=10051
gids={1015, 3003}

10-10 12:57:51.092 D/AndroidRuntime( 5006): Shutting down VM

10-10 12:57:51.092 W/dalvikvm( 5006): threadid=1: thread exiting with
uncaught exception (group=0x4001d888)

10-10 12:57:51.105 E/AndroidRuntime( 5006): FATAL EXCEPTION: main

10-10 12:57:51.105 E/AndroidRuntime( 5006): java.lang.RuntimeException:
Unable to instantiate activity
ComponentInfo{com.bfreq.dice/com.bfreq.dice.SplashScreen}:
java.lang.ClassNotFoundException: com.bfreq.dice.SplashScreen in loader
dalvik.system.PathClassLoader[/data/app/com.bfreq.dice-1.apk]

它继续疯狂的很长一段时间......

4

1 回答 1

2

我不会在我的启动画面或任何其他活动中调用睡眠,那段代码有异味。尝试改变它。为什么不使用Handler.postDelayed()如果你使用 sleep 很长一段时间,你可能会得到 ANR。

这很简单,只需执行以下操作。

Runnable splashRunnable = new Runnable() {

    @Override
    public void run() {
        Intent intent = new Intent("com.bfreq.dice.VPM");
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        startActivity(intent);
        finish();
    }
}

在你的 onCreate() 方法中:

new Handler().postDelayed(splashRunnable, SPLASH_DELAY);

现在,你完成了。

还要记住,try catch块不应该用于处理程序逻辑,它应该只用于从问题中恢复。有时可能会有例外,但这种情况是不合适的。

于 2012-10-19T03:27:36.840 回答