gpt4 book ai didi

android - 类未定义无参数构造函数。如果您使用 ProGuard,请确保这些构造函数未被剥离

转载 作者:太空宇宙 更新时间:2023-11-03 12:44:12 35 4
gpt4 key购买 nike

我正在尝试在 android studio 上创建一个聊天应用程序。我的应用程序没有构建错误,我可以启动该应用程序。但是,当我使用 listOfMessage.setAdapter(adapter); 时,我的应用程序崩溃了。它确实启动了应用程序,但在我说 1-2 秒后它正在崩溃应用程序。在 logcat 上,我得到 Class does not define a no-argument constructor。如果您使用的是 ProGuard,请确保这些构造函数未被删除错误消息。 您能告诉我如何解决这个问题吗?

当我不使用 listOfMessage.setAdapter(adapter); 时,我在应用程序上写下的任何内容都不会显示在 listview 上,但我看到条目是通过罚款到火力基地。代码如下:

public class MainActivity extends AppCompatActivity {



private static int SIGN_IN_REQUEST_CODE = 1;
private FirebaseListAdapter<ChatMessage> adapter;
RelativeLayout activity_main;
FloatingActionButton sendButton;


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

activity_main =(RelativeLayout)findViewById(R.id.activiy_main);
sendButton = (FloatingActionButton) findViewById(R.id.sendButton);
sendButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
EditText input = (EditText)findViewById(R.id.input);
FirebaseDatabase.getInstance().getReference().push().setValue(new ChatMessage(input.getText().toString(),
FirebaseAuth.getInstance().getCurrentUser().getEmail()));
input.setText("");
}
});


if(FirebaseAuth.getInstance().getCurrentUser() == null) {
startActivityForResult(AuthUI.getInstance().createSignInIntentBuilder().build(), SIGN_IN_REQUEST_CODE);
}
else
{
Snackbar.make(activity_main,"Welcome "+FirebaseAuth.getInstance().getCurrentUser().getEmail(),Snackbar.LENGTH_SHORT).show();
displayChatMessage();
}





}
private void displayChatMessage() {
ListView listOfMessage = (ListView)findViewById(R.id.list_of_message);
adapter = new FirebaseListAdapter<ChatMessage>(this,ChatMessage.class,R.layout.list_item,FirebaseDatabase.getInstance().getReference())
{
@Override
protected void populateView(View v, ChatMessage model, int position) {
TextView messageText, messageUser,messageTime;
messageText = (TextView)v.findViewById(R.id.message_text);
messageUser = (TextView)v.findViewById(R.id.message_user);
messageTime = (TextView)v.findViewById(R.id.message_time);

messageText.setText(model.getMessageText());
messageUser.setText(model.getMessageText());
messageTime.setText(DateFormat.format("dd-MM-yyyy (HH:mm:ss)",model.getMessageTime()));
}
};


//BELOW ONE NEEDS TO BE ACTIVE...TO MAKE ENTRIES VISIBLE

//listOfMessage.setAdapter(adapter);



}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == SIGN_IN_REQUEST_CODE)
{
if(resultCode == RESULT_OK)
{
Snackbar.make(activity_main, "Successfully signed in. Welcome !", Snackbar.LENGTH_SHORT).show();
displayChatMessage();
}
else {
Snackbar.make(activity_main, "we couldn't sign you in. Please try again", Snackbar.LENGTH_SHORT).show();
finish();
}
}
}


@Override
public boolean onOptionsItemSelected(MenuItem item) {
if(item.getItemId() == R.id.menu_sign_out)
{
AuthUI.getInstance().signOut(this).addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
Snackbar.make(activity_main,"You have been signed out..", Snackbar.LENGTH_SHORT).show();
finish();
}
});
}
return true;
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main_menu,menu);
return true;
}

}

ChatMessage.class 如下:

