2017-02-16 8 views
1

Meine App stürzt beim Start ab, ohne einen Fehler anzuzeigen.
Ich kann nicht warum finden. Ich habe versucht, viele Lösungen, aber vergeblichMeine Anwendung stürzt beim Start ab

hier ist MainActivity.java

package com.example.android.mycourses; 

import android.os.Bundle; 
import android.support.v7.app.AppCompatActivity; 
import android.widget.CheckBox; 
import android.widget.CompoundButton; 
import android.widget.ListView; 
import android.widget.TextView; 

import com.google.firebase.database.ChildEventListener; 
import com.google.firebase.database.DataSnapshot; 
import com.google.firebase.database.DatabaseError; 
import com.google.firebase.database.DatabaseReference; 
import com.google.firebase.database.FirebaseDatabase; 

import java.util.ArrayList; 

public class MainActivity extends AppCompatActivity { 

    private FirebaseDatabase mfirebasedatabase; //to access the database 
    private DatabaseReference mDatabase; //class references a specific part of the database 
    private ChildEventListener mchildEventListener; //to read from the database 


    TextView courseTV; 
    CheckBox checkbox; 
    CourseAdapter adapter; 


    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 

     mfirebasedatabase=FirebaseDatabase.getInstance();//to instantiate the database(this is the access point to the database) 
     mDatabase=mfirebasedatabase.getReference().child("courses"); 

     courseTV = (TextView) findViewById(R.id.messageTextView); 
     populateUsersList(); 

     checkbox = (CheckBox) findViewById(R.id.checkbox); 
     checkbox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() 
     { 
      public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) 
      { 
       if (isChecked) 
       { 
        // save in database 
        Course cc=new Course(courseTV.getText().toString()); 
        mDatabase.push().setValue(cc); 
       } 
       else if(!isChecked){ 
        //remove from database 
       } 
      } 
     }); 
     mchildEventListener =new ChildEventListener(){ 
      @Override 
     public void onChildAdded(DataSnapshot dataSnapshot, String s) { 
      Course c=dataSnapshot.getValue(Course.class); 
      adapter.add(c); 
     } 

      @Override 
      public void onChildChanged(DataSnapshot dataSnapshot, String s) { 

      } 

      @Override 
      public void onChildRemoved(DataSnapshot dataSnapshot) { 

      } 

      @Override 
      public void onChildMoved(DataSnapshot dataSnapshot, String s) { 

      } 

      @Override 
      public void onCancelled(DatabaseError databaseError) { 

      } 
     }; 
     mDatabase.addChildEventListener(mchildEventListener); 


    } 
    private void populateUsersList() { 
     // Construct the data source 
     ArrayList<Course> arrayOfUsers = Course.getCourses(); 
     // Create the adapter to convert the array to views 
     CourseAdapter adapter = new CourseAdapter(this, arrayOfUsers); 
     // Attach the adapter to a ListView 
     ListView listView = (ListView) findViewById(R.id.listView); 
     listView.setAdapter(adapter); 
    } 
} 

hier ist activity_main.xml

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:paddingBottom="@dimen/activity_vertical_margin" 
    android:paddingLeft="@dimen/activity_horizontal_margin" 
    android:paddingRight="@dimen/activity_horizontal_margin" 
    android:paddingTop="@dimen/activity_vertical_margin" 
    tools:context="com.example.android.mycourses.MainActivity"> 

<ListView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:id="@+id/listView"></ListView> 


</RelativeLayout> 

hier ist item_message.xml

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_marginLeft="@dimen/activity_horizontal_margin" 
    android:layout_marginStart="@dimen/activity_horizontal_margin" 
    android:orientation="vertical"> 

    <TextView 
     android:id="@+id/messageTextView" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_weight="0" 
     android:textAppearance="?android:attr/textAppearanceLarge" 
     tools:text="course" /> 
    <CheckBox 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:id="@+id/checkbox" 
     android:layout_alignRight="@+id/messageTextView"/> 

