1

My code is

Button.setOnClickListener(new    View.OnClickListener() 
    { 
        @Override
        public void onClick(View v) { 
            int cv; 
            String getmont="",getyear="";
            getmont=year.getText().toString();
            getyear= (String) sid.getSelectedItem(); 
            SQLiteDatabase db;
            db = openOrCreateDatabase("monthapp", MODE_PRIVATE, null); 
            curtop = db.rawQuery("SELECT    SUM(currentpaid)FROM monthvaluesOrgin WHERE curmonth='" + getmont + "' AND curyear='" + getyear + "'", null);
            if (curtop.moveToNext() ) { 
                cv=curtop.getInt(0);      
                Toast.makeText(getApplicationContext(),cv,Toast.LENGTH_SHORT).show(); 
            } 
        }
     });

How to print/ toast the sum value? It always shows error EofException.

My app shows "unfortunately your app has stopped".

Please give me a solution! Thanks in advance!

Laposhasú Acsa
  • 1,550
  • 17
  • 18

1 Answers1

0

You are using the wrong signature for makeText. Because cv is an int the compiler think you are trying to pass a resource id and since your sum is unlikely to be a valid string ID your app crashes because makeText cannot find that that number in the string resources. Try to use valueOf to convert cv to a string like this :

Toast.makeText(getApplicationContext(),String.valueOf(cv),Toast.LENGTH_SHORT).show(); 
litelite
  • 2,857
  • 4
  • 23
  • 33