Android Merkwürdigkeiten im Layout

tobi193

Aktives Mitglied
Hallo,

ich bin gerade dabei eine Android App zu programmieren. Dabei hänge ich aber gerade an einer sehr verrückten Sache.
Mein Main-Layout besitzt gerade einen Button, den ich dort nicht mehr benötige. Er hat keinerlei Funktionen und es wird auch nirgends (Ich habe es 20mal überprüft) im Quelltext irgendetwas mit diesem Button angestellt.
Nun will ich diesen Button natürlich gerne löschen, aber sobald ich dies tue, crasht die App sofort beim start auf meinem Galaxy S Plus (per USB-Debugging ausgeführt). Ich kann den Button auch umbenennen und sonst was damit tun, wenn er aber weg ist, dann crasht die App.

Was kann dafür verantwortlich sein?

Das Layout sieht so aus (Es geht um den Button "fbdasdfasdf"):

HTML:
<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@drawable/light">
        
    <ImageView
    android:id="@+id/top"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginBottom="15sp"
    android:src="@drawable/logo"
    android:layout_gravity="center_horizontal" />

    <TextView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:textColor="#000000"
    android:text="Titel Beschreibung"/>
        
    <ImageButton
    android:id="@+id/activate"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:onClick="setAlarm"
    android:background="@drawable/aktivieren" />
    
    <Button android:id="@+id/timepicker"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:onClick="pickTime"
    android:text="Zeit auswählen" />
    
    <Button android:id="@+id/fbdasdfasdf"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />
    
    <Button android:id="@+id/recorder"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:onClick="recordAudio"
    android:text="Recorder" />

    <ImageButton
    android:id="@+id/fb"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:onClick="fb_login"
    android:background="@drawable/facebook" />
    
    <TextView
    android:id="@+id/fbtext"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="du bist nicht eingeloggt"/>

</LinearLayout>
 

tobi193

Aktives Mitglied
06-10 22:17:10.908: ERROR/AndroidRuntime(3519): FATAL EXCEPTION: main
06-10 22:17:10.908: ERROR/AndroidRuntime(3519): java.lang.RuntimeException: Unable to start activity ComponentInfo{org.me.badmorning/org.me.badmorning.MainActivity}: java.lang.NullPointerException
06-10 22:17:10.908: ERROR/AndroidRuntime(3519): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1651)
06-10 22:17:10.908: ERROR/AndroidRuntime(3519): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
06-10 22:17:10.908: ERROR/AndroidRuntime(3519): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
06-10 22:17:10.908: ERROR/AndroidRuntime(3519): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
06-10 22:17:10.908: ERROR/AndroidRuntime(3519): at android.os.Handler.dispatchMessage(Handler.java:99)
06-10 22:17:10.908: ERROR/AndroidRuntime(3519): at android.os.Looper.loop(Looper.java:130)
06-10 22:17:10.908: ERROR/AndroidRuntime(3519): at android.app.ActivityThread.main(ActivityThread.java:3687)
06-10 22:17:10.908: ERROR/AndroidRuntime(3519): at java.lang.reflect.Method.invokeNative(Native Method)
06-10 22:17:10.908: ERROR/AndroidRuntime(3519): at java.lang.reflect.Method.invoke(Method.java:507)
06-10 22:17:10.908: ERROR/AndroidRuntime(3519): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
06-10 22:17:10.908: ERROR/AndroidRuntime(3519): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
06-10 22:17:10.908: ERROR/AndroidRuntime(3519): at dalvik.system.NativeStart.main(Native Method)
06-10 22:17:10.908: ERROR/AndroidRuntime(3519): Caused by: java.lang.NullPointerException
06-10 22:17:10.908: ERROR/AndroidRuntime(3519): at org.me.badmorning.MainActivity.onStart(MainActivity.java:50)
06-10 22:17:10.908: ERROR/AndroidRuntime(3519): at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1129)
06-10 22:17:10.908: ERROR/AndroidRuntime(3519): at android.app.Activity.performStart(Activity.java:3791)
06-10 22:17:10.908: ERROR/AndroidRuntime(3519): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1624)
06-10 22:17:10.908: ERROR/AndroidRuntime(3519): ... 11 more
06-10 22:17:10.918: ERROR/(183): Dumpstate > /data/log/dumpstate_app_error


In Zeile 50 in MainActivity steht:
((TextView) this.findViewById(R.id.fbtext)).setText("Du bist nicht eingeloggt");

Das hat damit jedoch recht wenig zu tun.
 

tobi193

