android - NullPointerException error in my ListView -


I have a piece that I call ListView

One part of my code to be displayed

  Expenditure of the public square expands daily daily expansion {@ Override public void on crate (bundle saved instanestate) {super.onCreate (savedInstanceState ); LvExpenses = (ListView) getActivity (). FindViewById (android.R.id.list); Cursor expense list cursor; DBctrol DBC = New DB Control (Received Activity); Try {dbc.open (); ExpensesListCursor = dbc.list Expense (); String [] = new string [] {"description", "cost"}; List Adapter Adapter = New Acquisition (GetActivity), R.Lay Out.list_express, Exchange Listworker, New Ent [] (R.D.V.Description, R.D. tvCost}, 0); LvExpenses.setAdapter ();} Hold (SQLException e) {} dbc.close ();} @ Override Public View Creatives (LayoutInflator Influent, View Group Container, Bundle Saved InstantState) {Final View Rootview = Inflator.In Falette (R) Late expans_deli, container, false) ; Return route view;}} ** DbControl class **  
  Public class DbControl {Private SQLite database database; Private MySQLiteHelper dbHelper; Public DbControl ( Reference Reference) {dbHelper = new MySQLiteHelper ()}} Public Zero Open () throws SQLException {database = dbHelper.getWritableDatabase ();} Public Zero Closure () {dbHelper.close ();} Public cursor list expense () {Cursor cursor; cursor = database.query (MySQLiteHelper.TABLE_EXPENSES, new string [] {"id _id", "description, cost"}, "forDate = '" + + + "" ", blank, empty, empty, "Id ask"); If (cursor! = Null) {cursor.moveToFirst (); } Return cursor; }   

expenses_daily.xml

  & lt; LinearLayout xmlns: android = "http://schemas.android.com/ Apk / res / android" Android: Orientation = "Vertical" Android: layout_width = "match_parent" Android: layout_height = "match_parent" Android: id = "@ + ID / Lao Expense Daily "Android: Baseline Alliance =" False "& gt; & Lt; LinearLayout Android: layout_width = "fill_parent" Android: layout_height = "fill_parent" Android: Orientation = "horizontal" & gt; & Lt; ListView Android: id = "@ android: id / list" Android: layout_width = "fill_parent" android: layout_height = "wrap_content" & gt; & Lt; / ListView & gt; & Lt; / LinearLayout & gt; & Lt; / LinearLayout & gt;   

list_expenses.xml

  & lt; LinearLayout xmlns: android = "http://schemas.android.com/apk/Res/ android" android: orientation = "vertical" Android: layout_width = "match_parent" Android: layout_height = "match_parent" & gt; & Lt; LinearLayout Android: layout_width = "match_parent" android: layout_height = "wrap_content" android: orientation = "horizontal" Android: padding = "7dip" & gt; & Lt; TextView android: layout_width = "0dip" Android: layout_height = "wrap_content" android: layout_weight = "0.6" Android: id = "@ + id / tvDescription" /> & Lt; TextView android: layout_width = "0dip" Android: layout_height = "wrap_content" Android: layout_weight = "0.3" Android: id = "@ + id / tvCost" /> & Lt; / LinearLayout & gt; & Lt; / LinearLayout & gt;   

But every time I load the piece, it will display this error

  Fatal exception: main java.lang.NullPointerException com.code Imin.mymoneymanaged at Expense Daily Contatt (expans deli. Java: 60)   

indicates the row

  lvExpenses.setAdapter (class) in Class Expex daily  < / Pre>  

lvExpenses = (list view) getActivity (). FindViewById (android.r.id.list);

You can not call getActivity (). OnViewById onCreate Change the logic to onActivityCreated because the view was not created yet

Enter image details here

Comments

Popular posts from this blog

java - ImportError: No module named py4j.java_gateway -

python - Receiving "KeyError" after decoding json result from url -

.net - Creating a new Queue Manager and Queue in Websphere MQ (using C#) -