Category Archives: Error

[Solved] logback log format adjustment error: Failed to create converter for [%M] keyword

Adjust the log format of logback, and the program starts to report an error.

before fixing:

    <property name=”logLayout” value=”%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{10} :%-3L – %msg %X{span} %n”/>

adjusted:

   <property name=”logLayout” value=”%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger.%M\(%L\) – %msg %n” />

Error after adjustment:

Failed to create converter for [%M] keyword

 

The content of the logback-spring.xml file after format adjustment, before the format adjustment, the program is normal, and an error is reported after the adjustment.

<?xml version="1.0" encoding="UTF-8"? >
<configuration
 
    <contextName>emc-service</contextName>
 
    <springProperty scope="context" name="logging.path" source="logging.path"
                    defaultValue="/data/logs/emc-service"/>
    <springProperty scope="context" name="logging.level.root" source="logging.level.root"
                    defaultValue="info"/>
 
    <property name="logLayout" value="%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %-logger.%M\(%L\) - %msg %n"/>
    <! --%d date | %color() text color | -5level log level | %logger{10} is the class path | %-3L lines | %msg log content | %ex is the exception in log.error(xx,exption) | -->
    <! --><property name="logLayout" value="%blue(%-4relative) %d{yyyy-MM-dd HH:mm:ss.SSS} | [%thread] | %highlight(%-5level) | %logger{10} :%-3L - % yellow(%msg) %X{span}%n"/> -->
 
    <! -- Logger, date scrolling logging -->
    <appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <! -- Path and filename of the log file being logged -->
        <file>${logging.path}/emc-service.log</file
        <! -- Rolling policy for logger, by date, by size -->
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <! -- The path to the archived log file, e.g. today is the 2013-12-21 log, the path to the currently written log file is specified by the file node, you can set this file to a different path than the file specified by file, thus placing the current log file or the archived log file in a different directory.
            And the log file of 2013-12-21 in specified by fileNamePattern. %d{yyyy-MM-dd} specifies the date format and %i specifies the index -->
            <fileNamePattern>${logging.path}/%d{yyyy-MM,aux}/emc-service.%d.%i.gz</fileNamePattern>
            <! -- In addition to logging by log, it is also configured that the log file cannot exceed 2M, and if it exceeds 2M, the log file will start with index 0.
            Name the log file, e.g. log-error-2013-12-21.0.log -->
            <timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
                <maxFileSize>300MB</maxFileSize
            </timeBasedFileNamingAndTriggeringPolicy>
            <maxHistory>30</maxHistory
        </rollingPolicy>
        <! -- Append method of logging -->
        <append>true</append>
        <! -- Format of log file -->
        <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
            <pattern>${logLayout}</pattern>
            <charset>utf-8</charset>
        </encoder>
    </appender>
 
    <! -- Logger, date scrolling logging -->
    <appender name="ERROR" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <! -- Path and filename of the log file being logged -->
        <file>${logging.path}/emc-service-error.log</file
 
        <filter class="ch.qos.logback.classic.filter.LevelFilter">
            <level>ERROR</level>
            <onMatch>ACCEPT</onMatch
            <onMismatch>DENY</onMismatch>
        </filter>
 
        <! -- Logger's rolling policy, by date, by size -->
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <! -- The path to the archived log file, e.g. today is the 2013-12-21 log, the path to the currently written log file is specified by the file node, you can set this file to a different path than the file specified by file, thus placing the current log file or the archived log file in a different directory.
            And the log file of 2013-12-21 in specified by fileNamePattern. %d{yyyy-MM-dd} specifies the date format and %i specifies the index -->
            <fileNamePattern>${logging.path} /%d{yyyy-MM,aux}/emc-service-error.%d.%i.gz
            </fileNamePattern>
            <! -- In addition to logging by log, it is also configured that the log file cannot exceed 2M, and if it exceeds 2M, the log file will start with index 0.
            Name the log file, e.g. log-error-2013-12-21.0.log -->
            <timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
                <maxFileSize>100MB</maxFileSize
            </timeBasedFileNamingAndTriggeringPolicy>
            <maxHistory>30</maxHistory
        </rollingPolicy>
        <! -- Append method of logging -->
        <append>true</append>
        <! -- Format of log file -->
        <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
            <pattern>${logLayout}</pattern>
            <charset>utf-8</charset>
        </encoder>
    </appender
 
    <appender name="STDOUT" class="ch.qos.logback.core.
        <! --encoder is configured as PatternLayoutEncoder by default -->
        <encoder
            <pattern>${logLayout}</pattern>
            <charset>utf-8</charset>
        </encoder>
    </appender>
 
    <root level="${logging.level.root}">
        <! -- weighted logging -->
        <appender-ref ref="FILE"/>
        <! -- Error log -->
        <appender-ref ref="ERROR"/>
    </root
 
    <springProfile name="dev">
        <root level="${logging.level.root}">
            <appender-ref ref="STDOUT"/>
        </root
    </springProfile>
