Java - Try/catch method issue -


this question has answer here:

i have problem trying use try/catch in code. whenever try , return result; error "cannot resolve symbol 'result'". here code.

public object remove(int index) {     try{         object result = this.get(index);         (int k = index; k < size-1; k++) items[k] = items[k + 1];         items[size] = null;         size--;         return result;      }catch(arrayindexoutofboundsexception e){         system.out.println("exception occurred in 'remove' method.");         return result;     } } 

you have defined result variable within try block. if declare variable within {} braces variable avialble use within braces , wont available outside world.

so resolve issue, like:

object result = null; try {    .... } catch ... { } return result; 

Comments

Popular posts from this blog

angularjs - Showing an empty as first option in select tag -

qt - Change color of QGraphicsView rubber band -

c++ - Visible files in the "Projects" View of the Qt Creator IDE if using the CMake build system -