标签布局片段中的Google商家信息自动填充功能表

时间:2017-05-07 04:30:11

标签: android google-api illegalargumentexception

 Error

我尝试在标签布局片段中使用Google商家信息自动填充API。但是因为这个原因,我无法做到。我该怎么办?

出现的错误是: 错误:(51,54)错误:不兼容的类型:片段无法转换为PlaceAutocompleteFragment

XML文件是:

 <?xml version="1.0" encoding="utf-8"?>
<LinearLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">

<fragment
    android:id="@+id/place_autocomplete_fragment"


android:name=
"com.google.android.gms.location.places.ui.PlaceAutocompleteFragment"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    />

片段代码:

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;

import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.api.GoogleApiClient;
import com.google.android.gms.common.api.Status;
import com.google.android.gms.location.places.Place;
import com.google.android.gms.location.places.Places;
import 
com.google.android.gms.location.places.ui.PlaceAutocompleteFragment;
import 
 com.google.android.gms.location.places.ui.PlaceSelectionListener;

import butterknife.ButterKnife;


public class LocationSearchFragment extends Fragment implements 
GoogleApiClient.OnConnectionFailedListener {
ViewGroup rootView;
String TAG="Location Search:";
private FragmentActivity myContext;

private Context context;    private GoogleApiClient mGoogleApiClient;


@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    rootView = (ViewGroup) inflater

            .inflate(R.layout.place_search, container, false);


    mGoogleApiClient = new GoogleApiClient
            .Builder(rootView.getContext())
            .addApi(Places.GEO_DATA_API)
            .addApi(Places.PLACE_DETECTION_API)
            .build();


    PlaceAutocompleteFragment places= (PlaceAutocompleteFragment)
            getFragmentManager().findFragmentById(R.id.place_autocomplete_fragment);

    places.setOnPlaceSelectedListener(new PlaceSelectionListener() {
        @Override
        public void onPlaceSelected(Place place) {

            Toast.makeText(getContext(),place.getName(),Toast.LENGTH_SHORT).show();
        }

        @Override
        public void onError(Status status) {

            Toast.makeText(getContext(),status.toString(),Toast.LENGTH_SHORT).show();

        }
    });

    ButterKnife.bind(this, rootView);
    return rootView;
}
public void cleanUp(){
    getFragmentManager().beginTransaction().remove().commit();
}
@Override
public void onConnectionFailed(ConnectionResult result) {
    // An unresolvable error has occurred and a connection to Google APIs
    // could not be established. Display an error message, or handle
    // the failure silently

    // ...
}
@Override
public void onAttach(Activity activity) {
    myContext=(FragmentActivity) activity;
    super.onAttach(activity);
}

 }

