2016-05-15 217 views
0

在MATLAB中,我创建了一个图像识别应用程序,用于加载图像,然后检测它是什么货币。在MATLAB上,我已经运行该程序数千次,GUI显示以及MATLAB环境中的一切工作正常。MATLAB GUI可执行文件窗口应用程序不会显示

但是当我通过MATLAB将项目转换为可执行文件时,GUI不会显示,但它仍然会在后台运行,所以我必须去任务管理器手动关闭程序。我已经为我的电脑安装了MATLAB Runtime。

我做了一个测试,并创建了一个简单的GUI,只需一个按钮,将其转换为可执行文件,并且可以很好地显示GUI的内容。所以我知道MATLAB没有错,它只是我的代码。

因此,我通过命令窗口运行图像识别可执行文件,并得到这个错误。

java.lang.IllegalStateException: ActionData AbstractNamedUniqueID object with unique ID 'close-genome-desktop' and user-visible name 'Exit NGS Browser'. is already registered. 
    at com.mathworks.mwswing.binding.KeyBindingManager.throwError(KeyBindingManager.java:623) 
    at com.mathworks.mwswing.binding.KeyBindingManager.addAction(KeyBindingManager.java:201) 
    at com.mathworks.mwswing.binding.KeyBindingManager.parseAndRegisterActions(KeyBindingManager.java:71) 
    at com.mathworks.services.binding.MatlabKeyBindings.addActionFile(MatlabKeyBindings.java:666) 
    at com.mathworks.services.binding.MatlabKeyBindings.readActionAndContextFilesFromOSGi(MatlabKeyBindings.java:639) 
    at com.mathworks.services.binding.MatlabKeyBindings.<clinit>(MatlabKeyBindings.java:592) 
    at com.mathworks.widgets.action.BaseAbstractAction.<init>(BaseAbstractAction.java:24) 
    at com.mathworks.widgets.action.AbstractNewAction.<init>(AbstractNewAction.java:24) 
    at com.mathworks.hg.peer.FiguresGroup$NewFigureAction.<init>(FiguresGroup.java:78) 
    at com.mathworks.hg.peer.FiguresGroup.createToolBar(FiguresGroup.java:68) 
    at com.mathworks.hg.peer.FiguresGroup.<init>(FiguresGroup.java:43) 
    at com.mathworks.hg.peer.FiguresGroup.getInstance(FiguresGroup.java:52) 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) 
    at java.lang.reflect.Method.invoke(Unknown Source) 
    at com.mathworks.widgets.desk.DTGroup.createPropertyProvider(DTGroup.java:253) 
    at com.mathworks.widgets.desk.DTGroup.getPropertyProvider(DTGroup.java:190) 
    at com.mathworks.widgets.desk.DTOccupant.getProperty(DTOccupant.java:748) 
    at com.mathworks.widgets.desk.DTOccupant.getToolstripTabs(DTOccupant.java:520) 
    at com.mathworks.widgets.desk.DTGroup.add(DTGroup.java:345) 
    at com.mathworks.widgets.desk.Desktop.addClient(Desktop.java:6569) 
    at com.mathworks.widgets.desk.Desktop.addClient(Desktop.java:6536) 
    at com.mathworks.widgets.desk.Desktop.addSingletons(Desktop.java:5603) 
    at com.mathworks.mde.desk.MLDesktop.<init>(MLDesktop.java:554) 
    at com.mathworks.mde.desk.MLDesktop.getInstance(MLDesktop.java:615) 
    at com.mathworks.mde.desk.MLDesktopRegistrar.getDesktop(MLDesktopRegistrar.java:11) 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) 
    at java.lang.reflect.Method.invoke(Unknown Source) 
    at com.mathworks.mlservices.MLServices.getRegisteredService(MLServices.java:29) 
    at com.mathworks.mlservices.MatlabDesktopServices.<clinit>(MatlabDesktopServices.java:14) 
    at com.mathworks.hg.peer.FigureClientProxy.getMatlabDesktop(FigureClientProxy.java:504) 
    at com.mathworks.hg.peer.FigureClientProxy.<init>(FigureClientProxy.java:92) 
    at com.mathworks.hg.peer.HG2FigureClientProxy.<init>(HG2FigureClientProxy.java:20) 
    at com.mathworks.hg.peer.FigureHG2Mediator.<init>(FigureHG2Mediator.java:43) 
    at com.mathworks.hg.peer.HG2FigurePeer.createFigureClient(HG2FigurePeer.java:74) 
    at com.mathworks.hg.peer.FigurePeer.doInitializePeer(FigurePeer.java:454) 
    at com.mathworks.hg.peer.FigurePeer$2.run(FigurePeer.java:419) 
    at com.mathworks.jmi.AWTUtilities$Invoker$5$1.run(AWTUtilities.java:591) 
    at com.mathworks.mvm.context.ThreadContext$1.call(ThreadContext.java:76) 
    at com.mathworks.mvm.context.ThreadContext.callWithContext(ThreadContext.java:105) 
    at com.mathworks.mvm.context.ThreadContext.runWithContext(ThreadContext.java:73) 
    at com.mathworks.mvm.context.MvmContext.runWithContext(MvmContext.java:107) 
    at com.mathworks.jmi.AWTUtilities$Invoker$5.runWithOutput(AWTUtilities.java:588) 
    at com.mathworks.jmi.AWTUtilities$Invoker$2.watchedRun(AWTUtilities.java:475) 
    at com.mathworks.jmi.AWTUtilities$WatchedRunnable.run(AWTUtilities.java:436) 
    at java.awt.event.InvocationEvent.dispatch(Unknown Source) 
    at java.awt.EventQueue.dispatchEventImpl(Unknown Source) 
    at java.awt.EventQueue.access$200(Unknown Source) 
    at java.awt.EventQueue$3.run(Unknown Source) 
    at java.awt.EventQueue$3.run(Unknown Source) 
    at java.security.AccessController.doPrivileged(Native Method) 
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source) 
    at java.awt.EventQueue.dispatchEvent(Unknown Source) 
    at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source) 
    at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source) 
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source) 
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source) 
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source) 
    at java.awt.EventDispatchThread.run(Unknown Source) 
