我将FirebaseFirestore用作数据库,并且从Firestore检索字段以显示在TextView上时,我的应用程序始终崩溃。即使在使用相同代码的情况下,它也可以在我的一个页面上正常工作,但不能在其他页面上正常工作(该Java类在具有相似功能的3个不同页面之间共享),数据库中的所有文档都具有相同的字段
我试图在TextView上显示任何onFailed错误消息,但是程序跳出了错误代码,并且检查logcat并没有任何好处。
...
db = FirebaseFirestore.getInstance();
myRef = db.collection("users").document(userEmail).collection(events).document(documentID);
myRef.get().addOnSuccessListener(new OnSuccessListener<DocumentSnapshot>() {
@Override
public void onSuccess(DocumentSnapshot documentSnapshot) {
eventName = documentSnapshot.getString("name");
myEventName.setText(eventName);
eventDate = documentSnapshot.getString("date");
eventTime = documentSnapshot.getString("time");
myEventTime.setText("Date: " + eventDate + " Time: " + eventTime);
eventVenue = documentSnapshot.getString("venue");
myEventVenue.setText(eventVenue);
eventNotes = documentSnapshot.getString("notes");
myAdditionalInfo.setText(eventNotes);
eventPriority = documentSnapshot.getLong("priority").intValue();
eventDay = documentSnapshot.getString("day");
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Intent error = new Intent(ViewMyEvent.this, errorMessage.class);
error.putExtra("msg", e.toString());
startActivity(error);
}
});
...
结果应该是文本视图根据需要显示字段的值,但它会“崩溃”,在活动中停留几秒钟(不显示信息,而是显示预定义的布局),然后返回上一个意图。再次尝试将导致应用强制关闭。
logcat如下
2019-05-06 20:18:38.088 21616-21637/? E/Fabric: Settings request failed.
io.fabric.sdk.android.services.network.HttpRequest$HttpRequestException: java.net.SocketTimeoutException: failed to connect to settings.crashlytics.com/23.23.142.246 (port 443) from /192.168.1.132 (port 53802) after 10000ms
at io.fabric.sdk.android.services.network.HttpRequest.code(HttpRequest.java:1359)
at io.fabric.sdk.android.services.settings.DefaultSettingsSpiCall.handleResponse(DefaultSettingsSpiCall.java:104)
at io.fabric.sdk.android.services.settings.DefaultSettingsSpiCall.invoke(DefaultSettingsSpiCall.java:88)
at io.fabric.sdk.android.services.settings.DefaultSettingsController.loadSettingsData(DefaultSettingsController.java:93)
at io.fabric.sdk.android.services.settings.DefaultSettingsController.loadSettingsData(DefaultSettingsController.java:70)
at io.fabric.sdk.android.services.settings.Settings.loadSettingsData(Settings.java:156)
at io.fabric.sdk.android.Onboarding.retrieveSettingsData(Onboarding.java:128)
at io.fabric.sdk.android.Onboarding.doInBackground(Onboarding.java:100)
at io.fabric.sdk.android.Onboarding.doInBackground(Onboarding.java:46)
at io.fabric.sdk.android.InitializationTask.doInBackground(InitializationTask.java:63)
at io.fabric.sdk.android.InitializationTask.doInBackground(InitializationTask.java:28)
at io.fabric.sdk.android.services.concurrency.AsyncTask$2.call(AsyncTask.java:311)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:459)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at java.lang.Thread.run(Thread.java:764)
Caused by: java.net.SocketTimeoutException: failed to connect to settings.crashlytics.com/23.23.142.246 (port 443) from /192.168.1.132 (port 53802) after 10000ms
at libcore.io.IoBridge.connectErrno(IoBridge.java:185)
at libcore.io.IoBridge.connect(IoBridge.java:129)
at java.net.PlainSocketImpl.socketConnect(PlainSocketImpl.java:137)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:390)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:230)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:212)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:436)
at java.net.Socket.connect(Socket.java:621)
at com.android.okhttp.internal.Platform.connectSocket(Platform.java:145)
at com.android.okhttp.internal.io.RealConnection.connectSocket(RealConnection.java:1416)
at com.android.okhttp.internal.io.RealConnection.connect(RealConnection.java:1368)
at com.android.okhttp.internal.http.StreamAllocation.findConnection(StreamAllocation.java:219)
at com.android.okhttp.internal.http.StreamAllocation.findHealthyConnection(StreamAllocation.java:142)
at com.android.okhttp.internal.http.StreamAllocation.newStream(StreamAllocation.java:104)
at com.android.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:392)
at com.android.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:325)
at com.android.okhttp.internal.huc.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:470)
at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:416)
at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getResponseCode(HttpURLConnectionImpl.java:547)
at com.android.okhttp.internal.huc.DelegatingHttpsURLConnection.getResponseCode(DelegatingHttpsURLConnection.java:105)
at com.android.okhttp.internal.huc.HttpsURLConnectionImpl.getResponseCode(HttpsURLConnectionImpl.java:26)
at io.fabric.sdk.android.services.network.HttpRequest.code(HttpRequest.java:1357)
at io.fabric.sdk.android.services.settings.DefaultSettingsSpiCall.handleResponse(DefaultSettingsSpiCall.java:104)
at io.fabric.sdk.android.services.settings.DefaultSettingsSpiCall.invoke(DefaultSettingsSpiCall.java:88)
at io.fabric.sdk.android.services.settings.DefaultSettingsController.loadSettingsData(DefaultSettingsController.java:93)
at io.fabric.sdk.android.services.settings.DefaultSettingsController.loadSettingsData(DefaultSettingsController.java:70)
at io.fabric.sdk.android.services.settings.Settings.loadSettingsData(Settings.java:156)
at io.fabric.sdk.android.Onboarding.retrieveSettingsData(Onboarding.java:128)
at io.fabric.sdk.android.Onboarding.doInBackground(Onboarding.java:100)
at io.fabric.sdk.android.Onboarding.doInBackground(Onboarding.java:46)
at io.fabric.sdk.android.InitializationTask.doInBackground(InitializationTask.java:63)
at io.fabric.sdk.android.InitializationTask.doInBackground(InitializationTask.java:28)
at io.fabric.sdk.android.services.concurrency.AsyncTask$2.call(AsyncTask.java:311)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:459)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at java.lang.Thread.run(Thread.java:764)
在onFailure方法上进行调试之后,它只是在此处停止,即它进入预定义的类并退出,但不运行我放入的失败代码。
答案 0 :(得分:0)
这在logcat或stacktrace中没有出现,但是再三遍遍代码,我发现该错误是选项菜单代码中的空指针异常,因为我需要它动态。我指向数据库中错误位置的代码