exception NumberFormatException ListView OnItemClickListener

hey:) I would like to do somethin when I click on my ListView item but I got these Exception

Thread [<1> main] (Suspended (exception NumberFormatException)) 
<VM does not provide monitor information>   
StringToReal.invalidReal(String, boolean) line: 63  
StringToReal.parseDouble(String) line: 248  
Double.parseDouble(String) line: 295    
Double.valueOf(String) line: 332    
MainActivity$5.onItemClick(AdapterView, View, int, long) line: 719  
ListView(AdapterView).performItemClick(View, int, long) line: 299   
ListView(AbsListView).performItemClick(View, int, long) line: 1282  
ListView.performItemClick(View, int, long) line: 4450   
AbsListView$PerformClick.run() line: 3174   
AbsListView$3.run() line: 3925  
Handler.handleCallback(Message) line: 733   
ViewRootImpl$ViewRootHandler(Handler).dispatchMessage(Message) line: 95 
Looper.loop() line: 157 
ActivityThread.main(String[]) line: 5872    
Method.invokeNative(Object, Object[], Class, Class[], Class, int, boolean) line: not available [native method]  
Method.invoke(Object, Object...) line: 515  
ZygoteInit$MethodAndArgsCaller.run() line: 858  
ZygoteInit.main(String[]) line: 674 
NativeStart.main(String[]) line: not available [native method]  

Here is my code which gives the exception:

 void registerListClickCallback() {
    ListView myList = (ListView) findViewById(R.id.listViewFave);
    myList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View viewClicked, 
                int position, long idInDB) {
            Cursor cursor = myDBAF.getRow(idInDB);
            if (cursor.moveToFirst()) {
                long idDB = cursor.getLong(DBAdapter.COL_ROWID);
                int Kalo = cursor.getInt(DBAdapter.COL_KALO);
                int Hydrate = cursor.getInt(DBAdapter.COL_HYDRATE);
                int Fat = cursor.getInt(DBAdapter.COL_FAT);
                int Protein = cursor.getInt(DBAdapter.COL_PROTEIN);
                 //int to double

                KalorienenVerzehrt=KalorienenVerzehrt+(double)Kalo;
                KalorienenUebrig=KalorienenUebrig-(double)Kalo;
                HydrateG=HydrateG+(double)Hydrate;
                FetteG=FetteG+(double)Fat;
                EiweisseG=EiweisseG+(double)Protein;

Thank you for Helping:) And sorry for my bad Englsih;)

Answers


To get rid of crash

Surround your parsing methods in a try-catch, catching NumberFormatException. If the exception occurs, notify the user they entered an invalid value and do not proceed with the calculation

try {
    Float value = Float.valueOf(text);

    if (value == null || value == 0f) {
        answer.setText("Zero");
    }
} catch (NumberFormatException e) {
    answer.setText("Invalid input");
}

Need Your Help

pointer movement what is difference between cs, and *cs++

c arrays pointers

I am trying to understand how the pointers are moving.

boolean function not working

c++ arrays function boolean

I'm wondering if the logic is right for this. The function gets paased an array of lets say 1,2,3,4,5 through compcards[] and also a number a user would input such as 4. however if the user guessed...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.