类未定义无参数构造函数.如果您使用的是ProGuard,请确保未剥离这些构造函数 [英] Class does not define a no-argument constructor. If you are using ProGuard, make sure these constructors are not stripped

查看:86
本文介绍了类未定义无参数构造函数.如果您使用的是ProGuard,请确保未剥离这些构造函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在android studio上创建一个聊天应用程序.我的应用程序没有构建错误,我可以启动该应用程序.但是,当我使用listOfMessage.setAdapter(adapter);时,我的应用程序崩溃了.它确实启动了应用程序,但在我说1-2秒之后,它使应用程序崩溃了.在logcat上,我得到了Class does not define a no-argument constructor. If you are using ProGuard, make sure these constructors are not stripped error message.,您能告诉我如何解决这个问题吗?

I am trying to create a chat app on android studio. my app has no build errors and i can start the app. However, when i use listOfMessage.setAdapter(adapter); my app is crashing. it does start the app though, after i would say 1-2 secs it is crashing the app. on logcat, i am getting Class does not define a no-argument constructor. If you are using ProGuard, make sure these constructors are not stripped error message. can you please advise me how to resolve this?

当我不使用listOfMessage.setAdapter(adapter);时,我在应用程序上写下的所有内容都不会显示在listview上,但是我看到条目正在逐步完善.下面的代码:

When i do not use listOfMessage.setAdapter(adapter);, whatever i write down on the app doesn't show on the listview, but i see entries are going through fine to firebase. code below:

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)

推荐答案

我只是失踪了:

public ChatMessage(){}在我的ChatMessage.class上-感谢@Michael为我找到了解决方案.

public ChatMessage(){} on my ChatMessage.class - thanks @Michael for finding me the solution.

这篇关于类未定义无参数构造函数.如果您使用的是ProGuard,请确保未剥离这些构造函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