无论我做什么,我都无法开展新的活动。 我再次重新下载了所有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中的Button Handler
调用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);
}
的Manifest.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);
}
答案 0 :(得分: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()
。