微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Firestore错误:java.util.UnknownFormatConversionException:转换='F'

如何解决Firestore错误:java.util.UnknownFormatConversionException:转换='F'

当尝试在Java应用程序上使用firebase admin时,我收到此错误

Exception in thread "main" com.google.cloud.firestore.FirestoreException: java.util.UnkNownFormatConversionException: Conversion = 'F'
    at com.google.cloud.firestore.FirestoreException.networkException(FirestoreException.java:89)
    at com.google.cloud.firestore.FirestoreOptions$DefaultFirestoreRpcFactory.create(FirestoreOptions.java:92)
    at com.google.cloud.firestore.FirestoreOptions$DefaultFirestoreRpcFactory.create(FirestoreOptions.java:82)
    at com.google.cloud.ServiceOptions.getRpc(ServiceOptions.java:561)
    at com.google.cloud.firestore.FirestoreOptions.getFirestoreRpc(FirestoreOptions.java:385)
    at com.google.cloud.firestore.FirestoreImpl.<init>(FirestoreImpl.java:67)
    at com.google.cloud.firestore.FirestoreOptions$DefaultFirestoreFactory.create(FirestoreOptions.java:73)
    at com.google.cloud.firestore.FirestoreOptions$DefaultFirestoreFactory.create(FirestoreOptions.java:66)
    at com.google.cloud.ServiceOptions.getService(ServiceOptions.java:541)
    at firebase.Firebase.initialize(Firebase.java:30)
    at launch.Main.main(Main.java:33)
Caused by: java.io.IOException: java.util.UnkNownFormatConversionException: Conversion = 'F'
    at com.google.cloud.firestore.spi.v1.GrpcFirestoreRpc.<init>(GrpcFirestoreRpc.java:137)
    at com.google.cloud.firestore.FirestoreOptions$DefaultFirestoreRpcFactory.create(FirestoreOptions.java:90)
    ... 9 more
Caused by: java.util.UnkNownFormatConversionException: Conversion = 'F'
    at java.base/java.util.Formatter$FormatSpecifier.conversion(Formatter.java:2839)
    at java.base/java.util.Formatter$FormatSpecifier.<init>(Formatter.java:2865)
    at java.base/java.util.Formatter.parse(Formatter.java:2713)
    at java.base/java.util.Formatter.format(Formatter.java:2655)
    at java.base/java.util.Formatter.format(Formatter.java:2609)
    at java.base/java.lang.String.format(String.java:3292)
    at com.google.api.pathtemplate.ValidationException.message(ValidationException.java:91)
    at com.google.api.pathtemplate.ValidationException.<init>(ValidationException.java:86)
    at com.google.api.pathtemplate.PathTemplate.encodeUrl(PathTemplate.java:1093)
    at com.google.api.pathtemplate.PathTemplate.instantiate(PathTemplate.java:775)
    at com.google.api.pathtemplate.PathTemplate.instantiate(PathTemplate.java:702)
    at com.google.api.pathtemplate.PathTemplate.instantiate(PathTemplate.java:711)
    at com.google.firestore.v1.DatabaseRootName.toString(DatabaseRootName.java:122)
    at com.google.cloud.firestore.spi.v1.GrpcFirestoreRpc.<init>(GrpcFirestoreRpc.java:116)
    ... 10 more

供参考,以下是来源:

package firebase;

import com.google.auth.oauth2.GoogleCredentials;
import com.google.cloud.firestore.Firestore;
import com.google.cloud.firestore.FirestoreOptions;
import com.google.firebase.FirebaseApp;
import com.google.firebase.FirebaSEOptions;

import java.io.ByteArrayInputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.nio.charset.StandardCharsets;

public class Firebase {
    private static boolean initialized = false;
    static Firestore db;

    static public void initialize() throws IOException {
        if(initialized)
            return;

        FirestoreOptions options = FirestoreOptions.getDefaultInstance().toBuilder()
                .setCredentials(GoogleCredentials.fromStream(new ByteArrayInputStream(System.getenv("firebase").getBytes(StandardCharsets.UTF_8))))
                .build();

        System.out.println(options.getCredentials());
        System.out.println(System.getenv("firebase"));


        db = options.getService();

        initialized = true;

        return;
    }
}

System.getenv("firebase")打印以下内容

{   "type": "service_account","project_id": "<PROJECT_ID>","private_key_id": "<PRIVATE_KEY_ID>","private_key": "-----BEGIN PRIVATE KEY----- xxxxxx -----END PRIVATE KEY-----\n","client_email": "xxxxxxxxx","client_id": "xxxxxxxxxxxxx","auth_uri": "https://accounts.google.com/o/oauth2/auth","token_uri": "https://oauth2.googleapis.com/token","auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs","client_x509_cert_url": "https://www.googleapis.com/robot/v1/Metadata/x509/firebase-adminsdk-s16j9%40xxxxxxx.iam.gserviceaccount.com" }

即使使用不明显的版本,我也只能找到一次%字符:在4之前的末尾。

options.getCredentials()打印出看似正确的数据,因此我认为问题与访问Firebase时出错有关。

我已经尝试替换firebase密钥。谢谢您的帮助。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?