gpt4 book ai didi

在 android 中添加 google place API 时出现 java.lang.IllegalStateException

转载 作者:行者123 更新时间:2023-12-01 09:35:55 25 4
gpt4 key购买 nike

我想使用 Google Places API 检索当前地点,但添加它后应用程序崩溃了。这是Myactivity的代码

ChooseLanguage.java

public class ChooseLanguage extends AppCompatActivity {
ViewFlipper vf;
GoogleApiClient mGoogleapiCient;
private RadioGroup language;
private RadioButton rb;
private ProgressBar pb;
private ChooseLanguage cl;
private boolean isLanguageselected;
private String lang;
TextView tv;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_choose_language);
cl=this;
isLanguageselected = false;
tv=(TextView)findViewById(R.id.tv);
language=(RadioGroup)findViewById(R.id.radioGroup);
pb=(ProgressBar)findViewById(R.id.progressBar);
vf=(ViewFlipper)findViewById(R.id.viewFlipper);
vf.setInAnimation(this,R.anim.fade_in);
vf.setOutAnimation(this,R.anim.fade_out);
mGoogleapiCient = new GoogleApiClient
.Builder( this )
.enableAutoManage(this, 0, new GoogleApiClient.OnConnectionFailedListener() {
@Override
public void onConnectionFailed(@NonNull ConnectionResult connectionResult) {

}
})
.addApi( Places.GEO_DATA_API )
.addApi( Places.PLACE_DETECTION_API )
.build();
}
@Override
protected void onStart() {
super.onStart();
if( mGoogleapiCient != null )
mGoogleapiCient.connect();
}

@Override
protected void onStop() {
if (mGoogleapiCient != null && mGoogleapiCient.isConnected()) {
mGoogleapiCient.disconnect();
}
super.onStop();
}
public void LangChosen(View view)
{
int slctd=language.getCheckedRadioButtonId();
rb=(RadioButton)findViewById(slctd);


cl.lang=rb.getText().toString();
if(cl.lang.contains("English"))
{
Toast.makeText(this,"Eng Chosen", Toast.LENGTH_LONG).show();
MainActivity.getInstance().update(true);
}
else
{
Toast.makeText(this,"Hindi", Toast.LENGTH_LONG).show();
MainActivity.getInstance().update(false);
}
Toast.makeText(this,"Reached", Toast.LENGTH_LONG).show();
pb.setVisibility(View.VISIBLE);
guessCurrentPlace();


}
private void guessCurrentPlace() {
try {
// location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);

PendingResult<PlaceLikelihoodBuffer> result = Places.PlaceDetectionApi.getCurrentPlace( mGoogleapiCient, null );
result.setResultCallback( new ResultCallback<PlaceLikelihoodBuffer>() {
@Override
public void onResult( PlaceLikelihoodBuffer likelyPlaces ) {

PlaceLikelihood placeLikelihood = likelyPlaces.get( 0 );
String content = "";
if( placeLikelihood != null && placeLikelihood.getPlace() != null && !TextUtils.isEmpty( placeLikelihood.getPlace().getName() ) )
content = "Most likely place: " + placeLikelihood.getPlace().getName() + "\n";
if( placeLikelihood != null )
content += "Percent change of being there: " + (int) ( placeLikelihood.getLikelihood() * 100 ) + "%";
tv.setText( content );

pb.setVisibility(View.GONE);
likelyPlaces.release();

startActivity(new Intent(ChooseLanguage.this, MainActivity.class));
finish();
}
});}

catch (SecurityException e) {
// lets the user know there is a problem with the gps
}
}

}

这是 Android list

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.urjapawar.jagrukbharat">

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>

<uses-feature
android:glEsVersion="0x00020000"
android:required="true"/>

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="AIzaSyBsAr7DXxdEV0vTDkToPeHsz0FI-xbf4go"/>
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:theme="@style/AppTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>

</activity>
<activity android:name=".ChooseLanguage">

</activity>
</application>

</manifest>

这是日志猫

08-13 19:55:44.644 2176-2176/com.urjapawar.jagrukbharat E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.urjapawar.jagrukbharat, PID: 2176
java.lang.IllegalStateException
at com.google.android.gms.common.internal.zzaa.zzai(Unknown Source)
at com.google.android.gms.common.data.zzc.zzbN(Unknown Source)
at com.google.android.gms.common.data.zzc.<init>(Unknown Source)
at com.google.android.gms.location.places.internal.zzt.<init>(Unknown Source)
at com.google.android.gms.location.places.internal.zzn.<init>(Unknown Source)
at com.google.android.gms.location.places.PlaceLikelihoodBuffer.get(Unknown Source)
at com.urjapawar.jagrukbharat.ChooseLanguage$2.onResult(ChooseLanguage.java:104)
at com.urjapawar.jagrukbharat.ChooseLanguage$2.onResult(ChooseLanguage.java:100)
at com.google.android.gms.internal.zznv$zza.zzb(Unknown Source)
at com.google.android.gms.internal.zznv$zza.handleMessage(Unknown Source)
at android.os.Handler.dispatchMessage(Handler.java:111)
at android.os.Looper.loop(Looper.java:194)
at android.app.ActivityThread.main(ActivityThread.java:5706)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1033)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:828)

它指向的线是:

  PlaceLikelihood placeLikelihood = likelyPlaces.get( 0 );
result.setResultCallback( new ResultCallback<PlaceLikelihoodBuffer>() {

最佳答案

也许 likelyPlaces 没有条目,这可以解释为什么调用 likelyPlaces.get( 0 ) 会导致抛出异常。

关于在 android 中添加 google place API 时出现 java.lang.IllegalStateException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38933831/

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