No public field [variable] exists for class matlab.ui.​container.​toolbar.Pu​shTool. ERROR

5 views (last 30 days)
Dear all,
We changed to Windows 10 and R2015a (was windows 7 with R2014a) and since then my program does not work anymore properly.
I have a gui which opens a function. This function creates a figure and the figure contains an pushtool in the toolbar because of the following code:
hGinput = uipushtool('cdata',cdata_gin, 'tooltip','Select startingpoint exercise','ClickedCallback',{@NIRS_OFFSET_FUNC,handles},'Separator','on');
The subsequent called function is as follows:
function NIRS_OFFSET_FUNC(handles,~,~)
hMainGui=getappdata(0,'hMainGui');
handles.t = getappdata(hMainGui,'t');
However, when I run my program it keeps getting the failure:
No public field t exists for class matlab.ui.container.toolbar.PushTool.
Error in NIRS_OFFSET_NIRS_OFFSET_FUNC (line 205)
handles.t = getappdata(hMainGui,'t');
I never had such failure and I can't find a proper solution on the internet.
Does it have to do with the uipushtool or with gathering the appdata??
Can somebody help me :)?

Answers (1)

Steven Lord
Steven Lord on 24 Aug 2015
What do you expect hMainGui to be? I suspect from the name that you expect it to be the handle to the GUI figure, but it's the handle of the uipushtool. You didn't show the code that set the application data of the root object (by the way, that's a bad idea IMO; you're giving anyone with access to the root object [i.e. everyone] the ability to break and/or hijack your GUI.)
If you want to obtain the handles to your main GUI and to your uipushtool, they're probably stored in the handles structure that was passed into NIRS_OFFSET_FUNC as the first input argument (if you wrote this GUI using Guide or used GUIHANDLES and GUIDATA in your programmatic GUI.)
  2 Comments
KFrenkie
KFrenkie on 24 Aug 2015
In mainGUI I gather some data (i.e. xlsread) which I store in hMainGui. I have a pushbutton opening a functions which contains a figure, in this figure I have the uipushtool defined. In R2014a, I pushed the button which calls NIRS_OFFSET_FUNC for the offset purpose... It used to gather all the data from the hMainGui
But for some reason this does not work while its complains about public fieds!
I don't mind the "risks" while it is for own use (research purposes)
KFrenkie
KFrenkie on 24 Aug 2015
Hi,
For SOME reason I managed to fix the problem.
The only thing I changed was the following:
hGinput = uipushtool('cdata',cdata_gin, 'tooltip','Select startingpoint exercise','ClickedCallback',@NIRS_OFFSET_FUNC,'Separator','on');
and
function NIRS_OFFSET_FUNC(hObject,eventdata)
I changed the clickedcallback where I deleted the handles part and changed the NIRS_OFFSET_FUNC() from handles to hObject and eventdata..
I have NO idea why this worked... But it worked.. Weird that it worked in R2014a and not in R2015a

Sign in to comment.

Categories

Find more on Language Fundamentals in Help Center and File Exchange

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!