gpt4 book ai didi

java - 应用程序在检索值时不断崩溃

转载 作者:行者123 更新时间:2023-12-02 05:57:04 26 4
gpt4 key购买 nike

我使用 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);
}
});
...

结果应该是 TextView 根据需要显示字段的值,但它“崩溃”了,在返回到之前的 Intent 之前在 Activity 中停留几秒钟(不显示信息,而是预定义的布局)。重试将导致应用程序强制关闭。

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 方法进行调试后,它只是停在那里,也就是说,它进入预定义的类并退出,但不会运行我输入的失败代码。

最佳答案

不知何故,这没有出现在 logcat 或 stacktrace 中,但再次检查代码时,我发现该错误是选项菜单代码中的空指针异常,因为我需要它动态。我的代码指向了数据库中的错误位置

关于java - 应用程序在检索值时不断崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56002869/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com