Aktives Mitglied
Java:
    @Override public void onCreate(Bundle icicle) {
        super.onCreate(icicle);
        FileSystem.getInstance(this);
        Fb.getInstance(this, MainActivity.this);
        sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this);
        hour = sharedPrefs.getInt("hour", 0);
        minute = sharedPrefs.getInt("minute", 0);
        this.setContentView(R.layout.main);
    }
    
    @Override public void onStart(){
        super.onStart();
        if(Fb.getInstance().login()){
            ((TextView) this.findViewById(R.id.fbtext)).setText("Eingeloggt als " + Fb.getInstance().getName() + " (" + Fb.getInstance().getId() + ")");
        }else{
            ((TextView) this.findViewById(R.id.fbtext)).setText("Du bist nicht eingeloggt");
        }
    }
 

schlingel

Gesperrter Benutzer
Und die Exception ist noch immer die gleiche?

Oben hast du geschrieben, dass da noch irgend etwas mit den Views passiert. AUßerdem: Welchen Sinn hat der Code im onStart?

Wenn du auf Activity-Stopps reagieren möchtest, wäre der Code im onResume mehr angebracht da er so auch nach einem onPause und nicht nur nach einem onRestart ausgeführt wird.
 

tobi193

Aktives Mitglied
im onStart wird einfach überprüft, ob man noch eingeloggt ist. Das soll bei jedem neu öffnen das App passieren. Aber da wäre natürlich tatsächlich onResume wohl besser.

Mit den Views passiert nichts. Das Problem ist ja der Button, den ich nicht entfernen kann. Mit dem wird nirgends irgendetwas angestellt im Quelltext.
 

schlingel

Gesperrter Benutzer
So ganz kann ich das nicht glauben. Hast du schon ein Project -> Clean gemacht?

Ich hatte schon ein paar Mal das Problem, dass die Resourcen nicht neu kompiliert wurden und dann auch immer so seltsame NPEs geflogen sind.

Wenn's das nicht war, poste einmal den gesamten Code der Activity und des Layouts (falls sich das verändert hat) und die neueste Exception.
 
Ähnliche Java Themen
  Titel Forum Antworten Datum
W Ausklappbares Verlängertes XML Layout Android & Cross-Platform Mobile Apps 6
W Android Wieso kann ich keine ListView mehr zum Layout hinzufügen? Android & Cross-Platform Mobile Apps 1
A Android-Studio: 2. Layout nach kurzer Zeit aufzeigen Android & Cross-Platform Mobile Apps 2
S Android Layout - welchen Typ? Android & Cross-Platform Mobile Apps 3
B Android Multiple Screens- layout-sw600dp Android & Cross-Platform Mobile Apps 1
D Android Layout für alle Geräte Android & Cross-Platform Mobile Apps 4
W Android Designfrage / Layout / Activity / Fragments Android & Cross-Platform Mobile Apps 2
B Layout Bibliothek Android & Cross-Platform Mobile Apps 8
B Android Spiele-Layout umsetzen Android & Cross-Platform Mobile Apps 5
O zurück Schaltfläche in voriges Layout Android & Cross-Platform Mobile Apps 5
B Erste Android-App: setContentView(R.layout.main) funktioniert nicht Android & Cross-Platform Mobile Apps 6
D Android Viele Buttons und ein Layout Android & Cross-Platform Mobile Apps 6
M Android Game, welche Layout? Android & Cross-Platform Mobile Apps 2
B Eigene View xml-Layout einbinden Android & Cross-Platform Mobile Apps 1
R Android Layout Bild mit Text Android & Cross-Platform Mobile Apps 13
K Rand bei (Table,Relative,Linear)Layout - wie bekomme ich ihn weg? Android & Cross-Platform Mobile Apps 3
D Android Layout Problem Android & Cross-Platform Mobile Apps 2
P Android Nach Animation Layout auf alten Platz Android & Cross-Platform Mobile Apps 3
T Android Layout Update Animation Android & Cross-Platform Mobile Apps 3
P Probleme mit xml-Layout Android & Cross-Platform Mobile Apps 2
W XML Layout: wann wird geladen? Android & Cross-Platform Mobile Apps 10
F Layout mit listViews (Scrolling-Probleme) Android & Cross-Platform Mobile Apps 2
G Fehlermeldung: "No XML content. Please add a root view or layout to your documet." Android & Cross-Platform Mobile Apps 7
N Android xml - graphical layout nur noch weiß :o Android & Cross-Platform Mobile Apps 4
JAVAnnik Android Layout ändern in Thread Android & Cross-Platform Mobile Apps 2
A Android Browser öffnen, XML-GUI-Layout Android & Cross-Platform Mobile Apps 23
A Absolute Layout soll auf jedem Gerät gleich aussehen Android & Cross-Platform Mobile Apps 4
S Android Layout Problem mit fill_parent Android & Cross-Platform Mobile Apps 5
tfa Android Layout-Probleme: View programmatisch erweitern (addContentView) Android & Cross-Platform Mobile Apps 7

Ähnliche Java Themen

Neue Themen


Oben