2016-11-17 11 views
0

Googleの自動位置情報を使用して、初めてダイアログを開いたときに警告ダイアログボックスで指定した場所を取得していますが、ダイアログボックスを閉じてダイアログボックスをもう一度開きます。すでにIDAがのGoogleApiClientを管理していても、enableautomanageを変更しようとしましたが、onstartメソッドとonpauseメソッドを追加しましたが、何も機能しません。alertdialogで使用するとid 0のgoogle apiクライアントでエラーが発生する

誰でも私にそれがなぜ発生するのかを教えてもらえますか?また、alertdialogボックスでこのエラーを克服するにはどうしたらいいですか?

コード:

final LayoutInflater layoutInflater = LayoutInflater.from(Activity_AddFastEntryDaybook.this); 
    final View promptView = layoutInflater.inflate(R.layout.dialog_add_newfarmer, null); 
    final AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(Activity_AddFastEntryDaybook.this); 
    alertDialogBuilder.setView(promptView); 
    alertDialogBuilder.setCancelable(true); 
    mlayout = promptView.findViewById(R.id.relative_view_layout); 
    final TextInputLayout ti_farmername = (TextInputLayout) promptView.findViewById(R.id.inputfarname); 
    final TextInputLayout ti_farmermobno = (TextInputLayout) promptView.findViewById(R.id.inputfarmobno); 
    final TextInputLayout ti_farmerlocation = (TextInputLayout) promptView.findViewById(R.id.inputfarmlocation); 
    edt_farmername = (EditText) promptView.findViewById(R.id.farmername); 
    edt_farmermobno = (EditText) promptView.findViewById(R.id.farmermobileno); 
    final ImageView importcontacts = (ImageView) promptView.findViewById(R.id.img_importcontacts); 
    final ImageView btnsave = (ImageView) promptView.findViewById(R.id.img_save); 
    final AutoCompleteTextView actv_farmerlocation = (AutoCompleteTextView) promptView.findViewById(R.id.farmerlocation); 
    // checkconnection(); 
    mGoogleApiClient = new GoogleApiClient.Builder(Activity_AddFastEntryDaybook.this) 
      .addApi(Places.GEO_DATA_API) 
      .enableAutoManage(this, GOOGLE_API_CLIENT_ID, this) 
      .addConnectionCallbacks(this) 
      .build(); 
    actv_farmerlocation.setThreshold(1); 
    actv_farmerlocation.setOnItemClickListener(mAutocompleteClickListener); 
    mPlaceArrayAdapter = new PlaceArrayAdapter(this, android.R.layout.simple_list_item_1, 
      BOUNDS_MOUNTAIN_VIEW, null); 
    actv_farmerlocation.setDropDownWidth(-1); 
    actv_farmerlocation.setAdapter(mPlaceArrayAdapter); 

    importcontacts.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View view) { 
      farmercontacts(); 
     } 
    }); 
    btnsave.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View view) { 
      String farmer_name = edt_farmername.getText().toString(); 
      String farmer_mobno = edt_farmermobno.getText().toString(); 
      String farmer_location = actv_farmerlocation.getText().toString(); 
      if (farmer_name.length() == 0) { 
       edt_farmername.setError("Enter Name"); 
      } else if (farmer_mobno.length() == 0) { 
       edt_farmermobno.setError("MobileNo"); 
      } else if ((farmer_mobno.length() > 10) && (farmer_mobno.startsWith("6") || farmer_mobno.startsWith("5") || farmer_mobno.startsWith("4") || farmer_mobno.startsWith("3") 
        || farmer_mobno.startsWith("2") || farmer_mobno.startsWith("1") || farmer_mobno.startsWith("0") || farmer_mobno.startsWith("*") || farmer_mobno.startsWith("#") || farmer_mobno.endsWith("*") || farmer_mobno.endsWith("#"))) { 
       edt_farmermobno.setError("enter a valid mobile no"); 
      } else if ((farmer_mobno.length() == 10) && (farmer_mobno.startsWith("6") || farmer_mobno.startsWith("5") || farmer_mobno.startsWith("4") || farmer_mobno.startsWith("3") || farmer_mobno.startsWith("2") || farmer_mobno.startsWith("1") || farmer_mobno.startsWith("0") || farmer_mobno.startsWith("*") || farmer_mobno.startsWith("#") || farmer_mobno.endsWith("*") || farmer_mobno.endsWith("#"))) { 
       edt_farmermobno.setError("Invalid mobile no"); 
      } else if ((farmer_mobno.length() < 10) && farmer_mobno.startsWith("6") || farmer_mobno.startsWith("5") || farmer_mobno.startsWith("4") || farmer_mobno.startsWith("3") 
        || farmer_mobno.startsWith("2") || farmer_mobno.startsWith("1") || farmer_mobno.startsWith("0") || farmer_mobno.startsWith("*") || farmer_mobno.startsWith("#") || farmer_mobno.endsWith("*") || farmer_mobno.endsWith("#")) { 
       edt_farmermobno.setError("enter a valid mobile no"); 

      } else if (farmer_location.length() == 0) { 
       actv_farmerlocation.setError("Location"); 
      } else { 
       edt_farmername.setError(null); 
       edt_farmermobno.setError(null); 
       actv_farmerlocation.setError(null); 
       databasehandler.insertFarmer(farmer_name, farmer_mobno, farmer_location); 
       alert.dismiss(); 
       myAdapterfarmer.notifyDataSetChanged(); 
      } 
     } 
    }); 
    alert = alertDialogBuilder.create(); 
    alert.show(); 

エラー:問題がalertdialogからではありません

java.lang.IllegalStateException: Already managing a GoogleApiClient with id 0 
                    at com.google.android.gms.common.internal.zzab.zza(Unknown Source) 
                    at com.google.android.gms.internal.zzpk.zza(Unknown Source) 
                    at com.google.android.gms.common.api.GoogleApiClient$Builder.zzf(Unknown Source) 
                    at com.google.android.gms.common.api.GoogleApiClient$Builder.build(Unknown Source) 
                    at codingtown.coconut.daybook.activity.Activity_AddFastEntryDaybook.addnewfarmer(Activity_AddFastEntryDaybook.java:325) 
                    at codingtown.coconut.daybook.activity.Activity_AddFastEntryDaybook.access$000(Activity_AddFastEntryDaybook.java:74) 
                    at codingtown.coconut.daybook.activity.Activity_AddFastEntryDaybook$5.onClick(Activity_AddFastEntryDaybook.java:265) 

答えて

0

、あなたがコード

`mGoogleApiClient .enableAutoManage(これ、0/*のclientIdを追加することで、これを試してください* /、this)

+0

私はすでにそれをしていますが、まだ私は同じエラーを受けています –

+0

それはwですalertdialogを削除した場合は、 – Vadivel

+0

@Overrideを追加してください。 public void onDestroy(){ super.onDestroy(); mGoogleClient.stopAutoManage(getActivity()); mGoogleClient.disconnect(); } – Vadivel

関連する問題