</configuration>

 

Solution:

Replace all placeholders ${logLayout} with log format content without placeholders

${logLayout} is replaced by %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger.%M\(%L\) – %msg %n

 

Error Messages:

2022-06-07 10:34:17.943 [main] ERROR org.springframework.boot.SpringApplication.%PARSER_ERROR[M] - Application startup failed 
java.lang.IllegalStateException: Logback configuration error detected: 
ERROR in ch.qos.logback.core.pattern.parser.Compiler@66048ac4 - Failed to instantiate converter class [ch.qos.logback.classic.pattern.MethodOfCallerConverter] as a composite converter for keyword [M] ch.qos.logback.core.util.IncompatibleClassException
ERROR in ch.qos.logback.core.pattern.parser.Compiler@66048ac4 - Failed to create converter for [%M] keyword
ERROR in ch.qos.logback.core.pattern.parser.Compiler@4f525e13 - Failed to instantiate converter class [ch.qos.logback.classic.pattern.MethodOfCallerConverter] as a composite converter for keyword [M] ch.qos.logback.core.util.IncompatibleClassException
ERROR in ch.qos.logback.core.pattern.parser.Compiler@4f525e13 - Failed to create converter for [%M] keyword
ERROR in ch.qos.logback.core.pattern.parser.Compiler@5d404a3c - Failed to instantiate converter class [ch.qos.logback.classic.pattern.MethodOfCallerConverter] as a composite converter for keyword [M] ch.qos.logback.core.util.IncompatibleClassException
ERROR in ch.qos.logback.core.pattern.parser.Compiler@5d404a3c - Failed to create converter for [%M] keyword
        at org.springframework.boot.logging.logback.LogbackLoggingSystem.loadConfiguration(LogbackLoggingSystem.java:162)
        at org.springframework.boot.logging.AbstractLoggingSystem.initializeWithConventions(AbstractLoggingSystem.java:81)
        at org.springframework.boot.logging.AbstractLoggingSystem.initialize(AbstractLoggingSystem.java:59)
        at org.springframework.boot.logging.logback.LogbackLoggingSystem.initialize(LogbackLoggingSystem.java:114)
        at org.springframework.boot.logging.LoggingApplicationListener.initializeSystem(LoggingApplicationListener.java:304)
        at org.springframework.boot.logging.LoggingApplicationListener.initialize(LoggingApplicationListener.java:277)
        at org.springframework.boot.logging.LoggingApplicationListener.onApplicationEnvironmentPreparedEvent(LoggingApplicationListener.java:240)
        at org.springframework.boot.logging.LoggingApplicationListener.onApplicationEvent(LoggingApplicationListener.java:213)
        at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:172)
        at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:165)
        at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139)
        at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:122)
        at org.springframework.boot.context.event.EventPublishingRunListener.environmentPrepared(EventPublishingRunListener.java:74)
        at org.springframework.boot.SpringApplicationRunListeners.environmentPrepared(SpringApplicationRunListeners.java:54)
        at org.springframework.boot.SpringApplication.prepareEnvironment(SpringApplication.java:325)
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:296)
        at org.springframework.boot.web.support.SpringBootServletInitializer.run(SpringBootServletInitializer.java:154)
        at org.springframework.boot.web.support.SpringBootServletInitializer.createRootApplicationContext(SpringBootServletInitializer.java:134)
        at org.springframework.boot.web.support.SpringBootServletInitializer.onStartup(SpringBootServletInitializer.java:87)
        at org.springframework.web.SpringServletContainerInitializer.onStartup(SpringServletContainerInitializer.java:169)
        at org.eclipse.jetty.plus.annotation.ContainerInitializer.callStartup(ContainerInitializer.java:145)
        at org.eclipse.jetty.annotations.ServletContainerInitializersStarter.doStart(ServletContainerInitializersStarter.java:64)
        at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:72)
        at org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContextHandler.java:341)
        at org.eclipse.jetty.webapp.WebAppContext.startWebapp(WebAppContext.java:1445)
        at org.eclipse.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1409)
        at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:822)
        at org.eclipse.jetty.servlet.ServletContextHandler.doStart(ServletContextHandler.java:275)
        at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:524)
        at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:72)
        at org.eclipse.jetty.deploy.bindings.StandardStarter.processBinding(StandardStarter.java:46)
        at org.eclipse.jetty.deploy.AppLifeCycle.runBindings(AppLifeCycle.java:188)
        at org.eclipse.jetty.deploy.DeploymentManager.requestAppGoal(DeploymentManager.java:513)
        at org.eclipse.jetty.deploy.DeploymentManager.addApp(DeploymentManager.java:154)
        at org.eclipse.jetty.deploy.providers.ScanningAppProvider.fileAdded(ScanningAppProvider.java:173)
        at org.eclipse.jetty.deploy.providers.WebAppProvider.fileAdded(WebAppProvider.java:447)
        at org.eclipse.jetty.deploy.providers.ScanningAppProvider$1.fileAdded(ScanningAppProvider.java:66)
        at org.eclipse.jetty.util.Scanner.reportAddition(Scanner.java:784)
        at org.eclipse.jetty.util.Scanner.reportDifferences(Scanner.java:753)
        at org.eclipse.jetty.util.Scanner.scan(Scanner.java:641)
        at org.eclipse.jetty.util.Scanner.doStart(Scanner.java:540)
        at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:72)
        at org.eclipse.jetty.deploy.providers.ScanningAppProvider.doStart(ScanningAppProvider.java:146)
        at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:72)
        at org.eclipse.jetty.deploy.DeploymentManager.startAppProvider(DeploymentManager.java:599)
        at org.eclipse.jetty.deploy.DeploymentManager.doStart(DeploymentManager.java:249)
        at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:72)
        at org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:169)
        at org.eclipse.jetty.server.Server.start(Server.java:407)
        at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:117)
        at org.eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.java:100)
        at org.eclipse.jetty.server.Server.doStart(Server.java:371)
        at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:72)
        at org.eclipse.jetty.xml.XmlConfiguration.lambda$main$0(XmlConfiguration.java:1888)
        at java.security.AccessController.doPrivileged(Native Method)
        at org.eclipse.jetty.xml.XmlConfiguration.main(XmlConfiguration.java:1837)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.eclipse.jetty.start.Main.invokeMain(Main.java:218)
        at org.eclipse.jetty.start.Main.start(Main.java:491)
        at org.eclipse.jetty.start.Main.main(Main.java:77)

 

