Android 访问隐藏字段 Landroid/widget/AbsListView;->mIsChildViewEnabled:Z(灰名单,反射,允许)

Android Accessing hidden field Landroid/widget/AbsListView;->mIsChildViewEnabled:Z (greylist, reflection, allowed)

我正在尝试使用来自 API 的数据填充微调器。但是,当我尝试打开微调器时,出现以下错误:Android Accessing hidden field Landroid/widget/AbsListView;->mIsChildViewEnabled:Z (greylist, reflection, allowed)

我将微调器放在一个片段中,然后在我的 main_activity:

中使用这个片段
import android.os.Bundle;
import androidx.fragment.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ProgressBar;
import android.widget.Spinner;
import android.widget.TextView;
import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.JsonObjectRequest;
import com.android.volley.toolbox.Volley;
import com.booij.mydogapplication.R;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.Array;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Iterator;

public class SearchbarFragment extends Fragment
{
    private URL _url;
    private Spinner _spinner;
    private ArrayList<String> _breedList;

    public SearchbarFragment()
    {
        // Required empty public constructor
        try
        {
            _url = new URL("https://dog.ceo/api/breeds/list/all");
            _breedList = new ArrayList<>();
        } catch (MalformedURLException e)
        {
            e.printStackTrace();
        }
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
    {
        View view =  inflater.inflate(R.layout.fragment_searchbar, container, false);

        _spinner = view.findViewById(R.id.breedDropdown);
        setSpinnerList();

        _spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener()
        {

            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id)
            {
                Log.e("myInfo", String.valueOf(position));
                Log.e("myInfo", _breedList.get(position));
            }

            @Override
            public void onNothingSelected(AdapterView<?> parent)
            {

            }
        });

        // Inflate the layout for this fragment
        return inflater.inflate(R.layout.fragment_searchbar, container, false);
    }


    private void setSpinnerList()
    {
        JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.GET, _url.toString(), null,
            new Response.Listener<JSONObject>()
            {
                @Override
                public void onResponse(JSONObject response)
                {
                    try
                    {
                        JSONObject breeds = new JSONObject(response.getString("message"));

                        _breedList.add("");
                        Iterator<String> iterator = breeds.keys();
                        while (iterator.hasNext())
                        {
                            String key = iterator.next();
                            _breedList.add(key);
                        }
                        ArrayAdapter<String> adapter = new ArrayAdapter(getActivity(), android.R.layout.simple_list_item_1, _breedList.toArray());
                        adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); // The drop down view
                        _spinner.setAdapter(adapter);
                        //spinner.setSelection(0);

                    }
                    catch (JSONException jsonException)
                    {
                        jsonException.printStackTrace();
                    }
                }
            },
            new Response.ErrorListener()
            {
                @Override
                public void onErrorResponse(VolleyError error)
                {
                    error.printStackTrace();
                }
            });

        RequestQueue queue = Volley.newRequestQueue(getActivity());

        queue.add(jsonObjectRequest);
    }

}

我做错了什么?如果我需要提前提供额外的details.Thanks

,请告诉我

我注意到 onCreateView 将 Fragment 布局膨胀了两次,并且没有返回用于设置微调器的视图。这可能是问题所在。我建议进行此更改:

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
    View view =  inflater.inflate(R.layout.fragment_searchbar, container, false);

    _spinner = view.findViewById(R.id.breedDropdown);
    setSpinnerList();

    _spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener()
    {

        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id)
        {
            Log.e("myInfo", String.valueOf(position));
            Log.e("myInfo", _breedList.get(position));
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent)
        {

        }
    });

    // Inflate the layout for this fragment
    return view <---- Return the view, rather than inflate another view.
}