App Designer Line 1 Class Name Error on any App

34 次查看(过去 30 天)
When attempting to run any app using App Designer (even tutorial apps or blank apps), I receive the following error.
Error using app1
Error: File: app1.mlapp Line: 1 Column: 10
Class name and filename must match.
The first line of the app code is autogenerated and not editable:
classdef app1 < matlab.apps.AppBase
As far as I can tell, the class name and filename do match. Filename: app1.mlapp
When selecting the "Pause on Errors" Run option, it pauses on this line in AppManagementService.m:
100 runningApp = evalin('base', sprintf('%s(%s);', command, appArguments));
In base workspace.
I'm brand new to App Designer and might be missing something fundamental here. All the tutorials I can find do not mention this error or define any setup needed to avoid it.

回答(2 个)

Jonathan Buchholz
Jonathan Buchholz 2024-8-16,6:21
I found the issue! Turned out to be the naming of parent folders that confused PathUtil to read a parent folder as a class folder.
My path looked something like this:
'C:\...\@Something\app1.mlapp'
Which led PathUtil.getAppRunCommandFromFileName to return the following line as TRUE:
isFileDirectlyInClassOrPackageFolder = PathUtil.fileDirectlyInClassOrPackageFolder(fullFileName);
Therefore leading to command evaluating to "Something" instead of "app1". When that command was returned to AppManagementService, it attempted to execute "Something", which did not match the filename.
Moving files to a path that did not have an @ character at the start solved the problem. Having no experience with classes, I had no idea the class folder naming convention existed. Here I just wanted certain document folders to always be displayed on top when sorting alphabetically. I guess there must be better ways of doing that...

Siraj
Siraj 2024-7-31,7:28
Hi!
I understand that you are encountering an issue where MATLAB is unable to run any app created with App Designer, even tutorial or blank apps, due to an error indicating that the class name and filename must match. Here’s a potential solution:
  1. Ensure that the filename and class name match exactly, including case sensitivity. For example, if your class name is "app1", the filename should be "app1.mlapp".
  2. Check for hidden characters, sometimes, hidden characters or spaces might cause issues. Make sure there are no trailing spaces or hidden characters in the filename or class name.
  3. Clear your MATLAB workspace and cache to ensure there are no conflicts.
>> restoredefaultpath
>> rehash toolbox
>> rehash toolboxcache
>> clear all;
Ensure that the directory containing your app file is on the MATLAB path. You can add the directory to the path using the "addpath" function.
>> addpath('your_directory_path');
Hope this helps.
  1 个评论
Jonathan Buchholz
Jonathan Buchholz 2024-8-1,5:32
Thanks for the quick reply, Siraj!
I can confirm that the class name and filename do match. Since the classdef line is autogenerated, even changing the filename causes the class name to immediately change to match it the next time the app is opened in App Designer.
I ran the recommended commands and the error still persists.
All apps I have attempted to run have been in my Current Folder, which is in my path.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Class File Organization 的更多信息

产品


版本

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by