Модераторы: javastic
  

Поиск:

Ответ в темуСоздание новой темы Создание опроса
> Вылетает чат-приложение Android 
:(
    Опции темы
OlgaSafronova
Дата 19.5.2020, 00:04 (ссылка) | (нет голосов) Загрузка ... Загрузка ... Быстрая цитата Цитата


Новичок



Профиль
Группа: Участник
Сообщений: 1
Регистрация: 18.5.2020

Репутация: нет
Всего: нет



Здравствуйте. Почему-то при нажатии на кнопку отправки сообщения вылетает чат, который я делаю по туториалу. Можете подсказать причину? Заранее спасибо.

Код:

Код

package Karasik.com;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import com.firebase.ui.auth.AuthUI;
import com.firebase.ui.database.FirebaseListAdapter;
import com.firebase.ui.database.FirebaseListOptions;
import com.google.android.material.floatingactionbutton.FloatingActionButton;
import com.google.android.material.snackbar.Snackbar;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.database.FirebaseDatabase;
import android.text.format.DateFormat;

public class MainActivity extends AppCompatActivity {

private static int SIGN_IN_CODE=1;
private RelativeLayout activity_main;
private FirebaseListAdapter<Message> adapter;
private FloatingActionButton sendBtn;

    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if(requestCode==SIGN_IN_CODE) {
           if(requestCode == RESULT_OK) {
               Snackbar.make(activity_main, "Вы авторизованы", Snackbar.LENGTH_LONG).show();
               displayAllMessages();
               } else {
                 Snackbar.make(activity_main, "Вы не авторизованы", Snackbar.LENGTH_LONG).show();
                 finish();
           }
        }
    }

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

        activity_main=findViewById(R.id.activity_main);
        sendBtn = findViewById(R.id.btnSend);
        sendBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                EditText textField = findViewById(R.id.messageField);
                if(textField.getText().toString()=="")
                    return;
                FirebaseDatabase.getInstance().getReference().push().setValue(new Message(FirebaseAuth.getInstance().getCurrentUser().getEmail(), textField.getText().toString()));
                textField.setText("");
            }
        });

        //Пользователь ещё не авторизован
        if (FirebaseAuth.getInstance().getCurrentUser()==null)
            startActivityForResult(AuthUI.getInstance().createSignInIntentBuilder().build(), SIGN_IN_CODE);
        //Пользователь авторизован
        else {
            Snackbar.make(activity_main, "Вы авторизованы", Snackbar.LENGTH_LONG).show();
            displayAllMessages();
        }
    }

    private void displayAllMessages() {
        ListView listOfMessages = findViewById(R.id.list_of_messages);
        FirebaseListOptions<Message> options =
                new FirebaseListOptions.Builder<Message>()
                        .setQuery(FirebaseDatabase.getInstance().getReference(), Message.class)
                        .setLayout(R.layout.list_item)
                        .build();
        adapter = new FirebaseListAdapter<Message>(options){
            @Override
            protected void populateView(View v, Message model, int position) {
                TextView mess_user, mess_time, mess_text;
                mess_user = v.findViewById(R.id.message_user);
                mess_time = v.findViewById(R.id.message_time);
                mess_text = v.findViewById(R.id.message_text);

                mess_user.setText(model.getUserName());
                mess_text.setText(model.getTextMessage());
                mess_time.setText(DateFormat.format("dd-MM-yyyy HH:mm:ss", model.getMessageTime()));
            }
        };
        listOfMessages.setAdapter(adapter);
    }
}


Класс Message:

Код

package Karasik.com;

import java.util.Date;

public class Message {
    public String UserName;
    public String TextMessage;
    private long MessageTime;

    public Message() {}
    public Message (String UserName, String TextMessage){
        this.UserName = UserName;
        this.TextMessage = TextMessage;

        this.MessageTime = new Date().getTime();
    }

    public String getUserName() {
        return UserName;
    }

    public void setUserName(String userName) {
        UserName = userName;
    }

    public String getTextMessage() {
        return TextMessage;
    }

    public void setTextMessage(String textMessage) {
        TextMessage = textMessage;
    }

    public long getMessageTime() {
        return MessageTime;
    }

    public void setMessageTime(long messageTime) {
        MessageTime = messageTime;
    }
}


Дизайн XML:

Код

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity"
    android:id="@+id/activity_main">

    <com.google.android.material.floatingactionbutton.FloatingActionButton
        android:id="@+id/btnSend"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:clickable="true"
        android:src="@drawable/ic_send_button"
        android:layout_alignParentBottom="true"
        android:layout_alignParentEnd="true"
        app:fabSize="normal">
    </com.google.android.material.floatingactionbutton.FloatingActionButton>

    <com.google.android.material.textfield.TextInputLayout
        android:id="@+id/text_layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentStart="true"
        android:layout_toLeftOf="@id/btnSend"
    >
        <EditText
            android:id="@+id/messageField"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint=" Сообщение"
        />
    </com.google.android.material.textfield.TextInputLayout>

    <ListView
        android:id="@+id/list_of_messages"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_above="@id/text_layout"
        android:layout_alignParentTop="true"
        android:layout_alignParentStart="true"
        android:divider="@android:color/transparent"
        android:dividerHeight="25px"
        android:layout_marginBottom="25px">
    </ListView>