public class ChatMessage {

private String messageText;
private String messageUser;
private long messageTime;

public ChatMessage(String messageText, String messageUser) {
this.messageText = messageText;
this.messageUser = messageUser;

messageTime = new Date().getTime();
}

public ChatMessage(String messageText) {
this.messageText = messageText;
}

public String getMessageText() {
return messageText;
}

public void setMessageText(String messageText) {
this.messageText = messageText;
}

public String getMessageUser() {
return messageUser;
}

public void setMessageUser(String messageUser) {
this.messageUser = messageUser;
}

public long getMessageTime() {
return messageTime;
}

public void setMessageTime(long messageTime) {
this.messageTime = messageTime;
}
}

logcat 上的完整错误:

com.google.firebase.database.DatabaseException: Class com.example.cagrik.chat.ChatMessage does not define a no-argument constructor. If you are using ProGuard, make sure these constructors are not stripped.
at com.google.android.gms.internal.firebase_database.zzku.zza(Unknown Source:44)
at com.google.android.gms.internal.firebase_database.zzkt.zzb(Unknown Source:196)
at com.google.android.gms.internal.firebase_database.zzkt.zza(Unknown Source:0)
at com.google.firebase.database.DataSnapshot.getValue(Unknown Source:10)
at com.firebase.ui.database.FirebaseListAdapter.parseSnapshot(FirebaseListAdapter.java:120)
at com.firebase.ui.database.FirebaseListAdapter.getItem(FirebaseListAdapter.java:109)
at com.firebase.ui.database.FirebaseListAdapter.getView(FirebaseListAdapter.java:137)
at android.widget.AbsListView.obtainView(AbsListView.java:3189)
at android.widget.ListView.makeAndAddView(ListView.java:2197)
at android.widget.ListView.fillDown(ListView.java:824)
at android.widget.ListView.fillFromTop(ListView.java:885)
at android.widget.ListView.layoutChildren(ListView.java:1924)
at android.widget.AbsListView.onLayout(AbsListView.java:2961)
at android.view.View.layout(View.java:20854)
at android.view.ViewGroup.layout(ViewGroup.java:6401)
at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1080)
at android.view.View.layout(View.java:20854)
at android.view.ViewGroup.layout(ViewGroup.java:6401)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323)
at android.widget.FrameLayout.onLayout(FrameLayout.java:261)
at android.view.View.layout(View.java:20854)
at android.view.ViewGroup.layout(ViewGroup.java:6401)
at android.support.v7.widget.ActionBarOverlayLayout.onLayout(ActionBarOverlayLayout.java:443)
at android.view.View.layout(View.java:20854)
at android.view.ViewGroup.layout(ViewGroup.java:6401)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323)
at android.widget.FrameLayout.onLayout(FrameLayout.java:261)
at android.view.View.layout(View.java:20854)
at android.view.ViewGroup.layout(ViewGroup.java:6401)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1791)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1635)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1544)
at android.view.View.layout(View.java:20854)
at android.view.ViewGroup.layout(ViewGroup.java:6401)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323)
at android.widget.FrameLayout.onLayout(FrameLayout.java:261)
at com.android.internal.policy.DecorView.onLayout(DecorView.java:945)
at android.view.View.layout(View.java:20854)
at android.view.ViewGroup.layout(ViewGroup.java:6401)
at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:2956)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2643)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1780)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:7827)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:911)
at android.view.Choreographer.doCallbacks(Choreographer.java:723)
at android.view.Choreographer.doFrame(Choreographer.java:658)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:897)
at android.os.Handler.handleCallback(Handler.java:789)
at android.os.Handler.dispatchMessage(Handler.java:98)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6944)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)

最佳答案

这已经晚了,但可能会在将来帮助某人 Kotlin

**change your from**

data class ChatMessage(
var messageText: String?,
var messageUser: String?,
var messageTime: Long?)

对此

data class ChatMessage(
var messageText: String? = "",
var messageUser: String? = "",
var messageTime: Long? = 0)

关于android - 类未定义无参数构造函数。如果您使用 ProGuard,请确保这些构造函数未被剥离,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52162502/

35 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com