Warning: Unable to create com.mathworks.hg.peer.FiguresGroup, for details see 
C:\Users\ELECTR~1\AppData\Local\Temp\MATLABDesktopCreateError.log 

这是叫我的所有功能,并具有GUI事件操作我的主要文件 - Image.m

function varargout = Image(varargin) 
% IMAGE MATLAB code for Image.fig 
%  IMAGE, by itself, creates a new IMAGE or raises the existing 
%  singleton*. 
% 
%  H = IMAGE returns the handle to a new IMAGE or the handle to 
%  the existing singleton*. 
% 
%  IMAGE('CALLBACK',hObject,eventData,handles,...) calls the local 
%  function named CALLBACK in IMAGE.M with the given input arguments. 
% 
%  IMAGE('Property','Value',...) creates a new IMAGE or raises the 
%  existing singleton*. Starting from the left, property value pairs are 
%  applied to the GUI before Image_OpeningFcn gets called. An 
%  unrecognized property name or invalid value makes property application 
%  stop. All inputs are passed to Image_OpeningFcn via varargin. 
% 
%  *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one 
%  instance to run (singleton)". 
% 
% See also: GUIDE, GUIDATA, GUIHANDLES 

% Edit the above text to modify the response to help Image 

% Last Modified by GUIDE v2.5 14-May-2016 19:14:58 

% Begin initialization code - DO NOT EDIT 
gui_Singleton = 1; 
gui_State = struct('gui_Name',  mfilename, ... 
        'gui_Singleton', gui_Singleton, ... 
        'gui_OpeningFcn', @Image_OpeningFcn, ... 
        'gui_OutputFcn', @Image_OutputFcn, ... 
        'gui_LayoutFcn', [] , ... 
        'gui_Callback', []); 
if nargin && ischar(varargin{1}) 
    gui_State.gui_Callback = str2func(varargin{1}); 
end 

if nargout 
    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:}); 
else 
    gui_mainfcn(gui_State, varargin{:}); 
end 
% End initialization code - DO NOT EDIT 


% --- Executes just before Image is made visible. 
function Image_OpeningFcn(hObject, eventdata, handles, varargin) 
% This function has no output args, see OutputFcn. 
% hObject handle to figure 
% eventdata reserved - to be defined in a future version of MATLAB 
% handles structure with handles and user data (see GUIDATA) 
% varargin command line arguments to Image (see VARARGIN) 

% Choose default command line output for Image 
handles.output = hObject; 

% Update handles structure 
guidata(hObject, handles); 

% UIWAIT makes Image wait for user response (see UIRESUME) 
% uiwait(handles.figure1); 


% --- Outputs from this function are returned to the command line. 
function varargout = Image_OutputFcn(hObject, eventdata, handles) 
% varargout cell array for returning output args (see VARARGOUT); 
% hObject handle to figure 
% eventdata reserved - to be defined in a future version of MATLAB 
% handles structure with handles and user data (see GUIDATA) 

% Get default command line output from handles structure 
varargout{1} = handles.output; 