[Solved] ENSP Failed to Start AR Device error code: 40

Errors are reported as follows:

My configuration is as follows:

ENSP-1.3

Virtualbox-5.2.32 (only version 5.0-5.2 can be used)

Wireshark-win64-3.0.3

My problem is solved as follows:

First, make sure that the installation paths of the reference tools are on Disk C

Those not in the C disk are reinstalled to the C disk, otherwise there is a high probability of error.

Then import the device package

When you drag it out and start it, you can add a device package. At this time, you can add a device package with the suffix img.

Registering an AR device

Follow the prompts on the help document to register the device.

Select all AR devices and register them.

After registration, exit and restart ENSP.

Inspection

Start successful.

Database App.config configurate file Error & Solution

Error message 1

Object reference is not set to an instance of the object.

Error Message:

[Problem Analysis]: Open the App.config file, check the string in the name node and the current brackets is the same, the comparison found, not the same, more than one S. Remember, C# reads the name in brackets used in the node, and the configuration file node configuration name must be consistent!

Solution

[problem-solving] remove “s” and run it.

[other Error] 1: some friends don’t pay attention to this situation that you add spaces in the string will also lead to this problem, such as the following:

Spaces must be removed. You cannot add any spaces in the configuration file.

[other Error] 2: if the node position is written incorrectly, the above error will also occur. For example, in the screenshot below, the node should be written to the arrow position.

[other Error] 3: If the App.config configuration file is not added, or the App.config file is not placed in the project launchable project directory, the above error will also occur. For example, the following is wrong:

The following green part is the project’s startable items, App.config file must be put here to work.

[Other Error] 4: modified the name of the configuration file, the configuration file requirements must be the default App.config to work, if you modify the file name, there will also be errors, such as the following is not allowed: the case of.

 

Error message 2

The type initial value setting item of “ThreeLayer.DAL.SQLHelper” raises an exception.

Error Message:

The problem is that as long as the prompt “SQLHelper’s type initial setting item raises an exception”. Generally, it is a configuration file problem, because we use App.config configuration file to save the data connection string. For beginners, because they can’t understand this error, so they don’t know where to start, here please remember the following troubleshooting methods.

Solution
[Solution 1] The configuration file node is written wrong

Originally this place node name is also the above is less than an s, change to the following can be: [Solution 2] configuration file App.config file if you change the name, not placed in the “startable project” root directory.

