App Designer Line 1 Class Name Error on any App

조회 수: 27 (최근 30일)
Jonathan Buchholz
Jonathan Buchholz 2024년 7월 31일
답변: Jonathan Buchholz 2024년 8월 16일
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일
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일
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일
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에서 Develop Apps Using App Designer에 대해 자세히 알아보기

제품


릴리스

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by