整个日志:

 05-07 10:38:23.452 27969-27969/com.example.apple.project2 E/AndroidRuntime: FATAL EXCEPTION: main
                                                                        Process: com.example.apple.project2, PID: 27969
                                                                        android.view.InflateException: Binary XML file line #8: Binary XML file line #8: Error inflating class fragment
                                                                            at android.view.LayoutInflater.inflate(LayoutInflater.java:551)
                                                                            at android.view.LayoutInflater.inflate(LayoutInflater.java:429)
                                                                            at com.example.apple.project2.LocationSearchFragment.onCreateView(LocationSearchFragment.java:38)
                                                                            at android.support.v4.app.Fragment.performCreateView(Fragment.java:2192)
                                                                            at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1299)
                                                                            at android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1528)
                                                                            at android.support.v4.app.BackStackRecord.executeOps(BackStackRecord.java:753)
                                                                            at android.support.v4.app.FragmentManagerImpl.executeOps(FragmentManager.java:2363)
                                                                            at android.support.v4.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2149)
                                                                            at android.support.v4.app.FragmentManagerImpl.optimizeAndExecuteOps(FragmentManager.java:2103)
                                                                            at android.support.v4.app.FragmentManagerImpl.execSingleAction(FragmentManager.java:1984)
                                                                            at android.support.v4.app.BackStackRecord.commitNowAllowingStateLoss(BackStackRecord.java:626)
                                                                            at android.support.v4.app.FragmentPagerAdapter.finishUpdate(FragmentPagerAdapter.java:143)
                                                                            at android.support.v4.view.ViewPager.populate(ViewPager.java:1268)
                                                                            at android.support.v4.view.ViewPager.populate(ViewPager.java:1116)
                                                                            at android.support.v4.view.ViewPager$3.run(ViewPager.java:273)
                                                                            at android.view.Choreographer$CallbackRecord.run(Choreographer.java:911)
                                                                            at android.view.Choreographer.doCallbacks(Choreographer.java:686)
                                                                            at android.view.Choreographer.doFrame(Choreographer.java:619)
                                                                            at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:897)
                                                                            at android.os.Handler.handleCallback(Handler.java:739)
                                                                            at android.os.Handler.dispatchMessage(Handler.java:95)
                                                                            at android.os.Looper.loop(Looper.java:148)
                                                                            at android.app.ActivityThread.main(ActivityThread.java:7331)
                                                                            at java.lang.reflect.Method.invoke(Native Method)
                                                                            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
                                                                            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
                                                                         Caused by: android.view.InflateException: Binary XML file line #8: Error inflating class fragment
                                                                            at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:794)
                                                                            at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:716)
                                                                            at android.view.LayoutInflater.rInflate(LayoutInflater.java:847)
                                                                            at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:810)
                                                                            at android.view.LayoutInflater.inflate(LayoutInflater.java:527)
                                                                            at android.view.LayoutInflater.inflate(LayoutInflater.java:429) 
                                                                            at com.example.apple.project2.LocationSearchFragment.onCreateView(LocationSearchFragment.java:38) 
                                                                            at android.support.v4.app.Fragment.performCreateView(Fragment.java:2192) 
                                                                            at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1299) 
                                                                            at android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1528) 
                                                                            at android.support.v4.app.BackStackRecord.executeOps(BackStackRecord.java:753) 
                                                                            at android.support.v4.app.FragmentManagerImpl.executeOps(FragmentManager.java:2363) 
                                                                            at android.support.v4.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2149) 
                                                                            at android.support.v4.app.FragmentManagerImpl.optimizeAndExecuteOps(FragmentManager.java:2103) 
                                                                            at android.support.v4.app.FragmentManagerImpl.execSingleAction(FragmentManager.java:1984) 
                                                                            at android.support.v4.app.BackStackRecord.commitNowAllowingStateLoss(BackStackRecord.java:626) 
                                                                            at android.support.v4.app.FragmentPagerAdapter.finishUpdate(FragmentPagerAdapter.java:143) 
                                                                            at android.support.v4.view.ViewPager.populate(ViewPager.java:1268) 
                                                                            at android.support.v4.view.ViewPager.populate(ViewPager.java:1116) 
                                                                            at android.support.v4.view.ViewPager$3.run(ViewPager.java:273) 
                                                                            at android.view.Choreographer$CallbackRecord.run(Choreographer.java:911) 
                                                                            at android.view.Choreographer.doCallbacks(Choreographer.java:686) 
                                                                            at android.view.Choreographer.doFrame(Choreographer.java:619) 
                                                                            at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:897) 
                                                                            at android.os.Handler.handleCallback(Handler.java:739) 
                                                                            at android.os.Handler.dispatchMessage(Handler.java:95) 
                                                                            at android.os.Looper.loop(Looper.java:148) 
                                                                            at android.app.ActivityThread.main(ActivityThread.java:7331) 
                                                                            at java.lang.reflect.Method.invoke(Native Method) 
                                                                            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230) 
                                                                            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120) 
                                                                         Caused by: java.lang.IllegalArgumentException: Binary XML file line #8: Duplicate id 0x7f0d0165, tag null, or parent id 0xffffffff with another fragment for com.google.android.gms.location.places.ui.PlaceAutocompleteFragment
                                                                            at android.app.FragmentManagerImpl.onCreateView(FragmentManager.java:2227)
                                                                            at android.app.FragmentController.onCreateView(FragmentController.java:99)
                                                                            at android.app.Activity.onCreateView(Activity.java:6085)
                                                                            at android.support.v4.app.BaseFragmentActivityHoneycomb.onCreateView(BaseFragmentActivityHoneycomb.java:36)
                                                                            at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:79)
                                                                            at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:766)
                                                                            at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:716) 
                                                                            at android.view.LayoutInflater.rInflate(LayoutInflater.java:847) 
                                                                            at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:810) 
                                                                            at android.view.LayoutInflater.inflate(LayoutInflater.java:527) 
                                                                            at android.view.LayoutInflater.inflate(LayoutInflater.java:429) 
                                                                            at com.example.apple.project2.LocationSearchFragment.onCreateView(LocationSearchFragment.java:38) 
                                                                            at android.support.v4.app.Fragment.performCreateView(Fragment.java:2192) 
                                                                            at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1299) 
                                                                            at android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1528) 
                                                                            at android.support.v4.app.BackStackRecord.executeOps(BackStackRecord.java:753) 
                                                                            at android.support.v4.app.FragmentManagerImpl.executeOps(FragmentManager.java:2363) 
                                                                            at android.support.v4.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2149) 
                                                                            at android.support.v4.app.FragmentManagerImpl.optimizeAndExecuteOps(FragmentManager.java:2103) 
                                                                            at android.support.v4.app.FragmentManagerImpl.execSingleAction(FragmentManager.java:1984) 
                                                                            at android.support.v4.app.BackStackRecord.commitNowAllowingStateLoss(BackStackRecord.java:626) 
                                                                            at android.support.v4.app.FragmentPagerAdapter.finishUpdate(FragmentPagerAdapter.java:143) 
                                                                            at android.support.v4.view.ViewPager.populate(ViewPager.java:1268) 
                                                                            at android.support.v4.view.ViewPager.populate(ViewPager.java:1116) 
                                                                            at android.support.v4.view.ViewPager$3.run(ViewPager.java:273) 
                                                                            at android.view.Choreographer$CallbackRecord.run(Choreographer.java:911) 
                                                                            at android.view.Choreographer.doCallbacks(Choreographer.java:686) 
                                                                            at android.view.Choreographer.doFrame(Choreographer.java:619) 
                                                                            at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:897) 
                                                                            at android.os.Handler.handleCallback(Handler.java:739) 
                                                                            at android.os.Handler.dispatchMessage(Handler.java:95) 
                                                                            at android.os.Looper.loop(Looper.java:148) 
                                                                            at android.app.ActivityThread.main(ActivityThread.java:7331) 
                                                                            at java.lang.reflect.Method.invoke(Native Method) 
                                                                            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230) 
                                                                            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120) 

05-07 10:38:25.192 27969-27969 / com.example.apple.project2 I / Process:发送信号。 PID:27969 SIG:9

1 个答案:

答案 0 :(得分:0)

第一个错误,导入错误的片段。

df1.merge(df2, left_on=['cond', 'point'], right_on=['cond', 'point'])

而不是

 import android.support.v4.app.Fragment

第二个错误,您正在制作一个不必要的xml文件并在另一个片段中放入一个额外的片段。

尝试重新开始

 import android.app.Fragment