javaexceptioninvocationtargetexception

How to solve InvocationTargetException in for loop? (seeking entire stack trace)


Currently, I'm having problem with my work.


List<Map<String,String>> tmp = //blahblahblah//(for my privacy)
        int size = tmp.size();
        String[] linearr = new String[size];
        String[] numarr= new String[size];
        String[] namearr= new String[size];
        String[] datearr= new String[size];
        int i = 0;

for (i = 0; i < size; i++) {
    linearr[i] = (String) tmp.get(i).get("line").toString();
    numarr[i] = (String) tmp.get(i).get("number").toString();
    namearr[i] = (String) tmp.get(i).get("name").toString();
    datearr[i] = (String) tmp.get(i).get("date").toString();
            }

I made a List<Map<String,String>> however when i got to for-loop. InvocationTargetException came up. And I could not debug anymore and cannot track it

I tried the code surrounds with try and catch block with throws InvocationTargetException e but Eclipse told me to remove it.

please help

specifically it said that invocationtargetexception.<init>(throwable) line: not available


Solution

  • You may find this link helpful. However, I'd like to suggest that you need to make sure that all keys are available in your map.

    P.S. You don't need to use toString() and (String) cast.