Android에서 레이아웃 확장을 사용할 때 Null 포인터 예외

코 데르 바라캇

TextViewmySQL에서 데이터를 검색 한 후 텍스트를 설정하려고 할 때 어댑터에 문제가 있습니다 . Doinbackground()+ jsonParsing이 성공했습니다.

입력 할 때 onPostexecute가격의 텍스트를 "anything"으로 설정하려고합니다 null pointer exception.

내가 주석을 price.setText("anything");달면 앱이 정상적으로 실행되고 URL에서 2 개의 json 객체 인스턴스를 얻고 내에서 두 개의 객체를 생성 listview하지만 물론 검색 된 데이터는 없습니다.

이것은 또한 모두와 함께 일어나고 TextViewsetText().

코드는 다음과 같습니다.

     public class Search extends Activity  {
 public static  String IP=Mysynch.IP;
static String url="http://"+IP+":80/senior/getStoreItemtoJson.php";
 String Scatid; 
String Sitemid;
String Suserid;
String Sdescription;
String Sprice;
String Squantity;
String Showmanyorders;
String Sprocessingtime;
String Sdeliverytime;
String Sdateadded;
String Sbrand;
String Ssale;
String Sbrandnew;
String Ssecondhand;
Activity activity;
List<Itemclass> list=new ArrayList<Itemclass>();
TextView  price;


TextView  desc;
TextView  quantity;


 ListView listview;
ViewGroup viewgroup;
Itemclass itemclass;Itemclass currentitem ;

    @Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    System.out.println(url);
    setContentView(R.layout.search);


        (new myAsynctask()).execute();

        System.out.println("Create");
       }



         public class myAsynctask extends AsyncTask<String, Void, Boolean>
      {
protected void onPreExecute()
{
    System.out.println("pre");
}

protected Boolean  doInBackground(final String... args) {
    System.out.println("Enter background");
    //this client handles the download and upload of the info
         DefaultHttpClient httpclient=new DefaultHttpClient(new BasicHttpParams());
         // Here we pass the url 
         HttpPost httppost=new HttpPost(url);
         httppost.setHeader("Content-type","application/json");
         InputStream inputstream=null;
         String result=null;

         try{
        HttpResponse response=httpclient.execute(httppost);  
        HttpEntity entity=response.getEntity();
        inputstream=entity.getContent();
        BufferedReader reader=new BufferedReader(new InputStreamReader(inputstream,"UTF-                 8"),8);
        StringBuilder Sbuilder=new StringBuilder();
        String line=null;
        while((line=reader.readLine())!=null){
            Sbuilder.append(line+'\n');
        }
             result=Sbuilder.toString();


         }

         catch(Exception e){
             e.printStackTrace();

         }finally{
             try{if(inputstream !=null )
            inputstream.close();     

             }
             catch(Exception e){
                 e.printStackTrace();
             }
         };
         System.out.println("finish conx + json");

         JSONArray jsonArray;
         try{
             //jibit awal json object ili howi b2albo kil shi
             JSONObject jsonobj=new JSONObject(result); 
           // String s= jsonobj.getString("success");
             //System.out.println(s);
           //String e=  jsonobj.getString("error");
           //System.out.println(e);
           jsonArray=jsonobj.getJSONArray("item");
             //how to get all objects into a json array
            // query array fiya kil el names ta3on el quote object eli jibti fo2
            //create a list
            for(int i=0;i<jsonArray.length();i++){
                JSONObject jsonline=jsonArray.getJSONObject(i);
                Scatid=jsonline.getString("catid");
                Sitemid=jsonline.getString("itemid");
                Suserid=jsonline.getString("userid");
                Sdescription=jsonline.getString("description");
                Sprice=jsonline.getString("price");
                Squantity=jsonline.getString("quantity");
                Showmanyorders=jsonline.getString("howmanyorders");
                Sprocessingtime=jsonline.getString("processingtime");
                Sdeliverytime=jsonline.getString("deliverytime");
                Sdateadded=jsonline.getString("dateadded");
                Sbrand=jsonline.getString("brand");
                Ssale=jsonline.getString("sale");
                Sbrandnew=jsonline.getString("brandnew");
                Ssecondhand=jsonline.getString("secondhand");


            Itemclass item=new Itemclass(Scatid, Sitemid, Suserid, Sdescription, Sprice,      Squantity, Showmanyorders, 
                    Sprocessingtime, Sdeliverytime, Sdateadded, Sbrand, Ssale, Sbrandnew, Ssecondhand);
            list.add(item);
            System.out.println("*******"+Sprice);
            }

         }catch(JSONException e ){
             e.printStackTrace();
         }
         System.out.println("*****************************************");
    return true;

}

protected void onPostExecute(final Boolean success)
{


    System.out.print("enter post");
    if(success){
        System.out.print(" enter initialize list"); 
        listview=(ListView)findViewById(R.id.listView1);
        ArrayAdapter<Itemclass> adapter = new MyListAdapter();

        listview.setAdapter(adapter);
        System.out.print("initialize list");        }
}
    }

              private class MyListAdapter extends ArrayAdapter<Itemclass> {
public MyListAdapter() {
    super(Search.this, R.layout.searchlistitems, list);
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {

    // Make sure we have a view to work with (may have been given null)
    View itemView = convertView;
    if (itemView == null) {


            itemView   =getLayoutInflater().inflate(R.layout.searchlistitems,
           parent, false);


         }

    currentitem = list.get(position);
    price=(TextView)findViewById(R.id.tvSearchprice);
    desc=(TextView)findViewById(R.id.tvsearchDescr);
    quantity=(TextView)findViewById(R.id.tvSearchquantity);

    System.out.println("position===>>>>"+position);
// price.setText("any thing");//<======== my problem is here


    // Fill the view
//ImageView imageView = (ImageView)itemView.findViewById(R.id.item_icon);
//imageView.setImageResource(currentCar.getIconID());





//desc.setText(currentitem.description);

    //      quantity.setText(currentitem.quantity);

           System.out.println("desc===>>>>"+currentitem.description);
    return itemView;
}               
     }


         }
