-3
    //global 

    getDatabaseChart();
    addData();


public void addData() {
    int a;
    a = profile.getTotalBelum();
    Log.d("AA",""+a);
    final float[] yData = {a};
    ......
 }

    public void getDatabaseChart(){
    //Creating a string request
    Log.d("MasukTak","MasukTak");
    StringRequest stringRequest = new StringRequest(Request.Method.POST, Config.URL_WEB + "a.php",
            new Response.Listener<String>() {
                @Override
                public void onResponse(String response) {
                    //   hidePDialog();
                    try {

                        Log.d("TgkSini", response);
                        JSONObject json = new JSONObject(response);
                        int success = json.getInt("success");

                        if (success == 1) {
                            user = json.getJSONArray("user");

                            for (int i = 0; i < user.length(); i++) {
                                JSONObject obj = user.getJSONObject(i);

                                profile = new ProfileUser();
                                profile.setTotalBelum(obj.getInt("belum"));


                             Log.d("BelumB",String.valueOf(profile.getTotalBelum()));

                            }
                            abc = profile.getTotalBelum();
                            Log.d("abccc", String.valueOf(abc));


                        } else {
                            Log.d("data2 ", "no user");
                        } ...............

This my code .. Now i change code .. I just direct integer value .. when i see logcat .. check log.d abccc .. value for abc = 2 ... then i check log.d AA value for a = 0 ...

How to solve it ? Please help me.

3
  • I just compiled your code, it is working fine. Can you check which line the error is occurring? Commented May 25, 2016 at 3:46
  • Don't just log only a, Log all and post the full stracktrace ! Commented May 25, 2016 at 3:54
  • @NecipAllef ... yes it working fine but the value that i get not same .. huhu Commented May 28, 2016 at 4:02

3 Answers 3

1

if you try to parse it to integer.

Check before parsing. or handle Exception properly. for example:

try{
   int a = Integer.parseInt(profile.getTotalBelum());
}catch(NumberFormatException ex){ // handle your exception

... }

Sign up to request clarification or add additional context in comments.

1 Comment

Sir @damini mehra .. i updated my question .. actually , i still got not same value .. so i directly call integer .. but still not get same value .. Can you see my updated question..
0

Use this method to handle the exception:

public static int parseInt(String number, int defaultValue){
    try{
       return Integer.parseInt(number);
    }catch(NumberFormatException e){
       return defaultValue;
    }
}

This is how to use that method:

a = parseInt(profile.getTotalBelum(), 3);
// if the string cannot be converted to integer,
// the value will be returned to 3 (i.e. the defaultValue)

1 Comment

Sir @Anggrayudi H.. i updated my question .. actually , i still got not same value .. so i directly call integer .. but still not get same value .. Can you see my updated question..
0

Check below updated method,

 public void addData() 
 {

    a = convertData(profile.getTotalBelum().toString());
    Log.d("AAAA",""+a);
    aa = convertData(profile.getTotalSedang().toString());
    aaa = convertData(profile.getTotalLulus().toString());

    float[] yData = { a, aa, aaa};
 }

 public int convertData(String strTemp)
 {
    int i = 0;
    try
    {
        i = Integer.parseInt(strTemp);            
    }
    catch(Exception e)
    {
         i = 0;
    }

    return i;
 }

1 Comment

Sir @Vickyexpert.. i updated my question .. actually , i still got not same value .. so i directly call integer .. but still not get same value .. Can you see my updated question..

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.