Android 数据未添加到Firebase,数据未通过Intent和!TextUtils.i完全不工作

Android 数据未添加到Firebase,数据未通过Intent和!TextUtils.i完全不工作,android,firebase,firebase-realtime-database,Android,Firebase,Firebase Realtime Database,因此,我正在创建一个使用Firebase作为数据库的事件应用程序。我是一个业余开发者,所以请容忍我。我一直面临三个主要问题: 1) 我的主要问题是数据没有写入Firebase。我已将数据库模块中的规则更改为“true”。我也有一个用户输入的图像正在上传,但诸如事件标题和其他数据没有上传 2) 我曾使用Intent将数据从一个活动传递到另一个活动,但它没有传递。我在setText的下一个活动中使用了textView,但它变为null。数据也没有显示在日志中,正如我对Log.d所知 3) 我不知道为

因此,我正在创建一个使用Firebase作为数据库的事件应用程序。我是一个业余开发者,所以请容忍我。我一直面临三个主要问题:

1) 我的主要问题是数据没有写入Firebase。我已将数据库模块中的规则更改为“true”。我也有一个用户输入的图像正在上传,但诸如事件标题和其他数据没有上传

2) 我曾使用Intent将数据从一个活动传递到另一个活动,但它没有传递。我在setText的下一个活动中使用了textView,但它变为null。数据也没有显示在日志中,正如我对Log.d所知

3) 我不知道为什么!TextUtils.isEmpty未在我的CreateEvent2上工作。我需要注释整个if-condition以转到CreateEvent3。但是,它在CreateEvent3.java中工作

我尝试了很多方法,但我不知道这些错误的原因是什么

这是我的密码:

CreateEvent2.java

package com.example.admin.college20;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class CreateEvent2 extends AppCompatActivity {

    private EditText mEventTitle, mEventLocation, mEventCategory, mContact;
    private Button mNextButton;

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

        mEventTitle = (EditText) findViewById(R.id.event_title);
        mEventLocation = (EditText) findViewById(R.id.event_location);
        mEventCategory = (EditText) findViewById(R.id.event_category);
        mContact = (EditText) findViewById(R.id.contact_info);
        mNextButton = (Button) findViewById(R.id.nextButton);

        final String event_title = mEventTitle.getText().toString().trim();
        final String event_location = mEventLocation.getText().toString().trim();
        final String event_category = mEventCategory.getText().toString().trim();
        final String contact = mContact.getText().toString().trim();

        mNextButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                /**if (!TextUtils.isEmpty(event_title)
                        && !TextUtils.isEmpty(event_location)
                        && !TextUtils.isEmpty(event_category)
                        && !TextUtils.isEmpty(contact)) {**/

                    Intent i = new Intent(CreateEvent2.this, CreateEvent3.class);
                    i.putExtra("title", event_title);
                    i.putExtra("location", event_location);
                    i.putExtra("category", event_category);
                    i.putExtra("contact", contact);
                    startActivity(i);
                }


        });
    }
}
活动\u创建\u事件2.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"
    tools:context="com.example.admin.college20.CreateEvent2"
    android:background="@drawable/create_event_1">

    <EditText
        android:layout_width="300dp"
        android:layout_height="50dp"
        android:hint="Event Title"
        android:layout_marginTop="90dp"
        android:id="@+id/event_title"
        android:inputType="textMultiLine"
        android:layout_alignParentTop="true"
        android:layout_alignRight="@+id/event_location"
        android:layout_alignEnd="@+id/event_location" />

    <EditText
        android:layout_width="300dp"
        android:layout_height="50dp"
        android:hint="Event Location"
        android:id="@+id/event_location"
        android:inputType="textMultiLine"
        android:layout_centerVertical="true"
        android:layout_alignLeft="@+id/contact_info"
        android:layout_alignStart="@+id/contact_info" />

    <EditText
        android:layout_width="300dp"
        android:layout_height="50dp"
        android:hint="Event Category"
        android:id="@+id/event_category"
        android:inputType="textMultiLine"
        android:layout_marginTop="32dp"
        android:layout_below="@+id/event_location"
        android:layout_alignLeft="@+id/contact_info"
        android:layout_alignStart="@+id/contact_info" />

    <EditText
        android:layout_width="300dp"
        android:layout_height="50dp"
        android:hint="Contact Number"
        android:id="@+id/contact_info"
        android:inputType="textMultiLine"
        android:layout_above="@+id/nextButton"
        android:layout_marginBottom="20dp"
        android:layout_centerHorizontal="true" />

    <Button
        android:layout_width="wrap_content"
        android:layout_height="50dp"
        android:text="New Button"
        android:id="@+id/nextButton"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:layout_marginBottom="27dp" />

