首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >PlaceAutoCompleteFragment setHint NPE

PlaceAutoCompleteFragment setHint NPE
EN

Stack Overflow用户
提问于 2016-07-27 02:27:37
回答 1查看 171关注 0票数 1

我在setHint方法上得到了一个NPE。Logcat显示此错误:

代码语言:javascript
复制
void android.widget.EditText.setHint(java.lang.CharSequence)' on a null object reference.

下面是我的代码:

代码语言:javascript
复制
AutocompleteFilter typeFilter = new AutocompleteFilter.Builder()
            .setTypeFilter(AutocompleteFilter.TYPE_FILTER_NONE)
            .build();
    if (pickup_point == null) {
        Fn.logD("BOOKNOW_FRAGMENT", "autocompleteFragment_null");
        pickup_point = (PlaceAutocompleteFragment) PlaceAutocompleteFragment.instantiate(getActivity(), "com.google.android.gms.location.places.ui.PlaceAutocompleteFragment");
        getActivity().getFragmentManager().beginTransaction().replace(R.id.pickup_container, pickup_point).commit();
                 Fn.logD("pickup_point_fragment",String.valueOf(pickup_point));
        pickup_point.setFilter(typeFilter);
        if ((southwest != null)) {
            Fn.SystemPrintLn("******haha**my curn loc is : " + southwest.longitude + " " + southwest.latitude);
            pickup_point.setBoundsBias(new LatLngBounds(southwest, northeast));
        }
        pickup_point.setOnPlaceSelectedListener(new PlaceSelectionListener() {
            @Override
            public void onPlaceSelected(Place place) {
                Fn.logD("BOOKNOW_FRAGMENT", "onPlaceSelected");
                pickuppoint_name = (String) place.getName();
                pickup_address = (String) place.getAddress();
                pickup_latlng = place.getLatLng();
                pickup_lat = pickup_latlng.latitude;
                pickup_lng = pickup_latlng.longitude;
            }

            @Override
            public void onError(Status status) {
                Fn.logD("BOOKNOW_FRAGMENT", "onError");
                // TODO: Handle the error.
                Fn.logD("BOOKNOW_FRAGMENT", "An error occurred: " + status);
            }
        });
        pickup_point.setHint("Pickup Point");
    }
    if (dropoff_point == null) {
        Fn.logD("BOOKNOW_FRAGMENT", "autocompleteFragment_null");
        dropoff_point = (PlaceAutocompleteFragment) PlaceAutocompleteFragment.instantiate(getActivity(), "com.google.android.gms.location.places.ui.PlaceAutocompleteFragment");
        getActivity().getFragmentManager().beginTransaction().replace(R.id.dropoff_container, dropoff_point).commit();
        //pickup_point.setHint("Pickup Point");
        dropoff_point.setFilter(typeFilter);
        if ((southwest != null)) {
            dropoff_point.setBoundsBias(new LatLngBounds(southwest, northeast));
        }
        dropoff_point.setOnPlaceSelectedListener(new PlaceSelectionListener() {
            @Override
            public void onPlaceSelected(Place place) {
                Fn.logD("BOOKNOW_FRAGMENT", "onPlaceSelected");
                dropoffpoint_name = (String) place.getName();
                dropoff_address = (String) place.getAddress();
            }

下面是xml文件中的相关代码:

代码语言:javascript
复制
<LinearLayout
        style="@style/horizontal_LL.sm.2">
        <LinearLayout
            style="@style/edittext_fragment"
            android:id="@+id/pickup_container"
            android:orientation="vertical">
        </LinearLayout>
    </LinearLayout>
    <LinearLayout
        style="@style/horizontal_LL.sm.2">
        <LinearLayout
            style="@style/edittext_fragment"
            android:orientation="vertical"
            android:id="@+id/dropoff_container">
        </LinearLayout>
    </LinearLayout>

我非常了解NPE以及如何解决它们,但我找不到解决这个问题的方法。提前谢谢。

这似乎就是问题所在:https://code.google.com/p/android/issues/detail?id=23972

EN

回答 1

Stack Overflow用户

发布于 2017-08-06 04:13:10

在调用setHint()方法之前,尝试在插入PlaceAutocompleteFragment之后执行挂起的事务,方法是调用:

代码语言:javascript
复制
getActivity().getFragmentManager().executePendingTransactions()
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/38597346

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档