0

我进口崩溃时,通话清单转接器内片段

import java.util.ArrayList; 

import org.w3c.dom.Document; 
import org.w3c.dom.Element; 
import org.w3c.dom.NodeList; 

import com.dwellesque.R; 
import com.dwellesque.util.Extraadap; 
import com.dwellesque.util.XMLfunctions; 

import android.app.Fragment; 
import android.os.Bundle; 
import android.util.Log; 
import android.view.LayoutInflater; 
import android.view.View; 
import android.view.ViewGroup; 
import android.widget.AbsListView; 
import android.widget.ListView; 
import android.widget.TextView; 
import android.widget.Toast; 

public class LoginsearchResult extends Fragment{ 

查看关于创建方法

public LoginsearchResult() 
{ 

} 
    public View onCreateView(LayoutInflater inflater, ViewGroup container, 
      Bundle savedInstanceState) { 
     View rootView; 
     String data=null; 


     rootView = inflater.inflate(R.layout.loginsearchresult,container,false); 
     txtType = (TextView) rootView.findViewById(R.id.logintype); 
      lstJobs= (ListView) rootView.findViewById(R.id.loginlist); 
     lstJobs.setChoiceMode(AbsListView.CHOICE_MODE_MULTIPLE); 

     showdata(data); 

     return rootView; 

    } 

通话清单适配器

Extraadap adapter= new Extraadap(getActivity(),strimage, strname, loc, square, price,strposted); 
      lstJobs.setAdapter(adapter); 

Extraadap类

public class Extraadap extends ArrayAdapter<String>{ 
ImageView imgProperty; 
TextView txtposted; 
TextView txtStreetName; 
TextView txtLocation; 
TextView txtSquareFotage; 
TextView txtPrice; 
ImageView imglike; 
Context context; 
String[] strimgview,strstreetname,strLocation,strSquarefootage,strPrice,strPosted; 
public ImageLoader imageLoader; 
public Extraadap(Context context,String[] strimgview, String[] strstreetname, String[] strLocation, 
          String[] strSquarefootage, String[] strPrice,String[] strPosted) 
{ 
    super(context, R.layout.propertyrow,strstreetname); 
    this.context= context; 
    this.strimgview= strimgview; 
    this.strstreetname= strstreetname; 
    this.strLocation= strLocation; 
    this.strSquarefootage= strSquarefootage; 
    this.strPrice= strPrice; 
    this.strPosted= strPosted; 

    imageLoader = new ImageLoader(context); 
} 
public View getView(int position, View convertView, ViewGroup parent) { 
    LayoutInflater mInflater = (LayoutInflater) context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE); 
    View row; 
    row=mInflater.inflate(R.layout.propertyrow, parent,false); 
    imgProperty =(ImageView) row.findViewById(R.id.npTupleImage); 
    txtStreetName= (TextView) row.findViewById(R.id.npTupleProjectName); 
    txtLocation= (TextView) row.findViewById(R.id.npTupleBuilder); 
    txtSquareFotage= (TextView) row.findViewById(R.id.npTupleProjectAddress); 
    txtPrice =(TextView) row.findViewById(R.id.npTupleProjectDistance); 
    txtposted =(TextView) row.findViewById(R.id.npTuplePossession); 
    imglike= (ImageView) row.findViewById(R.id.unsavebtn); 

    txtposted.setText("EnteredDate :"+strPosted[position]); 
     txtStreetName.setText("Street Name :"+strstreetname[position]); 
     txtLocation.setText("Location :"+strLocation[position]); 
     txtSquareFotage.setText("SquareFootage :"+strSquarefootage[position]); 
     txtPrice.setText("Price :$"+strPrice[position]); 
     Log.d("Img",strimgview[position]); 
    try{ 
     imageLoader.DisplayImage(strimgview[position], imgProperty); 
     Log.d("imageUrl", strimgview[position]); 
    } 
    catch(Exception e) 
    { 
     Toast.makeText(context, "Load"+e, Toast.LENGTH_LONG).show(); 
    } 
     imglike.setOnClickListener(new OnClickListener() { 

     @Override 
     public void onClick(View v) { 
      // TODO Auto-generated method stub 
      Toast.makeText(context, "Want to save", Toast.LENGTH_LONG).show(); 

     } 
    }); 
    return row; 


} 

}

当我打电话LoginsearchResult零散类然后应用崩溃

我的logcat