</RelativeLayout>

CreateEvent3.java

package com.example.admin.college20;

import android.app.ProgressDialog;
import android.content.Intent;
import android.graphics.Color;
import android.net.Uri;
import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import com.google.android.gms.tasks.OnFailureListener;
import com.google.android.gms.tasks.OnSuccessListener;

import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;

import com.google.firebase.storage.FirebaseStorage;
import com.google.firebase.storage.StorageReference;
import com.google.firebase.storage.UploadTask;

public class CreateEvent3 extends AppCompatActivity {
    private EditText mEventDesc, mEventFBUrl, mEventWebLink;
    private TextView hello;
    private Button upload_image_button, done_button;


    private ProgressDialog progressDialog;
    private static final int GALLERY_INTENT = 1;
    private Uri imageUri = null;

    private DatabaseReference mDatabaseReference;
    private StorageReference mStorageRef;


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

        mEventDesc = (EditText) findViewById(R.id.event_desc);
        mEventFBUrl = (EditText) findViewById(R.id.fb_event_url);
        mEventWebLink = (EditText) findViewById(R.id.event_weblink);
        upload_image_button = (Button) findViewById(R.id.upload_image_button);
        done_button = (Button) findViewById(R.id.done_button);
        hello = (TextView) findViewById(R.id.hello);

        mDatabaseReference = FirebaseDatabase.
                getInstance().
                getReference().
                child("Event");
        mStorageRef = FirebaseStorage.getInstance().getReference();

        progressDialog = new ProgressDialog(this);

        upload_image_button.setVisibility(View.VISIBLE);
        upload_image_button.setBackgroundColor(Color.TRANSPARENT);

