當我在Firebase適配器UI中收到消息時,ChatActivity崩潰。當我將它設置爲simple_list_item_1
佈局時,它可以正常工作,但是當我設置了兩個或更多個屬性時,應用程序會在收到消息時崩潰。當我設置FirebaseAdapterUI時,應用程序崩潰
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.TextView;
import com.firebase.ui.database.FirebaseListAdapter;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
public class ProfileAcrivity extends AppCompatActivity {
Button log_out;
FirebaseAuth firebaseAuth;
DatabaseReference databaseReference;
Button send;
EditText messgae;
ListView messagelist;
FirebaseListAdapter<Chat>firebaseListAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_profile_acrivity);
firebaseAuth = FirebaseAuth.getInstance();
log_out = (Button) findViewById(R.id.log_out);
send= (Button) findViewById(R.id.send);
messgae= (EditText) findViewById(R.id.mess_text);
messagelist= (ListView) findViewById(R.id.mess_list);
if (firebaseAuth.getCurrentUser() == null) {
finish();
startActivity(new Intent(getApplicationContext(), Login.class));
}
databaseReference= FirebaseDatabase.getInstance().getReference().child("group");
log_out.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
logout();
}
});
send.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
messageSend();
}
});
messageRecieved();
}
void logout() {
firebaseAuth.signOut();
finish();
startActivity(new Intent(getApplicationContext(), Login.class));
}
void messageSend()
{
databaseReference.push().setValue(new Chat(messgae.getText().toString(),firebaseAuth.getCurrentUser().getEmail()));
messgae.setText(" ");
}
void messageRecieved()
{
firebaseListAdapter=new FirebaseListAdapter<Chat>(this,Chat.class,android.R.layout.two_line_list_item,databaseReference) {
@Override
protected void populateView(View v, Chat model, int position) {
((TextView) v.findViewById(android.R.id.text1)).setText(model.getName());
((TextView) v.findViewById(android.R.id.text2)).setText(model.getMessage());
}
};
messagelist.setAdapter(firebaseListAdapter);
}
}
這是我Chat.java文件
public class Chat {
String message;
String name;
//String time;
public Chat(String message,String user)
{
this.message=message;
this.name=user;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
堆棧跟蹤:
02-10 01:15:07.106 15809-15809/a52.puri.fbkunal.com.firebase E/AndroidRuntime: FATAL EXCEPTION: main
Process: a52.puri.fbkunal.com.firebase, PID: 15809
com.google.firebase.database.DatabaseException: Class a52.puri.fbkunal.com.firebase.Chat is missing a constructor with no arguments
at com.google.android.gms.internal.zzbqi$zza.zze(Unknown Source)
at com.google.android.gms.internal.zzbqi$zza.zzaG(Unknown Source)
at com.google.android.gms.internal.zzbqi.zze(Unknown Source)
at com.google.android.gms.internal.zzbqi.zzb(Unknown Source)
at com.google.android.gms.internal.zzbqi.zza(Unknown Source)
at com.google.firebase.database.DataSnapshot.getValue(Unknown Source)
at com.firebase.ui.database.FirebaseListAdapter.parseSnapshot(FirebaseListAdapter.java:127)
at com.firebase.ui.database.FirebaseListAdapter.getItem(FirebaseListAdapter.java:116)
at com.firebase.ui.database.FirebaseListAdapter.getView(FirebaseListAdapter.java:146)
at android.widget.AbsListView.obtainView(AbsListView.java:2306)
at android.widget.ListView.makeAndAddView(ListView.java:1811)
at android.widget.ListView.fillDown(ListView.java:697)
at android.widget.ListView.fillFromTop(ListView.java:763)
at android.widget.ListView.layoutChildren(ListView.java:1627)
at android.widget.AbsListView.onLayout(AbsListView.java:2162)
at android.view.View.layout(View.java:14981)
at android.view.ViewGroup.layout(ViewGroup.java:4790)
at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1055)
at android.view.View.layout(View.java:14981)
at android.view.ViewGroup.layout(ViewGroup.java:4790)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:453)
at android.widget.FrameLayout.onLayout(FrameLayout.java:388)
at android.view.View.layout(View.java:14981)
at android.view.ViewGroup.layout(ViewGroup.java:4790)
at android.support.v7.widget.ActionBarOverlayLayout.onLayout(ActionBarOverlayLayout.java:437)
at android.view.View.layout(View.java:14981)
at android.view.ViewGroup.layout(ViewGroup.java:4790)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:453)
at android.widget.FrameLayout.onLayout(FrameLayout.java:388)
at android.view.View.layout(View.java:14981)
at android.view.ViewGroup.layout(ViewGroup.java:4790)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1671)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1525)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1434)
at android.view.View.layout(View.java:14981)
at android.view.ViewGroup.layout(ViewGroup.java:4790)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:453)
at android.widget.FrameLayout.onLayout(FrameLayout.java:388)
at android.view.View.layout(View.java:14981)
at android.view.ViewGroup.layout(ViewGroup.java:4790)
at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:1998)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1753)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1006)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5652)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:761)
at android.view.Choreographer.doCallbacks(Choreographer.java:574)
at android.view.Choreographer.doFrame(Choreographer.java:544)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:747)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5433)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1268)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1084)
at dalvik.system.NativeStart.main(Native Method)
02-10 01:15:11.770 15809-15850/a52.puri.fbkunal.com.firebase W/DynamiteModule: Local module descriptor class for com.google.firebase.auth not found.
如果你的應用程序崩潰,你的logcat中會有一個堆棧跟蹤。請編輯您的問題以包含該堆棧跟蹤。 –
我包含堆棧跟蹤 –
讀取堆棧跟蹤真的會幫助您節省時間來到StackOverflow ...'聊天缺少一個無參數的構造函數' –