在 Android 上将 ParseData 结果列表到 simpleListView

List ParseData results to simpleListView on Android

我想在简单列表视图中列出我的 ArrayList 项目。我试图将 ArrayList(iller) 转换为 StringArray(mListe) 但我做不到。它总是给我 NullPointerException。我的错误是什么,我该如何解决这个问题谢谢你的帮助。

这是我的列表片段;

public class ListeFragment extends ListFragment {

public View mView;
public String[] mListe;
public ListView listView;
public ArrayList<String> iller = new ArrayList<String>();


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

    mView = inflater.inflate(R.layout.fragment_liste, container, false);

    return mView;
}

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);

    getOnlineDataFromParse();


}

private void setIlcelerArray(){

    ArrayAdapter<String> adapter = new ArrayAdapter<String>(getListView().getContext(), R.layout.ilce_view, mListe);
    setListAdapter(adapter);

    listView = (ListView) mView.findViewById(android.R.id.list);
    listView.setAdapter(adapter);
}

@Override
public void onResume() {
    super.onResume();

    googleAnalyticsSendScreen();

    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {


            Intent intent = new Intent(getActivity(), ListVets.class);

            intent.putExtra("position", position);
            intent.putExtra("ilce", mListe[position]);
            startActivity(intent);


            //GOOGLE ANALYTICS EVENT SENDER
            String secilenilce = "Seçilen ilçe " + mListe[position];

            Tracker t = ((GlobalState) getActivity().getApplication()).getTracker(
                    GlobalState.TrackerName.APP_TRACKER);

            t.send(new HitBuilders.EventBuilder()
                    .setCategory("İlçeler Listesi")
                    .setAction("Seçilen ilçe")
                    .setLabel(secilenilce)
                    .build());
        }
    });
}

private void getOnlineDataFromParse(){

    ParseQuery<ParseObject> query = ParseQuery.getQuery("Veterinerler");
    query.setLimit(1000);
    query.findInBackground(new FindCallback<ParseObject>() {

        public void done(List<ParseObject> vetList, ParseException e) {
            if (e == null) {

                for(int i=0; i< vetList.size(); i++){

                    iller.add(vetList.get(i).getString("il"));

                }

                mListe = iller.toArray(new String[iller.size()]);

                setIlcelerArray();

            } else {

                AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
                builder.setTitle(getString(R.string.parse_online_query_error_title));
                builder.setMessage(getString(R.string.parse_online_query_error_message));
                builder.setPositiveButton(android.R.string.ok, null);
                AlertDialog dialog = builder.create();
                dialog.show();
            }

        }

    });

}

有logCat;

E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.NullPointerException
        at com.esmobileinc.vetmapp.u.k(Unknown Source)
        at android.support.v4.app.Fragment.C(Unknown Source)
        at android.support.v4.app.v.a(Unknown Source)
        at android.support.v4.app.v.a(Unknown Source)
        at android.support.v4.app.v.d(Unknown Source)
        at android.support.v4.app.v.e(Unknown Source)
        at android.support.v4.app.v.b(Unknown Source)
        at android.support.v4.app.aa.b(Unknown Source)
        at android.support.v4.view.ViewPager.a(Unknown Source)
        at android.support.v4.view.ViewPager.c(Unknown Source)
        at android.support.v4.view.ViewPager.onMeasure(Unknown Source)
        at android.view.View.measure(View.java:15518)
        at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4825)
        at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
        at android.view.View.measure(View.java:15518)
        at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4825)
        at android.support.v7.internal.widget.ActionBarOverlayLayout.onMeasure(Unknown Source)
        at android.view.View.measure(View.java:15518)
        at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4825)
        at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
        at android.view.View.measure(View.java:15518)
        at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4825)
        at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1404)
        at android.widget.LinearLayout.measureVertical(LinearLayout.java:695)
        at android.widget.LinearLayout.onMeasure(LinearLayout.java:588)
        at android.view.View.measure(View.java:15518)
        at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4825)
        at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
        at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2176)
        at android.view.View.measure(View.java:15518)
        at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:1874)
        at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1089)
        at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1265)
        at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:989)
        at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4351)
        at android.view.Choreographer$CallbackRecord.run(Choreographer.java:749)
        at android.view.Choreographer.doCallbacks(Choreographer.java:562)
        at android.view.Choreographer.doFrame(Choreographer.java:532)
        at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:735)
        at android.os.Handler.handleCallback(Handler.java:725)
        at android.os.Handler.dispatchMessage(Handler.java:92)
        at android.os.Looper.loop(Looper.java:137)
        at android.app.ActivityThread.main(ActivityThread.java:5041)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:511)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
        at dalvik.system.NativeStart.main(Native Method)

谢谢!

ParseQueryAdapter<ParseObject> mainAdapter;

^ParseQueryAdapter 是我们用来将 ParseObject(s) 加载到 ListView 中的工具。声明 ParseQueryAdapter 后,您需要制作一个 ParseQueryAdapter.QueryFactory 并将其应用于您的适配器。

ParseQueryAdapter.QueryFactory<ParseObject> factory;
factory = new ParseQueryAdapter.QueryFactory<ParseObject>() {
            @Override
            public ParseQuery<ParseObject> create() {
                ParseQuery query = new ParseQuery("ParseObject");
                return query;
            }
        };
mainAdapter = new ParseQueryAdapter<ParseObject>(this, factory) {
    @Override
    public View getItemView(final ParseObject object, View v, ViewGroup parent) {
        if (v == null) {
            v = View.inflate(getContext(), R.layout.your_list_view, null);
        }
        return v;
    }
};
mainAdapter.setPaginationEnabled(true);
mainAdapter.setTextKey("title");
mainAdapter.setImageKey("Image");
mainAdapter.loadObjects();

如果你想做更多这样的事情,你可能会取得一些成功。如果您查看 getItemView() 方法,您可以看到我在哪里引用了 xml 列表视图文件。