我目前正在为我的高级项目从事Android Studio项目。简而言之,该项目是事件创建者。我将Cloud firestore用作数据库,但是出现问题。我提供了以下代码;当我按下提交按钮时,日志将打印该按钮被按下,功能已启动以及即将开始将代码提交到Firebase的代码的日志,但无论成功与否,都不会打印出来。任何帮助将不胜感激!谢谢!
以下是活动的Java代码:
import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.EditText;
import com.google.android.gms.tasks.OnFailureListener;
import com.google.android.gms.tasks.OnSuccessListener;
import com.google.firebase.firestore.DocumentReference;
import com.google.firebase.firestore.FirebaseFirestore;
import java.util.HashMap;
import java.util.Map;
public class EventActivity extends AppCompatActivity implements
View.OnClickListener {
private static final String TAG = "EventSaved";
FirebaseFirestore db = FirebaseFirestore.getInstance();
//texts
private EditText eventTitle;
private EditText eventAddress;
private EditText eventState;
private EditText eventCity;
private EditText eventZip;
private EditText eventDate;
private EditText eventTime;
private EditText eventRules;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_event);
//views
eventTitle = findViewById(R.id.eventTitle);
eventAddress = findViewById(R.id.eventAddress);
eventState = findViewById(R.id.eventState);
eventCity = findViewById(R.id.eventCity);
eventZip = findViewById(R.id.eventZipCode);
//buttons
findViewById(R.id.submitButton).setOnClickListener(this);
findViewById(R.id.clearButton).setOnClickListener(this);
}
@Override
public void onClick(View v) {
int i = v.getId();
if (i == R.id.submitButton){
Log.d(TAG, "Submit Button was Pushed!");
saveEvent();
} else if (i == R.id.clearButton){
//reset the form
}
}//end onClick
private void saveEvent(){
Log.d(TAG,"Save Event function started");
String title = eventTitle.getText().toString();
String address = eventAddress.getText().toString();
String city = eventCity.getText().toString();
String state = eventState.getText().toString();
Map<String, Object> event = new HashMap<>();
event.put("title", title);
event.put("address", address);
event.put("city", city);
event.put("state", state);
Log.d(TAG,"Begin Write to Database!");
// Add a new document with a generated ID
db.collection("events")
.add(event)
.addOnSuccessListener(new OnSuccessListener<DocumentReference(){
@Override
public void onSuccess(DocumentReference
documentReference){
Log.d(TAG, "Success!");
}
})
.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Log.w(TAG, "Error adding document", e);
}
});
}
}
供参考;这也是我的应用程序build.gradle:
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.google.firebase:firebase-auth:16.1.0'
implementation 'com.google.firebase:firebase-core:16.0.7'
implementation 'com.google.firebase:firebase-firestore:18.0.1'
implementation 'com.android.support:multidex:1.0.3'
implementation 'com.google.android.gms:play-services-maps:16.1.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-
core:3.0.2'
这是当我按下“提交”按钮时发生的情况的日志:
03-12 12:09:59.759 8394-8394/com.example.seniorsemproject D/EventSaved: Submit Button was Pushed!
03-12 12:09:59.759 8394-8394/com.example.seniorsemproject D/EventSaved: Save Event function started
03-12 12:09:59.759 8394-8394/com.example.seniorsemproject D/EventSaved: Begin Write to Database!
03-12 12:09:59.889 8394-8423/com.example.seniorsemproject D/dalvikvm: GC_FOR_ALLOC freed 349K, 10% free 4135K/4552K, paused 12ms, total 15ms
03-12 12:10:00.049 8394-8423/com.example.seniorsemproject W/dalvikvm: Unable to resolve superclass of Lio/grpc/android/AndroidChannelBuilder$AndroidChannel$DefaultNetworkCallback; (11)
03-12 12:10:00.049 8394-8423/com.example.seniorsemproject W/dalvikvm: Link of class 'Lio/grpc/android/AndroidChannelBuilder$AndroidChannel$DefaultNetworkCallback;' failed
03-12 12:10:00.049 8394-8423/com.example.seniorsemproject E/dalvikvm: Could not find class 'io.grpc.android.AndroidChannelBuilder$AndroidChannel$DefaultNetworkCallback', referenced from method io.grpc.android.AndroidChannelBuilder$AndroidChannel.configureNetworkMonitoring
03-12 12:10:00.049 8394-8423/com.example.seniorsemproject W/dalvikvm: VFY: unable to resolve new-instance 945 (Lio/grpc/android/AndroidChannelBuilder$AndroidChannel$DefaultNetworkCallback;) in Lio/grpc/android/AndroidChannelBuilder$AndroidChannel;
03-12 12:10:00.069 8394-8423/com.example.seniorsemproject D/dalvikvm: VFY: replacing opcode 0x22 at 0x000b
03-12 12:10:00.069 8394-8423/com.example.seniorsemproject W/dalvikvm: Unable to resolve superclass of Lio/grpc/android/AndroidChannelBuilder$AndroidChannel$DefaultNetworkCallback; (11)
03-12 12:10:00.069 8394-8423/com.example.seniorsemproject W/dalvikvm: Link of class 'Lio/grpc/android/AndroidChannelBuilder$AndroidChannel$DefaultNetworkCallback;' failed
03-12 12:10:00.089 8394-8423/com.example.seniorsemproject D/dalvikvm: DexOpt: unable to opt direct call 0x3215 at 0x0d in Lio/grpc/android/AndroidChannelBuilder$AndroidChannel;.configureNetworkMonitoring
03-12 12:10:00.169 8394-8423/com.example.seniorsemproject D/dalvikvm: GC_FOR_ALLOC freed 374K, 10% free 4270K/4712K, paused 13ms, total 14ms
03-12 12:10:00.239 8394-8423/com.example.seniorsemproject W/dalvikvm: Unable to resolve superclass of Lcom/google/firebase/firestore/remote/AndroidConnectivityMonitor$DefaultNetworkCallback; (349)
03-12 12:10:00.239 8394-8423/com.example.seniorsemproject W/dalvikvm: Link of class 'Lcom/google/firebase/firestore/remote/AndroidConnectivityMonitor$DefaultNetworkCallback;' failed
03-12 12:10:00.249 8394-8423/com.example.seniorsemproject E/dalvikvm: Could not find class 'com.google.firebase.firestore.remote.AndroidConnectivityMonitor$DefaultNetworkCallback', referenced from method com.google.firebase.firestore.remote.AndroidConnectivityMonitor.configureNetworkMonitoring
03-12 12:10:00.249 8394-8423/com.example.seniorsemproject W/dalvikvm: VFY: unable to resolve new-instance 6888 (Lcom/google/firebase/firestore/remote/AndroidConnectivityMonitor$DefaultNetworkCallback;) in Lcom/google/firebase/firestore/remote/AndroidConnectivityMonitor;
03-12 12:10:00.249 8394-8423/com.example.seniorsemproject D/dalvikvm: VFY: replacing opcode 0x22 at 0x000b
03-12 12:10:00.249 8394-8423/com.example.seniorsemproject W/dalvikvm: Unable to resolve superclass of Lcom/google/firebase/firestore/remote/AndroidConnectivityMonitor$DefaultNetworkCallback; (349)
03-12 12:10:00.249 8394-8423/com.example.seniorsemproject W/dalvikvm: Link of class 'Lcom/google/firebase/firestore/remote/AndroidConnectivityMonitor$DefaultNetworkCallback;' failed
03-12 12:10:00.249 8394-8423/com.example.seniorsemproject D/dalvikvm: DexOpt: unable to opt direct call 0xd9e6 at 0x0d in Lcom/google/firebase/firestore/remote/AndroidConnectivityMonitor;.configureNetworkMonitoring
03-12 12:10:00.359 8394-8423/com.example.seniorsemproject I/dalvikvm: Could not find method sun.misc.Unsafe.copyMemory, referenced from method com.google.protobuf.UnsafeUtil.copyMemory
03-12 12:10:00.359 8394-8423/com.example.seniorsemproject W/dalvikvm: VFY: unable to resolve virtual method 18707: Lsun/misc/Unsafe;.copyMemory (JJJ)V
03-12 12:10:00.359 8394-8423/com.example.seniorsemproject D/dalvikvm: VFY: replacing opcode 0x74 at 0x0005
03-12 12:10:00.359 8394-8423/com.example.seniorsemproject I/dalvikvm: Could not find method sun.misc.Unsafe.copyMemory, referenced from method com.google.protobuf.UnsafeUtil.copyMemory
03-12 12:10:00.359 8394-8423/com.example.seniorsemproject W/dalvikvm: VFY: unable to resolve virtual method 18708: Lsun/misc/Unsafe;.copyMemory (Ljava/lang/Object;JLjava/lang/Object;JJ)V
03-12 12:10:00.359 8394-8423/com.example.seniorsemproject D/dalvikvm: VFY: replacing opcode 0x74 at 0x0007
03-12 12:10:00.359 8394-8423/com.example.seniorsemproject I/dalvikvm: Could not find method sun.misc.Unsafe.getByte, referenced from method com.google.protobuf.UnsafeUtil.getByte
03-12 12:10:00.359 8394-8423/com.example.seniorsemproject W/dalvikvm: VFY: unable to resolve virtual method 18709: Lsun/misc/Unsafe;.getByte (J)B
03-12 12:10:00.359 8394-8423/com.example.seniorsemproject D/dalvikvm: VFY: replacing opcode 0x6e at 0x0002
03-12 12:10:00.359 8394-8423/com.example.seniorsemproject I/dalvikvm: Could not find method sun.misc.Unsafe.getByte, referenced from method com.google.protobuf.UnsafeUtil.getByte
03-12 12:10:00.359 8394-8423/com.example.seniorsemproject W/dalvikvm: VFY: unable to resolve virtual method 18710: Lsun/misc/Unsafe;.getByte (Ljava/lang/Object;J)B
03-12 12:10:00.359 8394-8423/com.example.seniorsemproject D/dalvikvm: VFY: replacing opcode 0x6e at 0x0002
03-12 12:10:00.359 8394-8423/com.example.seniorsemproject I/dalvikvm: Could not find method sun.misc.Unsafe.getLong, referenced from method com.google.protobuf.UnsafeUtil.getLong
03-12 12:10:00.359 8394-8423/com.example.seniorsemproject W/dalvikvm: VFY: unable to resolve virtual method 18711: Lsun/misc/Unsafe;.getLong (J)J
03-12 12:10:00.359 8394-8423/com.example.seniorsemproject D/dalvikvm: VFY: replacing opcode 0x6e at 0x0002
03-12 12:10:00.359 8394-8423/com.example.seniorsemproject I/dalvikvm: Could not find method sun.misc.Unsafe.putByte, referenced from method com.google.protobuf.UnsafeUtil.putByte
03-12 12:10:00.359 8394-8423/com.example.seniorsemproject W/dalvikvm: VFY: unable to resolve virtual method 18714: Lsun/misc/Unsafe;.putByte (JB)V
03-12 12:10:00.359 8394-8423/com.example.seniorsemproject D/dalvikvm: VFY: replacing opcode 0x6e at 0x0002
03-12 12:10:00.359 8394-8423/com.example.seniorsemproject I/dalvikvm: Could not find method sun.misc.Unsafe.putByte, referenced from method com.google.protobuf.UnsafeUtil.putByte
03-12 12:10:00.359 8394-8423/com.example.seniorsemproject W/dalvikvm: VFY: unable to resolve virtual method 18715: Lsun/misc/Unsafe;.putByte (Ljava/lang/Object;JB)V
03-12 12:10:00.359 8394-8423/com.example.seniorsemproject D/dalvikvm: VFY: replacing opcode 0x6e at 0x0002
03-12 12:10:00.459 8394-8423/com.example.seniorsemproject D/dalvikvm: GC_FOR_ALLOC freed 376K, 10% free 4408K/4848K, paused 15ms, total 15ms
03-12 12:10:01.699 8394-8416/com.example.seniorsemproject V/FA: Inactivity, disconnecting from the service