MATLAB: Error using list box, please help!!!

edittexterror using setlistbox

my gui has a listbox1.
the list box has 2 (values).
for each values i have two different numbers, and i want to change the string and the handle of a edit text (edit1).
when i run the gui and click for the first time on the listbox every thing is OK…..but when i click for the second time appears the following error :
??? Error using ==> set
Invalid handle object.
Error in ==> GUI>listbox1_Callback at 110
set(handles.edit1,'String',X)
Error in ==> gui_mainfcn at 96
feval(varargin{:});
Error in ==> GUI at 42
gui_mainfcn(gui_State, varargin{:});
Error in ==>
@(hObject,eventdata)GUI('listbox1_Callback',hObject,eventdata,guidata(hObject))
??? Error while evaluating uicontrol Callback
________________________
here is my code:::
function listbox1_Callback(hObject, eventdata, handles)
Z=get(hObject,'value')
if Z==1
X=120;
elseif Z==2
X=240;
end
set(handles.edit1,'String',X)
handles.edit1=X
guidata(hObject,handles)
___________
thank for helping my solving this issue.

Best Answer

you are overwriting handles.edit1, see:
handles.edit1 = X
handle with the number X. Remove this and it should be ok.