[Solution 2] configuration file App.config file if the name is modified, not put into the “startable project” root directory, some VS versions will also appear the above error. (This is the same as the solution to error 1)

Summary
According to the above method, you can perfectly solve the common problem of getting the connection string through App.config. I hope today’s content can help you.

[Solved] MSYS2+ fatal error: zlib.h: There is no such file or directory

Operating environment: windows+msys2+vscode

A brief introduction to msys2

MSYS2 (Minimal SYStem 2) is a standalone rewrite of MSYS, mainly for shell command line development environments. It is also a Windows software that builds on Cygwin (POSIX compatibility layer) and MinGW-w64 (from “MinGW-generation”) for better interoperability.

Problem Description: fatal error: zlib.h: There is no such file or directory

There is an error message when executing the makefile file.

Fatal error: zlib.h: There is no such file or directory

After carefully checking the header file library, it is clear that this header file exists. And I ruled out the possibility of incorrect environment configuration.

Therefore, I open the GUI of msys2. Try other possible solutions.

Enter at the command line

pacman -Ss zlib

The explanation of this command is to find related resources with the keyword “zlib”.

The search result is

At first, the only modules that showed up as installed were msys/zlib 1.2.12-2 (libraries) and msys/perl 5.32.1-2 (base-devel).

I found that the last one felt quite like what I needed, after all, it was installed and not used at best, so I gave it a try, just in case it worked. So I’m going to install msys/zlib-devel 1.2.12-2 (development) as well!

Solution

The command to install msys/zlib-devel 1.2.12-2 (development) is:

pacman -S zlib-devel

Successfully solved the problem!

Wechat Applet error: [app.json file content error] app json: [“usingComponents“][“van-button“]: “@vant/weapp/lib/button/index

微信小程序报错[ app.json 文件内容错误] app.json: [“usingComponents“][“van-button“]: “@vant/weapp/lib/button/index

After pulling items from git to build NPM, the following error is reported:

Point out that the file cannot be found and the button component cannot be used. The file path is wrong. First, find the button file in the project,

After copying the path, change the van-button path of usingComponents in app.json

Problem-solving.

Summary: error in file path. Find the file and update the path.

 

[Solved] grafana Startup Error: failed to parse “/etc/grafana/grafana.ini“: open /etc/grafana/grafana.ini: no such file or directory

Grafana failed to start, and the configuration file parsing reported an error:

lvl=crit msg="failed to parse \"/etc/grafana/grafana.ini\": 
open /etc/grafana/grafana.ini: no such file or directory"

The grafana.ini file is not loading properly for the following two reasons.
1, there is no grafana.ini on the host itself.

If at this point it is docker-based boot and -v goes to mount it, the result is definitely still not there.

2, -v is not used correctly, there is grafana.ini on the host, but the file is not mapped into the container

Failure [INSTALL_FAILED_TEST_ONLY: installPackageLI]

Failure [INSTALL_FAILED_TEST_ONLY: installPackageLI]

Today adb command to install apk,prompted the following error:.
Failure [INSTALL_FAILED_TEST_ONLY: installPackageLI]

Solution:
Method 1:
Change android:testOnly=”true” to android:testOnly=”false” in AndroidManifest.xml, or just remove it.
Method 2:
adb push .apk /tmp
adb shell pm install -t /tmp/.apk
Method 3:
adb install -t *.apk

[Solved] torchvision.models.resnet18() Error: PytorchStreamReader failed reading zip archive: failed finding…

When I was downloading the resnet18 network using torchvision.models.resnet18(), I manually terminated it once and when I ran it again, I got the error PytorchStreamReader failed reading zip archive: failed finding central directory

This is because after manually terminating the program, the file was halfway down, but when I rerun it, the program thought it was done and started unpacking, which resulted in an error. Here is the file I downloaded halfway:

The procedure to detect if the file already exists is in the torch.hub file at line 585, follow the error message to find the torch.hub file

Type a breakpoint here, debug it, then see what the value of cached_file is here, follow the path of cached_file to find the file that is halfway down, delete it and you’re done.

When I run it, the path of this file looks like this

[Solved] ssh secure shell: server responded algorithm negotiation failed

ssh secure shell:server responded algorithm negotiation failed

This problem is usually solved as follows:
enter
1. cd /etc/ssh
2.vim /etc/ssh/sshd_config

# Add the following to the configuration file (except the last one of the third is gray plus purple, the others are blue, if it is gray means it is not right!)
Ciphers aes128-cbc,aes192-cbc,aes256-cbc,aes128-ctr,aes192-ctr,aes256-ctr,3des-cbc,arcfour128,arcfour256,arcfour,blowfish-cbc,cast128-cbc
 