fllo

다음 getView과 같은 방법으로 레이아웃을 확장 할 때 :

itemView = getLayoutInflater().inflate(R.layout.searchlistitems, parent, false);

이 확장 된 뷰를 사용하여 다음과 같이 자식 뷰를 검색합니다.

price = (TextView) itemView.findViewById(R.id.tvSearchprice); // use itemView
desc = (TextView) itemView.findViewById(R.id.tvsearchDescr);
quantity = (TextView) itemView.findViewById(R.id.tvSearchquantity);  

그러나 어댑터 성능향상 시키기 위해 ViewHolder패턴을 사용하는 것이 좋습니다 . 다음은 훌륭한 주제입니다. Android의 ListView에 대한 성능 팁 과 간단한 자습서 : Android ViewHolder 패턴 예제 . ListView 스크롤 중에 자주 호출되는 것을 피할 수 있습니다.findViewById()

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

Android Firebase에서 항목을 삭제하려고 할 때 Null 포인터 예외

분류에서Dev

메서드에서 (java.util.Random)을 사용하려고 할 때 Null 포인터 예외-초급 Java

분류에서Dev

Android-서랍 레이아웃-서랍을 닫으면 Null 포인터 예외 발생

분류에서Dev

빈 Excel 셀의 길이를 확인할 때 Java Null 포인터 예외 발생

분류에서Dev

Java에서 HashMap 값을 반환하려고 할 때 Null 포인터 예외

분류에서Dev

GSP 페이지에서 루프를 실행할 때 Null 포인터 예외

분류에서Dev

Android에서 SQLite 데이터베이스를 쿼리 할 때 Java Null 포인터 예외

분류에서Dev

Google 지역 정보를 사용할 때 Android Null 포인터 예외

분류에서Dev

Android에서 동일한 활동에서 두 개의 Volley 요청을 사용할 때 null 포인터 예외를 수정하는 방법은 무엇입니까?

분류에서Dev

CustomList 어댑터를 사용할 때 Null 포인터 예외

분류에서Dev

ArrayList에 쓸 때 Null 포인터 예외

분류에서Dev

밝기 설정을 조정할 때 Null 포인터 예외

분류에서Dev

XML을 Hive로로드 할 때 Null 포인터 예외

분류에서Dev

com.sun.jdi.InvocationException이 메서드를 호출하는 동안 "null 포인터 예외"가 발생했습니다. 셀레늄에서 PageFactory를 사용할 때

분류에서Dev

imageView를 사용할 때 Null 포인터 예외

분류에서Dev

riemann을 사용하여 파일에 쓰려고 할 때 널 포인터 예외

분류에서Dev

