我是相當新的Android和應用程序創建後立即關閉。任何幫助將不勝感激!Android應用程序關閉創建?
一些關於該應用程序,我創建一個基於文本的冒險,我把所有的代碼編碼到Java已經,我知道了Java代碼的工作,因爲我有一個JavaGui創建和它的工作。我現在試圖把這個java遊戲帶到android。
這是我的錯誤日誌
05-29 09:19:01.989: E/AndroidRuntime(539): FATAL EXCEPTION: main
05-29 09:19:01.989: E/AndroidRuntime(539): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.coalbolttproductions.russell/com.coalbolttproductions.russell.AdventureToCandyIslandActivity}: java.lang.NullPointerException
05-29 09:19:01.989: E/AndroidRuntime(539): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1880)
05-29 09:19:01.989: E/AndroidRuntime(539): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
05-29 09:19:01.989: E/AndroidRuntime(539): at android.app.ActivityThread.access$600(ActivityThread.java:123)
05-29 09:19:01.989: E/AndroidRuntime(539): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
05-29 09:19:01.989: E/AndroidRuntime(539): at android.os.Handler.dispatchMessage(Handler.java:99)
05-29 09:19:01.989: E/AndroidRuntime(539): at android.os.Looper.loop(Looper.java:137)
05-29 09:19:01.989: E/AndroidRuntime(539): at android.app.ActivityThread.main(ActivityThread.java:4424)
05-29 09:19:01.989: E/AndroidRuntime(539): at java.lang.reflect.Method.invokeNative(Native Method)
05-29 09:19:01.989: E/AndroidRuntime(539): at java.lang.reflect.Method.invoke(Method.java:511)
05-29 09:19:01.989: E/AndroidRuntime(539): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
05-29 09:19:01.989: E/AndroidRuntime(539): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
05-29 09:19:01.989: E/AndroidRuntime(539): at dalvik.system.NativeStart.main(Native Method)
05-29 09:19:01.989: E/AndroidRuntime(539): Caused by: java.lang.NullPointerException
05-29 09:19:01.989: E/AndroidRuntime(539): at android.app.Activity.findViewById(Activity.java:1794)
05-29 09:19:01.989: E/AndroidRuntime(539): at com.coalbolttproductions.russell.AdventureToCandyIslandActivity.<init>(AdventureToCandyIslandActivity.java:15)
05-29 09:19:01.989: E/AndroidRuntime(539): at java.lang.Class.newInstanceImpl(Native Method)
05-29 09:19:01.989: E/AndroidRuntime(539): at java.lang.Class.newInstance(Class.java:1319)
05-29 09:19:01.989: E/AndroidRuntime(539): at android.app.Instrumentation.newActivity(Instrumentation.java:1023)
05-29 09:19:01.989: E/AndroidRuntime(539): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1871)
05-29 09:19:01.989: E/AndroidRuntime(539): ... 11 more
這是我的main.xml,我認爲是我的問題
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:padding="25dp">
<EditText
android:id="@+id/etCommands"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="Type a Command"
android:password="true" />
<Button
android:id="@+id/bResults"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Try Command" />
<TextView
android:id="@+id/tvResults"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="TextView" />
</LinearLayout>
由於這裏大衆需求的真正原因是從Java代碼我冒險類。 線15按鈕chkCmd
public class AdventureToCandyIslandActivity extends Activity implements View.OnClickListener{
/** Called when the activity is first created. */
Button chkCmd = (Button) findViewById(R.id.bResults);
EditText input;
TextView display;
Game gameModel;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//Run the methods
createVars();
chkCmd.setOnClickListener(this);
}
private void createVars(){
gameModel = new Game();
input = (EditText) findViewById(R.id.etCommands);
display = (TextView) findViewById(R.id.tvResults);
display.setText(gameModel.printWelcome());
display.setGravity(Gravity.LEFT);
display.setTextColor(Color.WHITE);
}
public void onClick(View v) {
String inputLine = input.getText().toString();
Command command = Command.getCommand(inputLine);
String result = gameModel.processCommand(command);
if(result.equals("EXIT")) {
System.exit(0);
} else {
display.append("--------------------------------\n" + result + "\n");
}
}
}
在這裏添加Java代碼,請。 – Sajmon
作爲堆棧跟蹤說,活動'AdventureToCandyIslandActivity'失敗,因爲一個空指針的地方開始。如果你能從這裏顯示代碼,它會幫助我們很多。 – Cheesebaron
'AdventureToCandyIslandActivity.java'看行沒有15 –