Read the value of the database displayed on the ListView

Source: Internet
Author: User


==================== Problem Description ====================
I have defined a method for querying the database (Selectallrecrod), saving the queried value in a list<string>, using unit tests, this method is feasible and can execute the result. ListView I use the Arrayadapter adapter, I write the data can be used, but a use of the Selectallrecrod method returned by the list error, null pointer exception. I want to know if you want to query the database, is to use the adapter is not must for simplecursoradapter, I think it should not be.
The Java code is as follows:
public class Towfragment extends fragment{private listview listview = null;private Mydao Mydao = null;private List<stri Ng> listData = null; @Overridepublic View Oncreateview (layoutinflater inflater, ViewGroup container,bundle Savedinstancestate) {View view = Inflater.inflate (R.layout.tow, container, false); listview = (ListView) View.findviewbyid (r.id.listview); Mydao = new Mydao (getactivity ()); listData = Mydao.selectedallrecord (); Listview.setadapter (New arrayadapter<string> (Getactivity (), Android. R.layout.simple_expandable_list_item_1, ListData)); return view;}}


The error log is as follows:

06-21 07:48:17.486:e/androidruntime (16659): FATAL exception:main
06-21 07:48:17.486:e/androidruntime (16659): java.lang.NullPointerException
06-21 07:48:17.486:e/androidruntime (16659): at Android.widget.ArrayAdapter.createViewFromResource (Arrayadapter.ja va:394)
06-21 07:48:17.486:e/androidruntime (16659): at Android.widget.ArrayAdapter.getView (arrayadapter.java:362)
06-21 07:48:17.486:e/androidruntime (16659): at Android.widget.AbsListView.obtainView (abslistview.java:2159)
06-21 07:48:17.486:e/androidruntime (16659): at Android.widget.ListView.measureHeightOfChildren (listview.java:1246 )
06-21 07:48:17.486:e/androidruntime (16659): at Android.widget.ListView.onMeasure (listview.java:1158)
06-21 07:48:17.486:e/androidruntime (16659): at Android.view.View.measure (view.java:15518)
06-21 07:48:17.486:e/androidruntime (16659): at Android.view.ViewGroup.measureChildWithMargins (viewgroup.java:4825 )
06-21 07:48:17.486:e/androidruntime (16659): at Android.widget.LinearLayout.measureChildBeforeLayout (LinearLayout. java:1404)
06-21 07:48:17.486:e/androidruntime (16659): at Android.widget.LinearLayout.measureVertical (linearlayout.java:695)
06-21 07:48:17.486:e/androidruntime (16659): at Android.widget.LinearLayout.onMeasure (linearlayout.java:588)
06-21 07:48:17.486:e/androidruntime (16659): at Android.view.View.measure (view.java:15518)
06-21 07:48:17.486:e/androidruntime (16659): at Android.view.ViewGroup.measureChildWithMargins (viewgroup.java:4825 )
06-21 07:48:17.486:e/androidruntime (16659): at Android.widget.FrameLayout.onMeasure (framelayout.java:310)
06-21 07:48:17.486:e/androidruntime (16659): at Android.view.View.measure (view.java:15518)
06-21 07:48:17.486:e/androidruntime (16659): at Android.support.v4.view.ViewPager.onMeasure (viewpager.java:1389)
06-21 07:48:17.486:e/androidruntime (16659): at Android.view.View.measure (view.java:15518)
06-21 07:48:17.486:e/androidruntime (16659): at Android.view.ViewGroup.measureChildWithMargins (viewgroup.java:4825 )
06-21 07:48:17.486:e/androidruntime (16659): at Android.widget.FrameLayout.onMeasure (framelayout.java:310)
06-21 07:48:17.486:e/androidruntime (16659): at Android.view.View.measure (view.java:15518)
06-21 07:48:17.486:e/androidruntime (16659): at Android.widget.LinearLayout.measureVertical (linearlayout.java:847)
06-21 07:48:17.486:e/androidruntime (16659): at Android.widget.LinearLayout.onMeasure (linearlayout.java:588)
06-21 07:48:17.486:e/androidruntime (16659): at Android.view.View.measure (view.java:15518)
06-21 07:48:17.486:e/androidruntime (16659): at Android.view.ViewGroup.measureChildWithMargins (viewgroup.java:4825 )
06-21 07:48:17.486:e/androidruntime (16659): at Android.widget.FrameLayout.onMeasure (framelayout.java:310)
06-21 07:48:17.486:e/androidruntime (16659): at Com.android.internal.policy.impl.phonewindow$decorview.onmeasure (P honewindow.java:2176)
06-21 07:48:17.486:e/androidruntime (16659): at Android.view.View.measure (view.java:15518)
06-21 07:48:17.486:e/androidruntime (16659): at Android.view.ViewRootImpl.performMeasure (viewrootimpl.java:1874)
06-21 07:48:17.486:e/androidruntime (16659): at Android.view.ViewRootImpl.measureHierarchy (viewrootimpl.java:1089)
06-21 07:48:17.486:e/androidruntime (16659): at Android.view.ViewRootImpl.performTraversals (viewrootimpl.java:1265 )
06-21 07:48:17.486:e/androidruntime (16659): at Android.view.ViewRootImpl.doTraversal (viewrootimpl.java:989)
06-21 07:48:17.486:e/androidruntime (16659): At Android.view.viewrootimpl$traversalrunnable.run (ViewRootImpl.java: 4351)
06-21 07:48:17.486:e/androidruntime (16659): at Android.view.choreographer$callbackrecord.run (Choreographer.java:7 49)
06-21 07:48:17.486:e/androidruntime (16659): at Android.view.Choreographer.doCallbacks (choreographer.java:562)
06-21 07:48:17.486:e/androidruntime (16659): at Android.view.Choreographer.doFrame (choreographer.java:532)
06-21 07:48:17.486:e/androidruntime (16659): at Android.view.choreographer$framedisplayeventreceiver.run (Choreogra pher.java:735)
06-21 07:48:17.486:e/androidruntime (16659): at Android.os.Handler.handleCallback (handler.java:725)
06-21 07:48:17.486:e/androidruntime (16659): at Android.os.Handler.dispatchMessage (handler.java:92)
06-21 07:48:17.486:e/androidruntime (16659): at Android.os.Looper.loop (looper.java:137)
06-21 07:48:17.486:e/androidruntime (16659): at Android.app.ActivityThread.main (activitythread.java:5041)
06-21 07:48:17.486:e/androidruntime (16659): at Java.lang.reflect.Method.invokeNative (Native Method)
06-21 07:48:17.486:e/androidruntime (16659): at Java.lang.reflect.Method.invoke (method.java:511)
06-21 07:48:17.486:e/androidruntime (16659): at Com.android.internal.os.zygoteinit$methodandargscaller.run (ZygoteI nit.java:793)
06-21 07:48:17.486:e/androidruntime (16659): at Com.android.internal.os.ZygoteInit.main (zygoteinit.java:560)
06-21 07:48:17.486:e/androidruntime (16659): at Dalvik.system.NativeStart.main (Native Method)
06-21 07:48:21.626:e/inputdispatcher (296): Channel ' 41055180 com.ccniit.zhh.main/com.ccniit.zhh.main.mainactivity ( Server) ' ~ Channel is unrecoverably broken and'll be disposed!
==================== Solution 1====================
The problem isn't at the level of code you posted.
We need to track and debug.

Read the value of the database displayed on the ListView

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.