gpt4 book ai didi

java - Google map 应用程序 - 运行应用程序时出错

转载 作者:行者123 更新时间:2023-12-02 09:07:25 24 4
gpt4 key购买 nike

我目前正在开发一个应用程序,该应用程序可以获取用户位置,并允许用户使用地方 API 查看附近的位置。每当我尝试运行代码时,都会收到多个错误,这些错误可追溯到我的主 MapActivity 类中的一个错误,错误如下所示:

 at projektapplikation.MapsActivity.onCreate(MapsActivity.java:60)

获取错误的方法称为 OnCreate,如下所示:

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);
// Obtain the SupportMapFragment and get notified when the map is ready to be used.
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);

//Init Service
mServiceType = Common.getGoogleAPIServiceType();

//Request Runtime Permission
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
checkLocationPermission();
}

BottomNavigationView bottomNavigationView = (BottomNavigationView) findViewById(R.id.bottom_navigation);
bottomNavigationView.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {

switch (item.getItemId()) {
case R.id.action_hospital:
nearByPlace("Sjukhus");
break;
case R.id.action_market:
nearByPlace("Shopping");
break;
case R.id.action_retaurant:
nearByPlace("Resturang");
break;
case R.id.action_school:
nearByPlace("Skola");
break;
default:
break;

}


return true;
}
});
}

这就是我的 gradle 的样子:

apply plugin: 'com.android.application'

android {
compileSdkVersion 28
defaultConfig {
applicationId "se.hig.p18wisa02.projektapplikation"
minSdkVersion 26
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}


repositories
{
jcenter()
google()

}

buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}

allprojects {
repositories {
google()
jcenter()
}
}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.squareup.retrofit2:retrofit:2.7.1'
implementation 'com.squareup.retrofit2:converter-gson:2.7.1'
implementation 'androidx.appcompat:appcompat:1.0.2'
compile 'com.android.support:design:28.0.0'
implementation 'com.google.android.gms:play-services-maps:16.0.0'
implementation 'com.google.android.gms:play-services:16.0.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
}

这些都是我的错误:

    2020-01-12 18:37:08.508 26780-26780/se.hig.p18wisa02.projektapplikation E/jektapplikatio: The String#value field is not present on Android versions >= 6.0
2020-01-12 18:37:08.806 26780-26780/se.hig.p18wisa02.projektapplikation D/AndroidRuntime: Shutting down VM
2020-01-12 18:37:08.807 26780-26780/se.hig.p18wisa02.projektapplikation E/AndroidRuntime: FATAL EXCEPTION: main
Process: se.hig.p18wisa02.projektapplikation, PID: 26780
java.lang.BootstrapMethodError: Exception from call site #4 bootstrap method
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 se.hig.p18wisa02.projektapplikation.Remote.RetrofitClient.getClient(RetrofitClient.java:10)
at se.hig.p18wisa02.projektapplikation.Common.getGoogleAPIServiceType(Common.java:12)
at se.hig.p18wisa02.projektapplikation.MapsActivity.onCreate(MapsActivity.java:67)
at android.app.Activity.performCreate(Activity.java:7136)
at android.app.Activity.performCreate(Activity.java:7127)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1271)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2893)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3048)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1808)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
Caused by: java.lang.ClassCastException: Bootstrap method returned null
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 se.hig.p18wisa02.projektapplikation.Remote.RetrofitClient.getClient(RetrofitClient.java:10) 
at se.hig.p18wisa02.projektapplikation.Common.getGoogleAPIServiceType(Common.java:12) 
at se.hig.p18wisa02.projektapplikation.MapsActivity.onCreate(MapsActivity.java:67) 
at android.app.Activity.performCreate(Activity.java:7136) 
at android.app.Activity.performCreate(Activity.java:7127) 
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1271) 
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2893) 
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3048) 
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78) 
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108) 
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1808) 
at android.os.Handler.dispatchMessage(Handler.java:106) 
at android.os.Looper.loop(Looper.java:193) 
at android.app.ActivityThread.main(ActivityThread.java:6669) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858) 

我不知道需要更改什么才能使其正常工作,因此我非常感谢一些帮助。

最佳答案

最新发布的 com.google.android.gms:play-services 版本为 12.0.1,如公布的 here ,所以改变

implementation 'com.google.android.gms:play-services:16.0.0'

implementation 'com.google.android.gms:play-services:12.0.1'

另请注意,您在使用 AndroidX 时不应使用旧版支持存储库。所以而不是

compile'com.android.support:design:28.0.0'

使用

implementation 'com.google.android.material:material:1.0.0'

关于java - Google map 应用程序 - 运行应用程序时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59705950/

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