04-16 15:03:14.815: E/AndroidRuntime(1956): FATAL EXCEPTION: main 
    04-16 15:03:14.815: E/AndroidRuntime(1956): 
    java.lang.NullPointerException 04-16 15:03:14.815: 
    E/AndroidRuntime(1956): at 
    com.dwellesque.LoginsearchResult.showdata(LoginsearchResult.java:249) 
    04-16 15:03:14.815: E/AndroidRuntime(1956): at 
    com.dwellesque.LoginsearchResult.onCreateView(LoginsearchResult.java:57) 
    04-16 15:03:14.815: E/AndroidRuntime(1956): at 
    android.app.FragmentManagerImpl.moveToState(FragmentManager.java:829) 
    04-16 15:03:14.815: E/AndroidRuntime(1956): at 
    android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1035) 
    04-16 15:03:14.815: E/AndroidRuntime(1956): at 
    android.app.BackStackRecord.run(BackStackRecord.java:635) 04-16 
    15:03:14.815: E/AndroidRuntime(1956): at 
    android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1397) 
    04-16 15:03:14.815: E/AndroidRuntime(1956): at 
    android.app.FragmentManagerImpl$1.run(FragmentManager.java:426) 04-16 
    15:03:14.815: E/AndroidRuntime(1956): at 
    android.os.Handler.handleCallback(Handler.java:615) 04-16 
    15:03:14.815: E/AndroidRuntime(1956): at 
    android.os.Handler.dispatchMessage(Handler.java:92) 04-16 
    15:03:14.815: E/AndroidRuntime(1956): at 
    android.os.Looper.loop(Looper.java:137) 04-16 15:03:14.815: 
    E/AndroidRuntime(1956): at 
    android.app.ActivityThread.main(ActivityThread.java:4745) 04-16 
    15:03:14.815: E/AndroidRuntime(1956): at 
    java.lang.reflect.Method.invokeNative(Native Method) 04-16 
    15:03:14.815: E/AndroidRuntime(1956): at 
    java.lang.reflect.Method.invoke(Method.java:511) 04-16 15:03:14.815: 
    E/AndroidRuntime(1956): at 
    com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786) 
    04-16 15:03:14.815: E/AndroidRuntime(1956): at 
    com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553) 04-16 
    15:03:14.815: E/AndroidRuntime(1956): at 
    dalvik.system.NativeStart.main(Native Method) 04-16 15:03:16.616: 
    E/Trace(1984): error opening trace file: No such file or directory 
    (2) 

showdata()方法

