2017-02-16 9 views
1

起動時にエラーが表示されずにアプリケーションがクラッシュします。
理由が見つかりません。私は多くのソリューションを試してみましたが、無駄起動時にアプリケーションがクラッシュする

でここ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); 
    } 
} 

は、ここでは、ここで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> 

はここ

<?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> 

item_message.xmlされているされていますログに表示される内容

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

'findViewById'の仕組みが分からないと思います...' findViewById(R.id.checkbox); 'はnullを返します。あなたのアプリにはエラーがあり、それはnullpointerexception –

+0

で、常にエラーを表示します。アンドロイドモニタで「選択したアプリケーションのみを表示」から「フィルタなし」に切り替えます。 – ZeroOne

答えて

0

これらのアプリは、どちらもそれらのビューの

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

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

を実行したい場合は、アダプタではなく、活動にする必要が

+0

男u r素晴らしい!私の問題の残りの部分を解決することができますか?私はアダプタクラスにチェックボックスを入れます。どのように私は私のデータベースにチェックされた項目を保存しますか? –

+0

別の質問がある場合は、[Ask Question](// stackoverflow.com/questions/ask)ボタンをクリックして質問してください。 –

+0

よろしくお願いします –

2

activity_main内部のあるビルドをクリーニングしてみてください:([設定] - >アプリケーション - > MyApp - > Memory - > Clear Data)は、クラスローダーの問題を解決することが知られています。

それ以外の場合は、XMLレイアウトに問題がある可能性があります。

関連する問題