</RelativeLayout> 

hier was das Protokoll mir zeigt

02-16 16:57:52.515 9095-9095/? I/art: Late-enabling -Xcheck:jni 
    02-16 16:57:52.647 9095-9095/com.example.android.mycourses W/System: ClassLoader referenced unknown path: /data/app/com.example.android.mycourses-1/lib/arm64 
    02-16 16:57:52.686 9095-9095/com.example.android.mycourses I/FA: App measurement is starting up, version: 10084 
    02-16 16:57:52.686 9095-9095/com.example.android.mycourses I/FA: To enable debug logging run: adb shell setprop log.tag.FA VERBOSE 
    02-16 16:57:52.703 9095-9095/com.example.android.mycourses I/FA: To enable faster debug mode event logging run: 
                     adb shell setprop debug.firebase.analytics.app com.example.android.mycourses 
    02-16 16:57:52.712 9095-9095/com.example.android.mycourses I/HwCust: Constructor found for class android.app.HwCustAlarmManagerImpl 
    02-16 16:57:52.722 9095-9095/com.example.android.mycourses I/FirebaseInitProvider: FirebaseApp initialization successful 
    02-16 16:57:52.775 9095-9095/com.example.android.mycourses W/art: Before Android 4.1, method android.graphics.PorterDuffColorFilter android.support.graphics.drawable.VectorDrawableCompat.updateTintFilter(android.graphics.PorterDuffColorFilter, android.content.res.ColorStateList, android.graphics.PorterDuff$Mode) would have incorrectly overridden the package-private method in android.graphics.drawable.Drawable 
    02-16 16:57:52.894 9095-9095/com.example.android.mycourses I/DynamiteModule: Considering local module com.google.android.gms.firebase_database:4 and remote module com.google.android.gms.firebase_database:5 
    02-16 16:57:52.894 9095-9095/com.example.android.mycourses I/DynamiteModule: Selected remote version of com.google.android.gms.firebase_database, version >= 5 
    02-16 16:57:52.911 9095-9095/com.example.android.mycourses W/System: ClassLoader referenced unknown path: /data/user/0/com.google.android.gms/app_chimera/m/00000007/n/arm64-v8a 
    02-16 16:57:52.967 9095-9144/com.example.android.mycourses I/System: core_booster, getBoosterConfig = false 
    02-16 16:57:52.989 9095-9095/com.example.android.mycourses I/Process: Sending signal. PID: 9095 SIG: 9 
+0

Ich glaube nicht, dass Sie wissen, wie 'findViewById' funktioniert ...' findViewById (R.id.checkbox); 'gibt null zurück. Ihre App hat einen Fehler, und es ist eine nullpointerexception –

+0

es zeigt immer einen Fehler .. Wechseln Sie von "Nur ausgewählte Anwendung anzeigen" auf "Kein Filter" bei Android-Monitor. – ZeroOne

Antwort

0

Diese müssen in den Adapter sein, nicht die Aktivität, wenn Sie die App wollen

courseTV = (TextView) findViewById(R.id.messageTextView); 

checkbox = (CheckBox) findViewById(R.id.checkbox); 
checkbox.setOnCheckedChangeListener 

Keines dieser Ansichten activity_main

+0

man ist unglaublich !! Aber könntest du den Rest meines Problems lösen? wenn ich das checkbox in der adapter klasse..wie werde ich das checked item in meiner datenbank speichern? –

+0

Wenn Sie eine andere Frage haben, klicken Sie bitte auf die Schaltfläche [Frage stellen] (// stackoverflow.com/questions/ask). –

+0

Okay danke für deine Hilfe –

2

Versuchen Reinigung Build innen sind auszuführen: (Einstellungen -> Anwendungen -> MyApp -> Speicher -> Daten löschen) ist bekannt, um Probleme mit Klassenladeprogrammen zu beheben.

Andernfalls könnte ein Problem in Ihren XML-Layouts auftreten.

Verwandte Themen