android - When application running in the device how to handle null pointer exception
<p>In My application have one Text view,one rating bar and one Text view( Like this 3 are there). These are filled with the web service response. i got web service response correctly. In Emulator its working properly. But in device i am getting the NPE.  i am getting the NPE at  </p>

<pre><code>try{
        holder.r2.setRating(ksrating_value_w_onedecimal);
    }
</code></pre>

<p>Here i am getting the holder.r2 address is NULL in device(not in emulator). Why here i am not getting the address of holder.r2. can anybody help me</p>

<p>stack trace</p>

<pre><code>07-21 12:42:04.289: ERROR/AndroidRuntime(3400): java.lang.NullPointerException

07-21 12:42:04.289: ERROR/AndroidRuntime(3400):     at com.ibkr.roadbrake.RB_StaticSearchResults$StaticSearchResultsListViewAdapter.getView(RB_StaticSearchResults.java:1097)

07-21 12:42:04.289: ERROR/AndroidRuntime(3400):     at android.widget.AbsListView.obtainView(AbsListView.java:1367)

07-21 12:42:04.289: ERROR/AndroidRuntime(3400):     at android.widget.ListView.makeAndAddView(ListView.java:1734)

07-21 12:42:04.289: ERROR/AndroidRuntime(3400):     at android.widget.ListView.fillDown(ListView.java:703)

07-21 12:42:04.289: ERROR/AndroidRuntime(3400):     at android.widget.ListView.fillGap(ListView.java:674)

07-21 12:42:04.289: ERROR/AndroidRuntime(3400):     at android.widget.AbsListView.trackMotionScroll(AbsListView.java:2891)

07-21 12:42:04.289: ERROR/AndroidRuntime(3400):     at android.widget.AbsListView$FlingRunnable.run(AbsListView.java:2617)

07-21 12:42:04.289: ERROR/AndroidRuntime(3400):     at android.os.Handler.handleCallback(Handler.java:587)

07-21 12:42:04.289: ERROR/AndroidRuntime(3400):     at android.os.Handler.dispatchMessage(Handler.java:92)

07-21 12:42:04.289: ERROR/AndroidRuntime(3400):     at android.os.Looper.loop(Looper.java:123)

07-21 12:42:04.289: ERROR/AndroidRuntime(3400):     at android.app.ActivityThread.main(ActivityThread.java:4363)

07-21 12:42:04.289: ERROR/AndroidRuntime(3400):     at java.lang.reflect.Method.invokeNative(Native Method)

07-21 12:42:04.289: ERROR/AndroidRuntime(3400):     at java.lang.reflect.Method.invoke(Method.java:521)

07-21 12:42:04.289: ERROR/AndroidRuntime(3400):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:862)

07-21 12:42:04.289: ERROR/AndroidRuntime(3400):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:620)

07-21 12:42:04.289: ERROR/AndroidRuntime(3400):     at dalvik.system.NativeStart.main(Native Method)
</code></pre>

<p><strong>Java</strong></p>

<pre><code>   public View getView(final int position, View convertView, ViewGroup parent) {           

        class ViewHolder {
            TextView Res_Name;               
            RatingBar r1,r2,r3;
            TextView ratingpts, ratingpks, ratingprr;               
        }
        ViewHolder holder;

        convertView = mInflater.inflate(R.layout.stsearchresults_eachitem, null);               
        holder = new ViewHolder();
        holder.Res_Name = (TextView) convertView.findViewById(R.id.restaurantname);
        holder.r1 = (RatingBar)convertView.findViewById(R.id.small_ratingbar);
        holder.ratingpts = (TextView)convertView.findViewById(R.id.ratingpts);                
        holder.r2 = (RatingBar)convertView.findViewById(R.id.kssmall_ratingbar);
        holder.ratingpks = (TextView)convertView.findViewById(R.id.ratingpks);
        holder.r3 = (RatingBar)convertView.findViewById(R.id.rrsmall_ratingbar);
        holder.ratingprr = (TextView)convertView.findViewById(R.id.ratingprr);          

        String Res_Name_Draw = (String)RB_Constant.filterSearchResultObj.response.get(position).Name;
        holder.Res_Name.setText(Res_Name_Draw);

        float rating = RB_Constant.filterSearchResultObj.response.get(position).Rating;
        float rating_value = Math.round(rating * 10);           
        float rating_value_w_onedecimal = rating_value / 10;                       
        try{
            holder.r1.setRating(rating_value_w_onedecimal);
        }
        catch(Exception e){
            System.out.println("Error-&gt;"+e.toString()+" position "+position);
        }            
        holder.ratingpts.setText(""+rating_value_w_onedecimal);     

        float ksrating = RB_Constant.filterSearchResultObj.response.get(position).KidsRating;
        float ksrating_value = Math.round(ksrating * 10);           
        float ksrating_value_w_onedecimal = ksrating_value / 10;
        try{
            holder.r2.setRating(ksrating_value_w_onedecimal);
        }
        catch(Exception e){
            System.out.println("Error-&gt;"+e.toString()+" position "+position);
        }            
        holder.ratingpks.setText(""+ksrating_value_w_onedecimal);  

        float rrrating = RB_Constant.filterSearchResultObj.response.get(position).RestRoomRating;
        float rrrating_value = Math.round(rrrating * 10);           
        float rrrating_value_w_onedecimal = rrrating_value / 10;
        try{
            holder.r3.setRating(rrrating_value_w_onedecimal);
        }
        catch(Exception e){
            System.out.println("Error-&gt;"+e.toString()+" position "+position);
        }            
        holder.ratingprr.setText(""+rrrating_value_w_onedecimal);  
            return convertView;
    } 



thanks
</code></pre>