        upload_image_button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
                intent.setType("image/*");
                startActivityForResult(intent, GALLERY_INTENT);
            }
        });
        done_button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startPosting();
                Toast.makeText(CreateEvent3.this, "Button Selected", Toast.LENGTH_SHORT).show();
            }
        });

    }

    public void startPosting() {

        progressDialog.setMessage("Uploading the Data");

        Intent in = getIntent();
        Bundle bundle = in.getExtras();
        final String event_title = getIntent().getStringExtra("title");
        final String event_location = getIntent().getStringExtra("location");
        final String event_category = getIntent().getStringExtra("category");
        final String contact = getIntent().getStringExtra("contact");

        final String event_desc = mEventDesc.getText().toString().trim();
        final String event_weblink = mEventWebLink.getText().toString().trim();
        final String event_fb_url = mEventFBUrl.getText().toString().trim();

        Log.d("Event Tile", event_title);
        Log.d("Event Location", event_location);
        Log.d("Event Category", event_category);
        hello.setText(event_title);

        if (!TextUtils.isEmpty(event_desc)
                && !TextUtils.isEmpty(event_weblink)
                && !TextUtils.isEmpty(event_fb_url)
                && imageUri != null) {
            progressDialog.show();

            StorageReference filepath = mStorageRef.child("Images").child(imageUri.getLastPathSegment());

            filepath.putFile(imageUri).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
                @Override
                public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
                    Uri uri = taskSnapshot.getDownloadUrl();

                    DatabaseReference newEvent = mDatabaseReference.push();
                    newEvent.child("title").setValue(event_title);
                    newEvent.child("location").setValue(event_location);
                    newEvent.child("category").setValue(event_category);
                    newEvent.child("contact").setValue(contact);
                    newEvent.child("desc").setValue(event_desc);
                    newEvent.child("web").setValue(event_weblink);
                    newEvent.child("fb").setValue(event_fb_url);
                    newEvent.child("imageUrl").setValue(uri.toString());

                    progressDialog.dismiss();
                    startActivity(new Intent(CreateEvent3.this, MainPage1.class));
                }
            }).addOnFailureListener(new OnFailureListener() {
                @Override
                public void onFailure(@NonNull Exception e) {
                    Toast.makeText(CreateEvent3.this, "Upload Failed :(", Toast.LENGTH_SHORT).show();
                }
            });
        }
        else{
            Toast.makeText(this, "Fill in the details", Toast.LENGTH_SHORT).show();
        }
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == GALLERY_INTENT && resultCode == RESULT_OK) {
            imageUri = data.getData();
        }
    }

}
package com.example.admin.college20;
导入android.app.ProgressDialog;
导入android.content.Intent;
导入android.graphics.Color;
导入android.net.Uri;
导入android.support.annotation.NonNull;
导入android.support.v7.app.AppActivity;
导入android.os.Bundle;
导入android.text.TextUtils;
导入android.util.Log;
导入android.view.view;
导入android.widget.Button;
导入android.widget.EditText;
导入android.widget.TextView;
导入android.widget.Toast;
导入com.google.android.gms.tasks.OnFailureListener;
导入com.google.android.gms.tasks.OnSuccessListener;
导入com.google.firebase.database.DatabaseReference;
导入com.google.firebase.database.FirebaseDatabase;
导入com.google.firebase.storage.firebase存储;
导入com.google.firebase.storage.StorageReference;
导入com.google.firebase.storage.UploadTask;
公共类CreateEvent3扩展了AppCompatActivity{
私有编辑文本mEventDesc、mEventFBUrl、mEventWebLink;
私人文本视图你好;
私人按钮上传图片按钮,完成按钮;
私有进程对话;
专用静态最终int画廊\u意向=1;
私有Uri imageUri=null;
私有数据库引用mDatabaseReference;
私有存储参考mStorageRef;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity\u create\u event3);
mEventDesc=(EditText)findViewById(R.id.event_desc);
mEventFBUrl=(EditText)findViewById(R.id.fb\u事件\u url);
meventwebink=(EditText)findViewById(R.id.event\u weblink);
上传图片按钮=(按钮)findViewById(R.id.upload图片按钮);
完成按钮=(按钮)findViewById(R.id.done_按钮);
hello=(TextView)findViewById(R.id.hello);
mDatabaseReference=FirebaseDatabase。
getInstance()。
getReference()。
儿童(“事件”);
mStorageRef=FirebaseStorage.getInstance().getReference();
progressDialog=新建progressDialog(此);
上传图片按钮。设置可见性(View.VISIBLE);
上传图片按钮。setBackgroundColor(颜色。透明);
上传图片按钮。setOnClickListener(新视图。OnClickListener(){
@凌驾
公共void onClick(视图v){
意向意向=新意向(意向.行动\u获取\u内容);
intent.setType(“image/*”);
startActivityForResult(意向、画廊意向);
}
});
done_button.setOnClickListener(新视图.OnClickListener(){
@凌驾
公共void onClick(视图v){
startPosting();
Toast.makeText(CreateEvent3.this,“按钮已选定”,Toast.LENGTH_SHORT.show();
}
});
}
公共无效起始位置(){
progressDialog.setMessage(“上传数据”);
Intent in=getIntent();
Bundle Bundle=in.getExtras();
最终字符串事件_title=getIntent().getStringExtra(“标题”);
最终字符串事件位置=getIntent().getStringExtra(“位置”);
最终字符串事件_category=getIntent().getStringExtra(“类别”);
最终字符串联系人=getIntent().getStringExtra(“联系人”);
final String event_desc=mEventDesc.getText().toString().trim();
final String event_weblink=meventwebink.getText().toString().trim();
最后一个字符串事件\u fb\u url=mEventFBUrl.getText().toString().trim();
Log.d(“事件磁贴”,事件标题);
Log.d(“事件位置”,事件位置);
Log.d(“事件类别”,事件类别);
hello.setText(事件名称);
如果(!TextUtils.isEmpty)(事件描述)
&&!TextUtils.isEmpty(事件链接)
&&!TextUtils.isEmpty(事件\u fb\u url)
&&imageUri!=null){
progressDialog.show();
StorageReference filepath=mStorageRef.child(“图像”).child(imageUri.getLastPathSegment());
filepath.putFile(imageUri).addOnSuccessListener(新的OnSuccessListener()){
@凌驾
成功时公共无效(UploadTask.TaskSnapshot TaskSnapshot){
Uri=taskSnapshot.getDownloadUrl();
DatabaseReference newEvent=mDatabaseReference.push();
newEvent.child(“标题”).setValue(事件标题);
newEvent.child(“位置”).setValue(事件位置);
newEvent.child(“类别”).setValue(事件\类别);
newEvent.child(“contact”).setValue(contact);
newEvent.child(“desc”).setValue(事件描述);
newEvent.child(“web”).setValue(事件_
<?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"

    tools:context="com.example.admin.college20.CreateEvent3"
    android:background="@drawable/create_event_2">


    <EditText
        android:layout_width="300dp"
        android:layout_height="wrap_content"
        android:id="@+id/event_desc"
        android:layout_marginTop="144dp"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:inputType="textMultiLine"
        android:hint="Enter short description here..."
        />

    <EditText
        android:layout_width="300dp"
        android:layout_height="wrap_content"
        android:id="@+id/fb_event_url"
        android:layout_below="@+id/event_desc"
        android:layout_alignLeft="@+id/event_desc"
        android:layout_alignStart="@+id/event_desc"
        android:layout_marginTop="134dp" />

    <EditText
        android:layout_width="300dp"
        android:layout_height="wrap_content"
        android:id="@+id/event_weblink"
        android:layout_marginTop="49dp"
        android:layout_below="@+id/fb_event_url"
        android:layout_alignLeft="@+id/fb_event_url"
        android:layout_alignStart="@+id/fb_event_url" />

    <Button
        style="?android:attr/buttonStyleSmall"
        android:layout_width="300dp"
        android:layout_height="60dp"
        android:id="@+id/upload_image_button"
        android:layout_marginTop="50dp"
        android:layout_below="@+id/event_desc"
        android:layout_alignLeft="@+id/event_desc"
        android:layout_alignStart="@+id/event_desc" />

    <Button
        android:layout_width="120dp"
        android:layout_height="wrap_content"
        android:id="@+id/done_button"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:layout_marginBottom="15dp" />

    <TextView
        android:text="Hello"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_alignRight="@+id/event_desc"
        android:layout_alignEnd="@+id/event_desc"
        android:layout_marginRight="49dp"
        android:layout_marginEnd="49dp"
        android:layout_marginTop="33dp"
        android:id="@+id/hello" />


</RelativeLayout>
mNextButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
            final String event_title = mEventTitle.getText().toString().trim();
            final String event_location = mEventLocation.getText().toString().trim();
            final String event_category = mEventCategory.getText().toString().trim();
            final String contact = mContact.getText().toString().trim();
                if (!TextUtils.isEmpty(event_title)
                        && !TextUtils.isEmpty(event_location)
                        && !TextUtils.isEmpty(event_category)
                        && !TextUtils.isEmpty(contact)) {

                    Intent i = new Intent(CreateEvent2.this, CreateEvent3.class);
                    i.putExtra("title", event_title);
                    i.putExtra("location", event_location);
                    i.putExtra("category", event_category);
                    i.putExtra("contact", contact);
                    startActivity(i);
                }
               }

        });