运行我的应用程序时,出现此“错误夸大类片段”信息

时间:2019-12-21 19:18:37

标签: android google-places-api

我正在尝试从其他布局中的对话框中设置PlaceAutoCompleteFragment,但是我一直在下面收到此错误。它说当我尝试实例化另一个片段中的一个片段时会有一个例外。

 Process: com.urbanx.urbaninsure, PID: 14961
android.view.InflateException: Binary XML file line #25: Error inflating class fragment
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:763)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:809)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
    at com.urbanx.urbaninsure.InsurancePayment.showAlertDialog(InsurancePayment.java:269)
    at com.urbanx.urbaninsure.InsurancePayment.onClick(InsurancePayment.java:241)
    at android.view.View.performClick(View.java:5076)
    at android.view.View$PerformClick.run(View.java:20279)
    at android.os.Handler.handleCallback(Handler.java:739)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:135)
    at android.app.ActivityThread.main(ActivityThread.java:5910)
    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:1405)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1200)
 Caused by: android.app.Fragment$InstantiationException: Trying to instantiate a class 
 com.google.android.gms.location.places.ui.PlaceAutocomplete that is not a Fragment

我找不到问题,请帮助

  private void showAlertDialog() {
    AlertDialog.Builder alertDialog = new AlertDialog.Builder(this);
    alertDialog.setTitle("Final step!");
    alertDialog.setMessage("Enter your delivery location: ");


    LayoutInflater inflater = LayoutInflater.from(this);
    View destination_layout = inflater.inflate(R.layout.enter_address,null);

    PlaceAutocompleteFragment edtAddress = (PlaceAutocompleteFragment) getFragmentManager().findFragmentById(R.id.place_autocomplete_fragment);
    //Hide search icon before fragment
    edtAddress.getView().findViewById(R.id.place_autocomplete_search_button).setVisibility(View.GONE);
    //set hint for fragment
    ((EditText)edtAddress.getView().findViewById(R.id.place_autocomplete_search_input))
            .setHint("Enter your address");

    ((EditText)edtAddress.getView().findViewById(R.id.place_autocomplete_search_input))
            .setTextSize(14);
    final MaterialEditText order_Comment = (MaterialEditText) destination_layout.findViewById(R.id.edtComment);

    //Get address from Place AutoComplete

    edtAddress.setOnPlaceSelectedListener(new PlaceSelectionListener() {
        @Override
        public void onPlaceSelected(Place place) {
            shippingAddress = place;
        }

        @Override
        public void onError(Status status) {
            Log.e("ERROR",status.getStatusMessage());

        }
    });



    alertDialog.setView(destination_layout);


    alertDialog.setPositiveButton("YES", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            final android.app.AlertDialog waitingDialog = new SpotsDialog(InsurancePayment.this,"Placing ");
            waitingDialog.show();


            address =  shippingAddress.getAddress().toString();
            comment = order_Comment.getText().toString();






            String requestId = requests.push().getKey();





            requests.child(requestId).child("firstName").setValue(Common.currentUser.getFirstName());
            requests.child(requestId).child("lastName").setValue(Common.currentUser.getLastName());
            requests.child(requestId).child("phone").setValue(Common.currentUser.getPhone());
            requests.child(requestId).child("address").setValue(address);
           requests.child(requestId).child("cart").setValue(cart);
           requests.child(requestId).child("comment").setValue(comment);
           requests.child(requestId).child("latLng").setValue(String.format("%s,%s",shippingAddress.getLatLng().latitude,shippingAddress.getLatLng().longitude));






            myDb.deleteAllInsurance();





            LAddress.setVisibility(View.VISIBLE);
            etvAddress.setText(address);


            waitingDialog.dismiss();






            PaymentStatementLayout.setVisibility(View.VISIBLE);
            CompleteLayout.setVisibility(View.GONE);
            pbComplete.setVisibility(View.VISIBLE);
            DeliveryLayout.setVisibility(View.VISIBLE);


        }

    });

    alertDialog.setNegativeButton("CANCEL", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialogInterface, int which) {
            dialogInterface.dismiss();

            //remove fragment
            getFragmentManager().beginTransaction()
                    .remove(getFragmentManager().findFragmentById(R.id.place_autocomplete_fragment)).commit();
        }
    });

    alertDialog.show();

      }

然后这是我实施片段的布局文件

   <?xml version="1.0" encoding="utf-8"?>
 <androidx.cardview.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:cardElevation="10dp">


<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_margin="20dp"
    android:orientation="vertical">










    <fragment
        android:id="@+id/place_autocomplete_fragment"
        android:name="com.google.android.gms.location.places.ui.PlaceAutocomplete"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>

    <com.rengwuxian.materialedittext.MaterialEditText
        android:id="@+id/edtComment"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textColorHint="@color/colorPrimary"
        app:met_floatingLabel="highlight"
        app:met_primaryColor="@color/colorPrimary"
        android:hint="Comment"
        android:inputType="textMultiLine"
        app:met_baseColor="@color/colorPrimary"
        android:textSize="24sp"
        android:text=""/>




</LinearLayout>


  </androidx.cardview.widget.CardView>

0 个答案:

没有答案