我的应用程序出现问题,当我登录时,该应用程序崩溃并出现错误
try {
$pdo = new PDO('mysql:host=127.0.0.1;dbname=db',
'user', 'password');
} catch (PDOException $e) {
exit($e->getMessage());
}
我试图弄乱gradle并更改变量。问题似乎源于此软件包:
java.lang.NoSuchMethodError: No static method metafactory(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite; in class Ljava/lang/invoke/LambdaMetafactory; or its super classes (declaration of 'java.lang.invoke.LambdaMetafactory' appears in /apex/com.android.runtime/javalib/core-oj.jar)
at okhttp3.internal.Util.<clinit>(Util.java:87)
at okhttp3.internal.Util.skipLeadingAsciiWhitespace(Util.java:321)
at okhttp3.HttpUrl$Builder.parse(HttpUrl.java:1313)
at okhttp3.HttpUrl.get(HttpUrl.java:917)
at retrofit2.Retrofit$Builder.baseUrl(Retrofit.java:492)
at com.example.usub.Remote.RetrofitClient.getClient(RetrofitClient.java:14)
at com.example.usub.Common.Common.getGoogleAPI(Common.java:10)
at com.example.usub.Welcome.onCreate(Welcome.java:208)
at android.app.Activity.performCreate(Activity.java:7825)
at android.app.Activity.performCreate(Activity.java:7814)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1306)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3245)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3409)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2016)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7356)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
然后,它又引用了:
import retrofit2.Retrofit;
import retrofit2.converter.scalars.ScalarsConverterFactory;
public class RetrofitClient {
private static Retrofit retrofit = null;
public static Retrofit getClient(String baseURL)
{
if(retrofit == null)
{
retrofit = new Retrofit.Builder()
.baseUrl(baseURL)
.addConverterFactory(ScalarsConverterFactory.create())
.build();
}
return retrofit;
}
}
编辑:这是我的礼物
import com.example.usub.Remote.IGoogleAPI;
import com.example.usub.Remote.RetrofitClient;
public class Common {
public static final String baseURL = "https://maps.googleapis.com";
public static IGoogleAPI getGoogleAPI()
{
return RetrofitClient.getClient(baseURL).create(IGoogleAPI.class);
}
}
关于如何找到纠正错误的方法的任何想法?谢谢
答案 0 :(得分:3)
尝试切换到Java 8兼容性,以对某些库进行适当的脱糖处理:
android {
...
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
此外,Google JSON API可能更需要GsonConverterFactory
。
答案 1 :(得分:3)
就我而言,它不是为了改造。我使用的是使用 Java version 1.8
(使用 Rx Java) 的本地库模块 (名为 Android XML to PDF generator),但我的应用程序级别 {{ 1}} 小于 Java version
。
所以我只是在我的应用程序级别添加了以下几行 build.gradle -
1.8
然后它对我有用!
答案 2 :(得分:1)
尝试重构改造依赖项。
写下:
implementation 'com.squareup.retrofit2:retrofit:2.4.0'
implementation 'com.squareup.retrofit2:converter-gson:2.2.0'