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 回答