2010-12-22 6 views
0

Ich versuche, eine einfache Android-App zu entwickeln, im Querformat behoben. Ich verwende Eclipse 1.3, kompiliere für Android SDK Version 7 (OS Version 2.1). Wenn ich versuche, es im Emulator auszuführen, stürzt es beim Booten ab. (Es kommt so weit wie der Entsperren-Schieberegler, aber kurz danach, wenn ich versuche, die Anwendung selbst zu starten, bekomme ich "Die Anwendung fehlgeschlagen (Prozess com.wcs.failtest) wurde unerwartet gestoppt. Bitte versuchen Sie es erneut.".)Hello-Weltklasse-Landschaft Android-App startet nicht (vollständiger Code enthalten)

hier

ist main.xml (mit den Tags entkam so dass diese korrekt angezeigt):


<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="horizontal" 
    android:layout_width="480px" 
    android:layout_height="320px" 
    > 
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="96px" 
    android:layout_height="320px" 
    android:id="@+id/action_menu" 
    > 
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     android:orientation="horizontal" 
     android:layout_width="96px" 
     android:layout_height="48px" 
     > 
     <Button 
     android:layout_width="48px" 
     android:layout_height="48px" 
     android:background="#f00" 
     android:id="@+id/action_button_11" 
     /> 
    </LinearLayout> 
    </LinearLayout> 
</LinearLayout> 

hier AndroidManifest.xml ist (wieder mit den Tags entkam so dass diese korrekt angezeigt):


<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
     package="com.wcs.failtest" 
     android:versionCode="1" 
     android:versionName="1.0"> 
    <application android:icon="@drawable/icon" android:label="@string/app_name" android:theme="@android:style/Theme.NoTitleBar.Fullscreen"> 
     <activity android:name=".FailtestActivity" 
        android:screenOrientation="landscape" 
        android:label="@string/app_name"> 
      <intent-filter> 
       <action android:name="android.intent.action.MAIN" /> 
       <category android:name="android.intent.category.LAUNCHER" /> 
      </intent-filter> 
     </activity> 
    </application> 
    <uses-sdk android:minSdkVersion="7" /> 
</manifest> 

Und hier ist FailtestActivity.java:


package com.wcs.failtest; 

import android.app.Activity; 
import android.os.Bundle; 
import android.widget.Button; 
import android.view.View.OnClickListener; 
import android.view.View; 

public class FailtestActivity extends Activity { 
    private OnClickListener action11Listener = new OnClickListener() { 
     public void onClick(View v) { 
     } 
    }; 

    /** Called when the activity is first created. */ 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     Button button; 
     button = (Button)findViewById(R.id.action_button_11); 
     button.setOnClickListener(action11Listener); 
     setContentView(R.layout.main); 
    } 
} 

Ich vermute, es ist etwas einfaches, das ich übersehe. Was ist es?

+0

Wenn eine App abstürzt, müssen Sie die logcat auszusenden. Das erklärt normalerweise genau, was vor sich geht. – EboMike

+0

Verwenden Sie 'adb logcat', DDMS oder die DDMS-Perspektive in Eclipse, um LogCat zu untersuchen und die mit Ihrem Absturz verknüpfte Stack-Ablaufverfolgung anzuzeigen. Außerdem benötigen Sie nur einen "android: xmlns" -Eintrag auf Ihrem Root-Element, nicht drei. – CommonsWare

Antwort

4

Versuchen:

public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 
     //setup button... 
+1

Yup, Sie verwenden eine Ansicht (R.id.action_button_11), bevor Sie sogar Ihre Benutzeroberfläche erstellen. 'button' ist null und Sie erhalten wahrscheinlich eine NullPointerException. – EboMike

+0

Danke! Das hat es getan. Ich dachte, es wäre so einfach. – WingedCat