printf 문을 추가 할 때 NULL 포인터 예외가 사라집니다.

분류에서Dev

앱에서 SQLite 데이터베이스를 만들 때 Null 포인터 예외

분류에서Dev

전역 변수에서 값을 가져 오려고 할 때 Null 포인터 예외가 발생합니다.

분류에서Dev

Dropbox에서 파일을 다운로드하려고 할 때 null 포인터 예외가 발생합니다.

분류에서Dev

Android getParentFragment () 레이아웃에서 직접 조각을 팽창 할 때 Null

분류에서Dev

조각간에 데이터를 전달하려고 할 때 Null 포인터 예외

분류에서Dev

타사 카메라 응용 프로그램을 선택할 때 카메라 의도의 Null 포인터 예외

분류에서Dev

확인란을 사용하는 Null 포인터 예외

분류에서Dev

라디오 버튼을 사용할 때 널 포인터 예외

분류에서Dev

Android 용 Facebook SDK null 포인터 예외

분류에서Dev

사용자 정의 목록보기에서 단일 행을 업데이트하기 위해 getListView ()를 사용할 때 널 포인터 예외

분류에서Dev

2D 배열을 버블 정렬 할 때 Null 포인터 예외

분류에서Dev

TestNG를 통해 Selenium을 실행할 때 Null 포인터 예외 발생

Related 관련 기사

  1. 1

    Android Firebase에서 항목을 삭제하려고 할 때 Null 포인터 예외

  2. 2

    메서드에서 (java.util.Random)을 사용하려고 할 때 Null 포인터 예외-초급 Java

  3. 3

    Android-서랍 레이아웃-서랍을 닫으면 Null 포인터 예외 발생

  4. 4

    빈 Excel 셀의 길이를 확인할 때 Java Null 포인터 예외 발생

  5. 5

    Java에서 HashMap 값을 반환하려고 할 때 Null 포인터 예외

  6. 6

    GSP 페이지에서 루프를 실행할 때 Null 포인터 예외

  7. 7

    Android에서 SQLite 데이터베이스를 쿼리 할 때 Java Null 포인터 예외

  8. 8

    Google 지역 정보를 사용할 때 Android Null 포인터 예외

  9. 9

    Android에서 동일한 활동에서 두 개의 Volley 요청을 사용할 때 null 포인터 예외를 수정하는 방법은 무엇입니까?

  10. 10

    CustomList 어댑터를 사용할 때 Null 포인터 예외

  11. 11

    ArrayList에 쓸 때 Null 포인터 예외

  12. 12

    밝기 설정을 조정할 때 Null 포인터 예외

  13. 13

    XML을 Hive로로드 할 때 Null 포인터 예외

  14. 14

    com.sun.jdi.InvocationException이 메서드를 호출하는 동안 "null 포인터 예외"가 발생했습니다. 셀레늄에서 PageFactory를 사용할 때

  15. 15

    imageView를 사용할 때 Null 포인터 예외

  16. 16

    riemann을 사용하여 파일에 쓰려고 할 때 널 포인터 예외

  17. 17

    printf 문을 추가 할 때 NULL 포인터 예외가 사라집니다.

  18. 18

    앱에서 SQLite 데이터베이스를 만들 때 Null 포인터 예외

  19. 19

    전역 변수에서 값을 가져 오려고 할 때 Null 포인터 예외가 발생합니다.

  20. 20

    Dropbox에서 파일을 다운로드하려고 할 때 null 포인터 예외가 발생합니다.

  21. 21

    Android getParentFragment () 레이아웃에서 직접 조각을 팽창 할 때 Null

  22. 22

    조각간에 데이터를 전달하려고 할 때 Null 포인터 예외

  23. 23

    타사 카메라 응용 프로그램을 선택할 때 카메라 의도의 Null 포인터 예외

  24. 24

    확인란을 사용하는 Null 포인터 예외

  25. 25

    라디오 버튼을 사용할 때 널 포인터 예외

  26. 26

    Android 용 Facebook SDK null 포인터 예외

  27. 27

    사용자 정의 목록보기에서 단일 행을 업데이트하기 위해 getListView ()를 사용할 때 널 포인터 예외

  28. 28

    2D 배열을 버블 정렬 할 때 Null 포인터 예외

  29. 29

    TestNG를 통해 Selenium을 실행할 때 Null 포인터 예외 발생

뜨겁다태그

보관