MACs hmac-md5,hmac-sha1,[email protected],hmac-ripemd160,hmac-sha1-96,hmac-md5-96
 
KexAlgorithms diffie-hellman-group1-sha1,diffie-hellman-group14-sha1,diffie-hellman-group-exchange-sha1,diffie-hellman-group-exchange-sha256,ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group1-sha1,[email protected]

Then restart sshd with this statement and you’re done
systemctl restart sshd

Because the error page can not be selected, so I did not directly check the error, but with their own understanding of the error to check, but wasted a lot of time, so if such an error, or hand typing in the future, it is very fast.

[Solved] VScode Error: find_package(catkin) failed

Question:

In vscode, when using cmake for configure, I found that the CMakeLists.txt generated by catkin_init_workspace reported an error:
find_package(catkin) failed. catkin was neither found in the workspace···

analysis:

After investigation and analysis, it is found that there is a problem with the following code in CMakeLists.txt:

# use command ‘catkin_init_workspace’  to generate ‘CMakeLists.txt’
set(catkin_search_path "")
  foreach(path ${CMAKE_PREFIX_PATH})
    if(EXISTS "${path}/.catkin")
      list(FIND catkin_search_path ${path} _index)
      if(_index EQUAL -1)
        list(APPEND catkin_search_path ${path})
      endif()
    endif()
  endforeach()

Specifically, the path from the variable ${CMAKE_PREFIX_PATH} is not searched for .catkin.
By directly modifying the /opt/ros/melodic/share/catkin/cmake/toplevel.cmake print variable ${CMAKE_PREFIX_PATH} pointed to by CMakeLists.txt, the output was found to be empty.
However, the configure in the system terminal works, and the command executed is the same as the configure in vscde, as follows

# The actual command executed when configure with cmake-tool in vscode
/usr/bin/cmake \
--no-warn-unused-cli \
-DCMAKE_PREFIX_PATH=/opt/ros/melodic \
-DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=TRUE -DCMAKE_BUILD_TYPE:STRING=Release \
-DCMAKE_C_COMPILER:FILEPATH=/usr/bin/x86_64-linux-gnu-gcc-7 \
-DCMAKE_CXX_COMPILER:FILEPATH=/usr/bin/x86_64-linux-gnu-g++-7 \
-S/home/will/allpros/avp_slam_sim \
-B/home/will/allpros/avp_slam_sim/build_vsc \
-G "Unix Makefiles"

Also, even if you add export CMAKE_PREFIX_PATH=/opt/ros/melodic:$CMAKE_PREFIX_PATH to ~/.bashrc, you will still get an error after restarting the computer and doing configure, where the path /opt/ros/melodic was determined when installing ros Of course, you can also use the command find / -iname *.catkin or locate *.catkin to find the specific path.
To summarize.
The reason for this is unclear. It is suspected that the environment variable ${CMAKE_PREFIX_PATH} obtained by vscode during cmake-configure is empty, but when using the system terminal ${CMAKE_PREFIX_PATH} has the value /opt/ros/melodic, which comes from the source /opt/ros/melodic at boot time. source /opt/ros/melodic/setup.bash, which is already written in the ~/.bashrc auto-execution file when we installed ROS, and after booting, echo $CMAKE_PREFIX_PATH in system terminal can output /opt/ros/melodic normally. .

Solution:
1. modify the system file directly

$ sudo gedit /opt/ros/melodic/share/catkin/cmake/toplevel.cmake

Add the following in /opt/ros/melodic/share/catkin/cmake/toplevel.cmake

list(APPEND CMAKE_PREFIX_PATH "/opt/ros/melodic")

The results are as follows:

# toplevel CMakeLists.txt for a catkin workspace
# catkin/cmake/toplevel.cmake

cmake_minimum_required(VERSION 3.0.2)

project(Project)

set(CATKIN_TOPLEVEL TRUE)

list(APPEND CMAKE_PREFIX_PATH "/opt/ros/melodic")

# search for catkin within the workspace
set(_cmd "catkin_find_pkg" "catkin" "${CMAKE_SOURCE_DIR}")
execute_process(COMMAND ${_cmd}
  RESULT_VARIABLE _res
  OUTPUT_VARIABLE _out
  ERROR_VARIABLE _err
  OUTPUT_STRIP_TRAILING_WHITESPACE
  ERROR_STRIP_TRAILING_WHITESPACE
)
...
...
...

2. add attribute in cmake setting of vscode

Ctrl+Shift+P –> preferences: open settings (JSON)
add:

"cmake.configureArgs": [
        "-DCMAKE_PREFIX_PATH=/opt/ros/melodic"
    ],