gpt4 book ai didi

java.lang.NoSuchMethodError : com. google.common.base.Platform.systemNanoTime()J

转载 作者:行者123 更新时间:2023-12-02 09:42:55 27 4
gpt4 key购买 nike

我想在运行我的代码时以 java 连接到 google cloud Sql form java 到此错误主程序,但出现此错误。

public static void main(String[] args) throws SQLNonTransientConnectionException,
IOException, SQLException, ClassNotFoundException {
String instanceConnectionName = "****";
String databaseName = "***";
String IP_of_instance = "***";
String username = "***";
String password = "****";
String jdbcUrl = String.format(
"jdbc:mysql://%s/%s?cloudSqlInstance=%s"
+ "&socketFactory=com.google.cloud.sql.mysql.SocketFactory&useSSL=false",
IP_of_instance,
databaseName,
instanceConnectionName);

Connection connection = DriverManager.getConnection(jdbcUrl, username, password);

try (Statement statement = connection.createStatement()) {
ResultSet resultSet = statement.executeQuery("SHOW TABLES");
while (resultSet.next()) {
System.out.println(resultSet.getString(1));
}
} catch (Exception e) {
e.printStackTrace();
}

我在运行代码时遇到此错误:

java.lang.NoSuchMethodError: com.google.common.base.Platform.systemNanoTime()J

这是我的 pom 文件,我添加了依赖项,但我仍然无法访问该类

 <dependency>
<groupId>com.google.appengine</groupId>
<artifactId>appengine-api-1.0-sdk</artifactId>
<version>1.9.69</version>
</dependency>
<dependency>
<groupId>org.httprpc</groupId>
<artifactId>httprpc</artifactId>
<version>6.3.3</version>
</dependency>
<!-- [START servlet] -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
<type>jar</type>
<scope>provided</scope>
</dependency>
<!-- [END servlet] -->
<dependency>
<groupId>com.google.api-client</groupId>
<artifactId>google-api-client-appengine</artifactId>
<version>1.7.0-beta</version>
</dependency>
<dependency>
<groupId>com.zaxxer</groupId>
<artifactId>HikariCP</artifactId>
<version>3.3.1</version>
</dependency>
<dependency>
<groupId>com.google.apis</groupId>
<artifactId>google-api-services-urlshortener</artifactId>
<version>v1-rev57-1.25.0</version>
</dependency>
<dependency>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
<version>1</version>
</dependency>
<dependency>
<groupId>com.healthmarketscience.sqlbuilder</groupId>
<artifactId>sqlbuilder</artifactId>
<version>3.0.0</version>
</dependency>
<!-- [START_EXCLUDE] -->
<!-- Test Dependencies -->
<dependency>
<groupId>com.google.appengine</groupId>
<artifactId>appengine-testing</artifactId>
<version>1.9.69</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.firebase</groupId>
<artifactId>firebase-admin</artifactId>
<version>6.8.1</version>
</dependency>
<dependency>
<groupId>com.google.appengine</groupId>
<artifactId>appengine-api-stubs</artifactId>
<version>1.9.69</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.appengine</groupId>
<artifactId>appengine-tools-sdk</artifactId>
<version>1.9.69</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.api-client</groupId>
<artifactId>google-api-client</artifactId>
<version>1.30.2</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>23.5-jre</version>
</dependency>
<dependency>
<groupId>com.google.truth</groupId>
<artifactId>truth</artifactId>
<version>0.42</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13-beta-1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>2.23.4</version>
<scope>test</scope>
</dependency>
<dependency> <!-- Only used locally -->
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.42</version>
</dependency>
<dependency>
<groupId>com.google.cloud.sql</groupId>
<artifactId>mysql-socket-factory</artifactId>
<version>1.0.12</version>
</dependency>
<!-- [END_EXCLUDE] -->
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20160810</version>
<type>jar</type>
</dependency>

最佳答案

验证您是否在同一项目的 Java 构建路径中使用 google-collect-1.0-rc1.jar 和 java-18.0.jar,请删除 google-collect

这是来源;

NoSuchMethodError: com.google.common.base.Platform.systemNanoTime() In GWT project

关于java.lang.NoSuchMethodError : com. google.common.base.Platform.systemNanoTime()J,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56919658/

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