% --- Executes on button press in pushbutton1. 
function pushbutton1_Callback(hObject, eventdata, handles) 
% hObject handle to pushbutton1 (see GCBO) 
% eventdata reserved - to be defined in a future version of MATLAB 
% handles structure with handles and user data (see GUIDATA) 
global im im2 
[path,user_cance]=imgetfile(); 
if user_cance 
    msgbox(sprintf('Error'),'Error','Error'); 
    return 
end 
im=imread(path); 
im=im2double(im); %converts to double 
im2=im; %for backup process :) 
axes(handles.axes1); 
imshow(im); 
currency = ClassImages(path) 
set(handles.edit1,'String',currency) 

% --- Executes on button press in pushbutton2. 
function pushbutton2_Callback(hObject, eventdata, handles) 
% hObject handle to pushbutton2 (see GCBO) 
% eventdata reserved - to be defined in a future version of MATLAB 
% handles structure with handles and user data (see GUIDATA) 


% --- Executes on button press in pushbutton3. 
function pushbutton3_Callback(hObject, eventdata, handles) 
% hObject handle to pushbutton3 (see GCBO) 
% eventdata reserved - to be defined in a future version of MATLAB 
% handles structure with handles and user data (see GUIDATA) 


% --- Executes on button press in pushbutton4. 
function pushbutton4_Callback(hObject, eventdata, handles) 
% hObject handle to pushbutton4 (see GCBO) 
% eventdata reserved - to be defined in a future version of MATLAB 
% handles structure with handles and user data (see GUIDATA) 


% --- Executes on slider movement. 
function slider1_Callback(hObject, eventdata, handles) 
% hObject handle to slider1 (see GCBO) 
% eventdata reserved - to be defined in a future version of MATLAB 
% handles structure with handles and user data (see GUIDATA) 

% Hints: get(hObject,'Value') returns position of slider 
%  get(hObject,'Min') and get(hObject,'Max') to determine range of slider 


% --- Executes during object creation, after setting all properties. 
function slider1_CreateFcn(hObject, eventdata, handles) 
% hObject handle to slider1 (see GCBO) 
% eventdata reserved - to be defined in a future version of MATLAB 
% handles empty - handles not created until after all CreateFcns called 

% Hint: slider controls usually have a light gray background. 
if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) 
    set(hObject,'BackgroundColor',[.9 .9 .9]); 
end 



function edit1_Callback(hObject, eventdata, handles) 
% hObject handle to edit1 (see GCBO) 
% eventdata reserved - to be defined in a future version of MATLAB 
% handles structure with handles and user data (see GUIDATA) 

% Hints: get(hObject,'String') returns contents of edit1 as text 
%  str2double(get(hObject,'String')) returns contents of edit1 as a double 


% --- Executes during object creation, after setting all properties. 
function edit1_CreateFcn(hObject, eventdata, handles) 
% hObject handle to edit1 (see GCBO) 
% eventdata reserved - to be defined in a future version of MATLAB 
% handles empty - handles not created until after all CreateFcns called 

% Hint: edit controls usually have a white background on Windows. 
%  See ISPC and COMPUTER. 
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) 
    set(hObject,'BackgroundColor','white'); 
end 

代码的唯一的一块,我加入到这是(我评论它额外的清晰度)

% --- Executes on button press in pushbutton1. 
function pushbutton1_Callback(hObject, eventdata, handles) 
% hObject handle to pushbutton1 (see GCBO) 
% eventdata reserved - to be defined in a future version of MATLAB 
% handles structure with handles and user data (see GUIDATA) 
global im im2 %Hold two images im-Main-Image im2-Second-Image 
[path,user_cance]=imgetfile(); % Push button and store the path of the image in path 
if user_cance 
    msgbox(sprintf('Error'),'Error','Error'); % If Image is not found display error 
    return 
end 
im=imread(path); %Read image and store in im 
im=im2double(im); %converts to double 
im2=im; %for backup process :) 
axes(handles.axes1); % Display the image on the axes 
imshow(im); %Show Image 
currency = ClassImages(path) % Stores the currency of the image in currency 
set(handles.edit1,'String',currency) %Sets edit box in the GUI to the value of the currency 

我不知道什么是错,它在MATLAB运行时,它工作正常,但崩溃时它成为一个可执行的应用程序。

回答

0

是的,我能解决它。最初我使用MATLAB R2016a。而且我正在使用MATLAB警告的旧功能将在下一组MATLAB应用程序中逐步淘汰。当我删除旧的函数,并重新编译为一个可执行文件它工作。所以最初,R2016a的MATLAB Runtime在其库中没有该功能。但是为了让我的应用程序正常工作,我需要这个功能。所以我降级到MATLAB R2015a和我的可执行文件与旧功能一起工作。

相关问题