0

何をしても新しい活動を始めることができません。すべての Android SDK を再度ダウンロードしました。Eclipse を再ダウンロードし、ADT プラグインを再度インストールしました

エラーログ

09-16 17:53:51.537: W/IInputConnectionWrapper(4661): getCursorCapsMode on inactive InputConnection
09-16 17:53:51.998: D/AndroidRuntime(4661): Shutting down VM
09-16 17:53:51.998: W/dalvikvm(4661): threadid=1: thread exiting with uncaught exception (group=0x41987300)
09-16 17:53:52.022: E/AndroidRuntime(4661): FATAL EXCEPTION: main
09-16 17:53:52.022: E/AndroidRuntime(4661): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.lays.decisong/com.lays.decisong.activities.GameActivity}: java.lang.NullPointerException
09-16 17:53:52.022: E/AndroidRuntime(4661):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1983)
09-16 17:53:52.022: E/AndroidRuntime(4661):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
09-16 17:53:52.022: E/AndroidRuntime(4661):     at android.app.ActivityThread.access$600(ActivityThread.java:130)
09-16 17:53:52.022: E/AndroidRuntime(4661):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
09-16 17:53:52.022: E/AndroidRuntime(4661):     at android.os.Handler.dispatchMessage(Handler.java:99)
09-16 17:53:52.022: E/AndroidRuntime(4661):     at android.os.Looper.loop(Looper.java:137)
09-16 17:53:52.022: E/AndroidRuntime(4661):     at android.app.ActivityThread.main(ActivityThread.java:4745)
09-16 17:53:52.022: E/AndroidRuntime(4661):     at java.lang.reflect.Method.invokeNative(Native Method)
09-16 17:53:52.022: E/AndroidRuntime(4661):     at java.lang.reflect.Method.invoke(Method.java:511)
09-16 17:53:52.022: E/AndroidRuntime(4661):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
09-16 17:53:52.022: E/AndroidRuntime(4661):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
09-16 17:53:52.022: E/AndroidRuntime(4661):     at dalvik.system.NativeStart.main(Native Method)
09-16 17:53:52.022: E/AndroidRuntime(4661): Caused by: java.lang.NullPointerException
09-16 17:53:52.022: E/AndroidRuntime(4661):     at android.content.ContextWrapper.getApplicationInfo(ContextWrapper.java:132)
09-16 17:53:52.022: E/AndroidRuntime(4661):     at android.view.ContextThemeWrapper.getTheme(ContextThemeWrapper.java:65)
09-16 17:53:52.022: E/AndroidRuntime(4661):     at android.app.AlertDialog.resolveDialogTheme(AlertDialog.java:142)
09-16 17:53:52.022: E/AndroidRuntime(4661):     at android.app.AlertDialog.<init>(AlertDialog.java:98)
09-16 17:53:52.022: E/AndroidRuntime(4661):     at android.app.ProgressDialog.<init>(ProgressDialog.java:77)
09-16 17:53:52.022: E/AndroidRuntime(4661):     at android.app.ProgressDialog.show(ProgressDialog.java:110)
09-16 17:53:52.022: E/AndroidRuntime(4661):     at android.app.ProgressDialog.show(ProgressDialog.java:99)
09-16 17:53:52.022: E/AndroidRuntime(4661):     at com.lays.decisong.activities.GameActivity$3.<init>(GameActivity.java:401)
09-16 17:53:52.022: E/AndroidRuntime(4661):     at com.lays.decisong.activities.GameActivity.<init>(GameActivity.java:398)
09-16 17:53:52.022: E/AndroidRuntime(4661):     at java.lang.Class.newInstanceImpl(Native Method)
09-16 17:53:52.022: E/AndroidRuntime(4661):     at java.lang.Class.newInstance(Class.java:1319)
09-16 17:53:52.022: E/AndroidRuntime(4661):     at android.app.Instrumentation.newActivity(Instrumentation.java:1053)
09-16 17:53:52.022: E/AndroidRuntime(4661):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1974)

DecisongApplication.java の公開鍵

public static final String PLAYERS_KEY = "com.lays.decisong.activities.Players";

InputActivity.java のボタン ハンドラ

startActivity() が呼び出されると、アプリが強制終了します

public void startGame(View v) {
    // check if there's more than one player
    if (mPlayers.size() < 2) {
        Log.i(TAG, "Only 1 player");
        Toast.makeText(mContext, "At least 2 players needed to start game",
                Toast.LENGTH_SHORT).show();
        return;
    }

    Intent intent = new Intent(this.getApplicationContext(), GameActivity.class);
    intent.putStringArrayListExtra(DecisongApplication.PLAYERS_KEY, mPlayers);
    startActivity(intent);
    overridePendingTransition(R.anim.slide_up_incoming, R.anim.slide_up_outgoing);
}

マニフェスト.xml

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

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

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

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

<application
    android:name="com.lays.decisong.DecisongApplication"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:screenOrientation="portrait"
    android:theme="@android:style/Theme.NoTitleBar" >
    <activity android:name=".activities.MainActivity" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity
        android:name=".activities.InstructionsActivity"
        android:noHistory="true" />
    <activity
        android:name=".activities.InputActivity"
        android:noHistory="true" />
    <activity
        android:name=".activities.SettingsActivity"
        android:noHistory="true" />
    <activity
        android:name=".activities.GameActivity"
        android:noHistory="true" />
</application>

</manifest>

呼び出されなかった com.lays.decisong.activities の GameActivity.java の onCreate

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_game);

    // init rdio variables
    mTrackQueue = new LinkedList<Track>();
    if (mRdio == null) {
        mRdio = new Rdio(DecisongApplication.RDIO_API_KEY,
                DecisongApplication.RDIO_SECRET_KEY, null, null, this, this);
    }

    // init quiz variables
    mListView = getListView();
    mAllAlbums = new HashMap<String, Album>();
    mChosenTracks = new ArrayList<Track>();
    mAdapter = new TracksAdapter(this, mChosenTracks);
    setListAdapter(mAdapter);

    // init player variables
    mCurrentRoundView = (TextView) findViewById(R.id.current_round);
    mCurrentRound = INITIAL_ROUND;
    mCurrentPlayerView = (TextView) findViewById(R.id.current_player);
    mCurrentPlayer = INITIAL_PLAYER;
    mPlayers = new ArrayList<Player>();
    if (getIntent().hasExtra(DecisongApplication.PLAYERS_KEY)) {
        ArrayList<String> players = getIntent().getStringArrayListExtra(DecisongApplication.PLAYERS_KEY);
        for (String p : players) {
            mPlayers.add(Player.create(p));
        }
    }

    // setup game conditions
    Collections.shuffle(mPlayers);
    mCurrentPlayerView.setText(mPlayers.get(mCurrentPlayer).name);
}
4

1 に答える 1

2
09-16 17:53:52.022: E/AndroidRuntime(4661):     at com.lays.decisong.activities.GameActivity$3.<init>(GameActivity.java:401)
09-16 17:53:52.022: E/AndroidRuntime(4661):     at com.lays.decisong.activities.GameActivity.<init>(GameActivity.java:398)

のコンストラクターでセットアップを実行しようとしているか、アクティビティが完全に初期化さGameActivityれる前にいくつかのフィールドを初期化しようとしているようです。ContextすべてのセットアップはonCreate();で行う必要があります。コンストラクターを使用しないでください。入力Contextされるまで使用できることに依存しないでくださいonCreate()

于 2012-09-16T22:03:24.027 に答える