44356

List ParseData results to simpleListView on Android

Question:

I want to list my ArrayList items to the simple list view. I tried to convert ArrayList(iller) to StringArray(mListe) but I couldn't. It gives me always NullPointerException. What is my mistakes and how can I solve this problem Thank you for any help.

This is my List Fragment;

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(); } } }); }

There is the 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)

Thank you !

Answer1:

ParseQueryAdapter<ParseObject> mainAdapter;

^ParseQueryAdapter is what we use to load ParseObject(s) into a ListView. After declaring a ParseQueryAdapter you will want to make a ParseQueryAdapter.QueryFactory and apply it to your adapter.

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();

If you want to do something more like this you may get some success. If you look at the getItemView() method you can see where I reference the xml listview file.

Recommend

  • Titanium - Perform Action when user clicks on Android Notification
  • Home screen shortcut to activity
  • How to detect airplane mode especially in jelly beam?
  • How is firebase able to detect “app_remove”
  • Google Analytics with jQuery - show pathname in label
  • youtube analytics api rows empty
  • Flush google analytics events manually with Google Play Services
  • Facebook API: cannot login on Android
  • Back press fragments issue in android
  • android-How to enable cache or buffering when videoView have downloaded a video
  • How to move again MainActivity after sending the mail?
  • Android - Call default browser with and redirect to a designated url
  • Receive custom intent without activity restart
  • Android NFC read Tags issue. Activity starts each time on data received
  • Unique SMS sender id?
  • UIBarButtonItem's action is not called when in a view with a UIGestureRecognizer
  • Sending email using standard gmail app without chooser
  • Exception HRESULT: 0x800455BC in speech recognition in Windows phone 8
  • How to access recipient on sent messages page with mailboxer
  • Send data from edittext to listview
  • How can go in last activity with resume button?
  • Click on button in another program - FindWindow, C#
  • c# open webrowser in many tab
  • Android application: how to use the camera and grab the image bytes?
  • Blackberry - Custom EditField Cursor
  • How to Cache Real-time Data?
  • d3 v4 drag and drop with TypeScript
  • Content-Length header not returned from Pylons response
  • JQuery Internet Explorer and ajaxstop
  • Play WS (2.2.1): post/put large request
  • Dialing with Intent.ACTION_CALL stopps at # in phone number
  • Body moving without any force applied? (Box2d)
  • How to access EntityManager inside Entity class in EJB3
  • Why HTML5 Canvas with a larger size stretch a drawn line?
  • Opengl-es onTouchEvents problem or a draw problem? [closed]
  • vba code to select only visible cells in specific column except heading
  • AT Commands to Send SMS not working in Windows 8.1
  • How to stop GridView from loading again when I press back button?
  • Android Google Maps API OnLocationChanged only called once
  • Linking SubReports Without LinkChild/LinkMaster