添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
相关文章推荐
冷冷的芒果  ·  Linen Community·  昨天    · 
焦虑的春卷  ·  Need help with ...·  昨天    · 
鬼畜的面包  ·  VS Code extension is ...·  昨天    · 
阳光的弓箭  ·  해결됨: fatal error ...·  昨天    · 
逃跑的生菜  ·  android编译失败 ...·  昨天    · 
八块腹肌的小刀  ·  帮助系统·  1 月前    · 
淡定的葡萄  ·  AAPT2 Daemon startup ...·  7 月前    · 
跑龙套的胡萝卜  ·  pandas.Series.dt.to_py ...·  1 年前    · 

I’m trying to follow this youtube api tutorial:

https://developers.google.com/youtube/v3/quickstart/java
I use java version “13.0.2” on a fresh lubuntu 19.10 distro

My folder structure is as follows

/src/main/build.gradle
/src/main/java/ApiExample.java

Following the tutorial I should be able to execute ApiExample as follows:

gradle -q run

However this exits with the following exception:
“Error: Could not find or load main class ApiExample
Caused by: java.lang.ClassNotFoundException: ApiExample”

My build.gradle is as follows:

apply plugin: ‘java’
apply plugin: ‘application’

mainClassName = ‘ApiExample’
sourceCompatibility = 1.7
targetCompatibility = 1.7
version = ‘1.0’

repositories {
mavenCentral()

dependencies {
compile ‘com.google.api-client:google-api-client:1.23.0’
compile ‘com.google.oauth-client:google-oauth-client-jetty:1.23.0’
compile ‘com.google.apis:google-api-services-youtube:v3-rev222-1.25.0’

After what I’ve read the folder structure should be ok and the build file is copied from the tutorial. Any ideas what is missing?

Your build.gradle file belongs in the root of the project, not in the src/main directory. Your file structure for the project should be:

/build.gradle
/src/main/java/ApiExample.java

The Java plugin is going to look for the src in src/main/java relative to the project, so your stated structure would cause the ApiExample.java file to not be compiled or available. Therefore, ClassNotFoundException.

While executing, when JVM does not find a .class file with the specified name then a run time error occurs saying “Could not found or load main class”. The reason why this happens is mostly due to:

  • Wrong Class Name
  • Invalid Classpath
  • Main class could not be found when there is typo or wrong syntax in the fully qualified java class name or it does not exist in the provided classpath. You must ensure that you add the location of your .class file to your classpath. So, if its in the current folder, add . to your classpath. Note that the Windows classpath separator is a semi-colon ; . If you want to execute the main() method in MainClass, you must use the full class name, including package name, in the java command.