This is one of the functions in my ExpendableListAdapter for the listview for the child of a particular list group. groupPosition == 2 means when user expand the third list group, I want to show a different view from the first and second list group which only contain a textview.
public View getChildView(int groupPosition, final int childPosition,
                         boolean isLastChild, View convertView, ViewGroup parent) {
    if (groupPosition == 2)
    {
        JSONObject jsonObject = (JSONObject) getItem(childPosition);
        Log.d("TestJson rating2", jsonObject.toString()); //line 62 <<<<<<
        if (convertView == null) {
            LayoutInflater infalInflater = (LayoutInflater) this._context
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            convertView = infalInflater.inflate(R.layout.row_detail_review, null);
        }
        TextView username = (TextView) convertView.findViewById(R.id.username);
        RatingBar ratingBar = (RatingBar) convertView.findViewById(R.id.userRating);
        TextView review = (TextView) convertView.findViewById(R.id.review);
        String username2 = "";
        String ratingBar2 = "0";
        String review2 = "";
        if (jsonObject.has("username"))
            username2 = (jsonObject.optString("username"));
        if (jsonObject.has("rate"))
            ratingBar2 = (jsonObject.optString("rate"));
        if (jsonObject.has("comment"))
            review2 = (jsonObject.optString("comment"));
        username.setText(username2);
        ratingBar.setRating(Float.parseFloat(ratingBar2));
        review.setText(review2);
        return convertView;
    }
    else
    {
        final String childText = (String) getChild(groupPosition, childPosition);
        if (convertView == null) {
            LayoutInflater infalInflater = (LayoutInflater) this._context
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            convertView = infalInflater.inflate(R.layout.row_detail_item, null);
        }
        TextView txtListChild = (TextView) convertView.findViewById(R.id.lblListItem);
        txtListChild.setText(childText);
        return convertView;
    }
}
I check the log which shows that there are values in the jsonObject but after that it shows the following NullPointerException error.
04-20 11:14:19.790 1759-1759/com.domain.appname D/TestJson rating2: {"username":"luqman","rate":"5","ratingId":"1","comment":"best","userId":"15"}
04-20 11:14:19.794 1759-1759/com.domain.appname D/TestJson rating2: {"username":"sumak","rate":"4","ratingId":"2","comment":"sedap","userId":"14"}
04-20 11:14:19.798 1759-1759/com.domain.appname D/AndroidRuntime: Shutting down VM
04-20 11:14:19.798 1759-1759/com.domain.appname W/dalvikvm: threadid=1: thread exiting with uncaught exception (group=0xa4cfbb20)
04-20 11:14:19.798 1759-1759/com.domain.appname E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.domain.appname, PID: 1759
java.lang.NullPointerException
at com.mycompany.loginregister.ExpandableListAdapter.getChildView(ExpandableListAdapter.java:62)
What cause the error?
 
    