android - Fragment with ListView: NullPointerException on setAdapter -
I have a problem, when I want to set the adapter on my ListView, I get a NullPointExeption before I Increased fragmentation with listfreagment and a simple adapter, before the problem was that it works but the problem is that I have 3 pieces in this activity with list activity and I found performance errors (shows the wrong list in one piece is). That's why I decided to set my own id of each piece on the list view, but now it does not work.
Error List View Ksetadaptr (adapter):
De.resper.e2cast.MainFragmentLive.onCreateView (MainFragmentLive.java:46) on java.lang.NullPointerException
piece:
import android.os.Bundle; Import android.util.log; Import android.view.LayoutInflater; Import android.view.View; Import android.view.ViewGroup; Import android.widget.ArrayAdapter; Import android.widget.ImageButton; Import android.widget.ListView; Import java.util.ArrayList; Import java.util.list; Import de.resper.e2cast.classes.globalBox; Import de.resper.e2cast.helper.getXml; Import de.resper.e2cast.helper.parseXml; Public Class Mainfragment Live Android Support.v4.app.Fragment {Private list & lt; String & gt; BouquetListString; Private array adapter & lt; String & gt; Adapter; Private globalbox active box; Private list view list view; See @ Override public Kriattiwu (Leautifltr Infletr, View Group container, bundle saved Instensstet) {views = Infliattrkflat (r. Lett. Fragment_man_liv, container, false); ActiveBox = ((global box) getActivity (). GetApplicationContext ()); Bouquet ListString = New Arrestist & lt; String & gt; (); BouquetListString.add ("Loading ..."); If> (activeBox.isInit ()) {if (activeBox.getBouquets (). Size ()> 0 & amp; amp; amp; Skriybokskbetkwakets (). Get (2). Size () gt; {bouquetListString = activeBox GetBouquets (find) (2).} other {log d. ( "load bouquet", "XML"); getBouquetBox ();}} Listview = (ListView) getActivity (). FindViewById (R.id.listLive); adapter = new Arre adapter & lt; string & gt; (getActivity (), android.R.layout.simple_list_item_1, bouquet list string); ListviewksetAdapter (adapter); Imejhbtn reload Bkaiket = (Imejbtn) Drishykfnd Vibiiaidi (R .IDRelodeBokket); ReloadBouquet.setOnClickListener (new view .OnClickListener () {@Override on public void (see ARG0) {getBouquetBox ();}}); setHasOptionsMenu (right), back view;} public void getBouquetBox () {getXml.DownloadCompleteListener DCL = new GetXmlkDownloadCompleteListener ( ) {@Override Public Zero onDownloadComplete (string result) {bouquetListString.clear (); string [] tag = {"e2servicereference", "e2servicename"}; & Lt; From the list & lt; String & gt; & Gt; BouquetsList = parseXml.parseXmlByTag (Results, tags); ActiveBox.addBouquets (bouquetsList); BouquetListString.addAll (activeBox.getBouquets () find (2).); Adapter.notifyDataSetChanged (); }}; Log D. ("MyLoger", "XML Request Box"); GetXml Downloader = New getXml (dcl); Downloader.execute ("http: //" + ActiveBox.IIP Port (++ / "Web / SmarterIs");}}
Piece XML:
< code> & lt ;? Xml version = "1.0" encoding = "UTF -8"? & Gt; & Lt; LinearLayout xmlns: android = "http://schemas.android.com/apk/res/android" android: Orientation: "vertical" Android: layout_width = "match_parent" Android: layout_height = "match_parent"> LinearLayout Android: layout_width = "match_parent" Android: layout_height = "wrap_content" Android: orientation = "horizontal" Android: layout_margin = "8dp">> TextView Android: layout_width = "0dip" Android: layout_height = "wrap_content" and Roid: layout_weight = "0.8" android: text = "@ string / selectBouquet" style = "@ style / header1" / & gt; & LT; ImageButton Android: layout_width = "0dip" Android: Layout_height = "Wrap_content" android: id = "@ + Id / reloadBouquet" Android: src = "@ drawable / ic_action_refresh" Android: Content Circles = "@ String / Search" Android: Layout_weight = ". 20 "Android: Leaut_graviti =" Bottom "/ & gt; & Lt; / LinearLayout & gt; & Lt; see Android: Layout_width =" Fill_parent "Android: Layout_height =" Ldp "android: background =" @ android: color / Andere_gray "/ & gt; & Lt; ListView android: layout_width =" match_parent "Android: layout_height =" wrap_content "android: id =" @ + id / list Live "/ & gt; & Lt; / LinearLayout & gt;Use
getActivity () instead of
see listView start because the piece is inside the piece instead of theView activity:
listview = (ListView) view.findViewById (R.id.listLive);
Comments
Post a Comment