void showdata(String data) 
    { 
     doc = XMLfunctions.XMLfromString(data); 
     NodeList nodes = doc.getElementsByTagName("PROPERTY"); 
      for (int i = 0; i < nodes.getLength(); i++) { 
       Element e = (Element) nodes.item(i); 

       // Street Name 

       if (!("null").equals(XMLfunctions.getValue(e, "street"))) { 
        mainList.add(XMLfunctions.getValue(e, "street")); 
        arliststitname.add(XMLfunctions.getValue(e, "street")); 


       } else { 
        mainList.add(" "); 
       } 

       // Location 

       if (!("null").equals(XMLfunctions.getValue(e, "city"))) { 
        if(!("null").equals(XMLfunctions.getValue(e, "state"))) 
        { 
         mainList.add(XMLfunctions.getValue(e, "city")+" ,"+XMLfunctions.getValue(e, "state")); 
         arlistlocation.add(XMLfunctions.getValue(e, "city")+" ,"+XMLfunctions.getValue(e, "state")); 
        } 
        mainList.add(XMLfunctions.getValue(e, "city")); 
        arlistlocation.add(XMLfunctions.getValue(e, "city")); 


       } else { 
        mainList.add(" "); 
       } 

       // Square Footage 

       if (!("null").equals(XMLfunctions.getValue(e, "SquareFootage"))) { 
        mainList.add(XMLfunctions.getValue(e, "SquareFootage")); 
        arlistsqare.add(XMLfunctions.getValue(e, "SquareFootage")); 


       } else { 
        mainList.add(" "); 
       } 

      // price 

       if (!("null").equals(XMLfunctions.getValue(e, "price"))) { 
        mainList.add(XMLfunctions.getValue(e, "price")); 
        arlistprice.add(XMLfunctions.getValue(e, "price")); 


       } else { 
        mainList.add(" "); 
       } 

       // Images 

       if (!("null").equals(XMLfunctions.getValue(e, "picture"))) { 
        mainList.add(XMLfunctions.getValue(e, "picture")); 
        arlistimg.add(XMLfunctions.getValue(e, "picture")); 
        Log.d("imageUrlIf", XMLfunctions.getValue(e, "picture")); 

       } else { 

        Log.d("imageUrlelse",XMLfunctions.getValue(e, "picture")); 
        mainList.add(""); 

       } 


       // posted on 

       if (!("null").equals(XMLfunctions.getValue(e, "EnteredDate"))) { 
        mainList.add(XMLfunctions.getValue(e, "EnteredDate")); 
        arlistposted.add(XMLfunctions.getValue(e, "EnteredDate")); 


       } else { 


        mainList.add(""); 

       } 

       if (!("null").equals(XMLfunctions.getValue(e, "description"))) { 
        mainList.add(XMLfunctions.getValue(e, "description")); 
        arlistDesc.add(XMLfunctions.getValue(e, "description")); 


       } else { 


        mainList.add(""); 

       } 

       if (!("null").equals(XMLfunctions.getValue(e, "propertystatus"))) { 
        mainList.add(XMLfunctions.getValue(e, "propertystatus")); 
        arlistproperty.add(XMLfunctions.getValue(e, "propertystatus")); 


       } else { 


        mainList.add(""); 

       } 


       if (!("null").equals(XMLfunctions.getValue(e, "EnteredDate"))) { 
        mainList.add(XMLfunctions.getValue(e, "EnteredDate")); 
        arlistyear.add(XMLfunctions.getValue(e, "EnteredDate")); 


       } else { 


        mainList.add(""); 

       } 

       //URL 

       if (!("null").equals(XMLfunctions.getValue(e, "url"))) { 
        mainList.add(XMLfunctions.getValue(e, "url")); 
        arlisturl.add(XMLfunctions.getValue(e, "url")); 


       } else { 


        mainList.add(""); 

       } 


      } 

      strposted = new String[arlistposted.size()]; 
      strposted = arlistposted.toArray(strposted); 

       strname = new String[arliststitname.size()]; 
       strname = arliststitname.toArray(strname); 

       loc = new String[arlistlocation.size()]; 
       loc = arlistlocation.toArray(loc); 

       square = new String[arlistsqare.size()]; 
       square = arlistsqare.toArray(square); 

       price = new String[arlistprice.size()]; 
       price = arlistprice.toArray(price); 

       strimage = new String[arlistimg.size()]; 
       strimage = arlistimg.toArray(strimage); 

       strpStatus = new String[arlistproperty.size()]; 
       strpStatus = arlistproperty.toArray(strpStatus); 


       strDesc = new String[arlistDesc.size()]; 
       strDesc = arlistDesc.toArray(strDesc); 

       strYear = new String[arlistyear.size()]; 
       strYear = arlistyear.toArray(strYear); 

       // int currentPosition =lstJobs.getFirstVisiblePosition(); 
      // List Adapter 

      Extraadap adapter= new Extraadap(getActivity(),strimage, strname, loc, square, price,strposted); 
      lstJobs.setAdapter(adapter); 

        // Log.d("List",""+e); 
        // Toast.makeText(getActivity(), "ss"+e, Toast.LENGTH_LONG).show(); 

       //tSelectionFromTop(currentPosition, 0); 
    } 

列表视图布局

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:orientation="vertical" 
android:background="@drawable/bg" > 
<LinearLayout 
android:id="@+id/top" 
android:layout_height="wrap_content" 
android:layout_width="fill_parent" 
android:background="#F0F0F0"> 

<TextView 

    android:layout_marginTop="0dip" 
    android:id="@+id/logintype" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_centerHorizontal="true" 
    android:textStyle="bold" 

    android:textSize="18sp" 
    android:text="TextView" /> 
</LinearLayout> 

<ListView 
    android:id="@+id/loginlist" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_below="@id/top" > 

    </ListView> 

</RelativeLayout> 

请帮助我如何解决此问题

在此先感谢。

+0

R.id.list use that not android.R.id.list –

+0

感谢您的重播,同样的问题发生我同时使用.. – Kuldeep

+0

你可以把showdata方法代码!!! –

回答

1

首先纠正这

lstJobs= (ListView) rootView.findViewById(android.R.id.list); 

lstJobs= (ListView) rootView.findViewById(R.id.list); 

,你确保你在loginsearchresult.xml布局有ListView ID为list

更新:试试这个

+0

感谢您的重播,同样的问题发生我使用了两个.. – Kuldeep

+0

所有权利发布你的布局,码。 –

+0

请参阅更新的问题我张贴布局 – Kuldeep