</RelativeLayout>


Gradle:

Код

apply plugin: 'com.android.application'

android {
    compileSdkVersion 29
    buildToolsVersion "29.0.3"

    defaultConfig {
        applicationId "Karasik.com"
        minSdkVersion 21
        targetSdkVersion 29
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }

}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'androidx.appcompat:appcompat:1.1.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test.ext:junit:1.1.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
    implementation 'com.google.firebase:firebase-analytics:17.4.1'
    implementation 'com.android.support:design:29.0.0'
    implementation 'com.google.firebase:firebase-auth:19.3.1'
    implementation 'com.google.firebase:firebase-database:19.3.0'
    implementation 'com.firebaseui:firebase-ui:6.2.0'
    implementation 'com.google.android.gms:play-services-auth:18.0.0'
    implementation 'com.firebaseui:firebase-ui-auth:6.2.0'
    implementation 'com.firebaseui:firebase-ui-database:6.2.0'

}
apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'


Ошибки из Run:
Код

E/eglCodecCommon: glUtilsParamSize: unknow param 0x000082da
    glUtilsParamSize: unknow param 0x000082da
...
E/AndroidRuntime: FATAL EXCEPTION: main
    Process: Karasik.com, PID: 14267
    com.google.firebase.database.DatabaseException: Found two getters or fields with conflicting case sensitivity for property: textmessage
        at com.google.firebase.database.core.utilities.encoding.CustomClassMapper$BeanMapper.addProperty(com.google.firebase:firebase-database@@19.3.0:557)
        at com.google.firebase.database.core.utilities.encoding.CustomClassMapper$BeanMapper.<init>(com.google.firebase:firebase-database@@19.3.0:488)
        at com.google.firebase.database.core.utilities.encoding.CustomClassMapper.loadOrCreateBeanMapperForClass(com.google.firebase:firebase-database@@19.3.0:329)
        at com.google.firebase.database.core.utilities.encoding.CustomClassMapper.serialize(com.google.firebase:firebase-database@@19.3.0:166)
        at com.google.firebase.database.core.utilities.encoding.CustomClassMapper.convertToPlainJavaTypes(com.google.firebase:firebase-database@@19.3.0:60)
        at com.google.firebase.database.DatabaseReference.setValueInternal(com.google.firebase:firebase-database@@19.3.0:282)
        at com.google.firebase.database.DatabaseReference.setValue(com.google.firebase:firebase-database@@19.3.0:159)
        at Karasik.com.MainActivity$1.onClick(MainActivity.java:55)
        at android.view.View.performClick(View.java:7125)
        at android.view.View.performClickInternal(View.java:7102)
        at android.view.View.access$3500(View.java:801)
        at android.view.View$PerformClick.run(View.java:27336)
        at android.os.Handler.handleCallback(Handler.java:883)
        at android.os.Handler.dispatchMessage(Handler.java:100)
        at android.os.Looper.loop(Looper.java:214)
        at android.app.ActivityThread.main(ActivityThread.java:7356)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)

PM MAIL   Вверх
Hugibor
Дата 16.12.2020, 13:46 (ссылка) | (нет голосов) Загрузка ... Загрузка ... Быстрая цитата Цитата


Новичок



Профиль
Группа: Участник
Сообщений: 7
Регистрация: 13.12.2020

Репутация: нет
Всего: нет



Вы всё время онлайн, или что там такого не обычного то
PM MAIL   Вверх
Dorilace
Дата 18.12.2020, 19:25 (ссылка) | (нет голосов) Загрузка ... Загрузка ... Быстрая цитата Цитата


Новичок



Профиль
Группа: Участник
Сообщений: 14
Регистрация: 16.12.2020

Репутация: нет
Всего: нет



А что только визы? или нельзя же не будет такого не как тогда
PM MAIL   Вверх
Kuceku
Дата 22.12.2020, 22:34 (ссылка) | (нет голосов) Загрузка ... Загрузка ... Быстрая цитата Цитата


Новичок



Профиль
Группа: Участник
Сообщений: 11
Регистрация: 22.12.2020

Репутация: нет
Всего: нет



Рано или поздно всё равно прийдёт
PM MAIL   Вверх
  
Ответ в темуСоздание новой темы Создание опроса
1 Пользователей читают эту тему (1 Гостей и 0 Скрытых Пользователей)
0 Пользователей:
« Предыдущая тема | Android | Следующая тема »


 




[ Время генерации скрипта: 0.1088 ]   [ Использовано запросов: 20 ]   [ GZIP включён ]


Реклама на сайте     Информационное спонсорство

 
По вопросам размещения рекламы пишите на vladimir(sobaka)vingrad.ru
Отказ от ответственности     Powered by Invision Power Board(R) 1.3 © 2003  IPS, Inc.