【问题标题】:Classes are being created without packages in Netbeans在 Netbeans 中创建的类没有包
【发布时间】:2022-01-08 04:03:47
【问题描述】:

每次我尝试使用 LibGDX 和 netbeans 时,我都在努力入门。

create class

class created

我不确定这些照片是否会显示,因为我刚刚创建了我的帐户并且我的声誉很低,但让我解释一下,以防它们不会显示。

所以我使用 LibGDX 创建了另一个项目,这是我得到的结果:

Executing 'C:\.....\ProTest/gradlew.bat clean --no-daemon' To honour
> the JVM settings for this build a new JVM will be forked. Please
> consider using the daemon:
> https://docs.gradle.org/6.7.1/userguide/gradle_daemon.html. Daemon
> will be stopped at the end of the build stopping after processing
> > Task :android:clean UP-TO-DATE
> > Task :core:clean UP-TO-DATE
> > Task :desktop:clean UP-TO-DATE
> > Task :html:clean
> > Task :ios:clean UP-TO-DATE Warning: Failed to parse host SSTap Warning: Failed to parse host SSTap Deprecated Gradle features were
> used in this build, making it incompatible with Gradle 7.0. Use
> '--warning-mode all' to show the individual deprecation warnings. See
> https://docs.gradle.org/6.7.1/userguide/command_line_interface.html#sec:command_line_warnings
> BUILD SUCCESSFUL in 21s 5 actionable tasks: 1 executed, 4 up-to-date
> Done! To import in Eclipse: File -> Import -> Gradle -> Existing
> Gradle Project To import to Intellij IDEA: File -> Open ->
> build.gradle To import to NetBeans: File -> Open Project...

之后我打开了Netbeans并打开了项目,trustgradle执行...... 我从创建的子项目中打开了核心、桌面和 IO,没有任何问题。

我去了桌面项目,里面有一个名为“DesktopLauncher”的类

里面的代码是

> package com.supa.testa.desktop; import
> com.badlogic.gdx.backends.lwjgl.LwjglApplication; import
> com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration; public
> class DesktopLauncher {   public static void main (String[] arg) {
>       LwjglApplicationConfiguration config = new
> LwjglApplicationConfiguration();      new LwjglApplication(new Testo (),
> config);  } }

我在路径“com.supa.testa”中创建了一个类,但它是在顶部没有提及包的情况下创建的,我认为通过使用扩展游戏会以某种方式修复,因为我找不到错误甚至写我自己沿着包路径...“Testo”类的代码现在看起来像这样:

package com.supa.testa;
import com.badlogic.gdx.Game;
public class Testo extends Game{
    @Override
    public void create() {
    }
    
}

所以我回到 DesktopLauncher 类并尝试使用我不知道名称的“灯泡”创建一个类(请帮助我),并且在另一个路径中创建了另一个具有相同名称“Testo”的类但同样没有顶部的包,它自己实现了 ApplicaitonListener

import com.badlogic.gdx.ApplicationListener;
public class Testo implements ApplicationListener {
    public Testo() {
    }
    
}

然后我回到 DesktopLauncher 做了同样的事情,我可以一遍又一遍地这样做 它将成为“Testo_1”“Testo_2”,该类将永远不会有包,也永远不会被识别

我尝试从桌面构建和清理项目,核心,项目本身,清理,单独构建

打开和关闭的 netbeans

创建不同的项目(这是最后一个)

我尝试的最后一件事,我在代码后按了“Ctrl +空格键”:

new LwjglApplication(new .....

并且出现的类来自其他项目

当我使用 LibGDX 创建项目时,我随机遇到了这个问题

但现在我无法摆脱它哈哈

我不确定它是否与守护进程有关

在另一个测试中,我从 badlogicgames 执行的“LwjglApplicationConfiguration”库似乎没有加载,因为我无法使用,根本没有出现,即使在手动编写后它也无法工作(与包:()

祝你有美好的一天:D

重新编辑:

我尝试创建另一个项目,之前使用的是桌面、Android、IO 和 Html

我只尝试了台式机,并且软件包工作正常

我尝试使用 Desktop 和 Html,这就是我得到的

Generating app in C:......
Executing 'C:\........ setup\ProTestD__H/gradlew.bat clean --no-daemon'
To honour the JVM settings for this build a new JVM will be forked. Please consider using the daemon: https://docs.gradle.org/6.7.1/userguide/gradle_daemon.html.
Daemon will be stopped at the end of the build stopping after processing

FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring root project 'ProTestD__H'.
> Could not resolve all artifacts for configuration ':classpath'.
   > Could not download commons-logging-1.1.1.jar (commons-logging:commons-logging:1.1.1)
      > Could not get resource 'https://repo.maven.apache.org/maven2/commons-logging/commons-logging/1.1.1/commons-logging-1.1.1.jar'.
         > Could not HEAD 'https://repo.maven.apache.org/maven2/commons-logging/commons-logging/1.1.1/commons-logging-1.1.1.jar'.
            > SSTap

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 13s
Done!
To import in Eclipse: File -> Import -> Gradle -> Existing Gradle Project
To import to Intellij IDEA: File -> Open -> build.gradle
To import to NetBeans: File -> Open Project...

之后我打开项目尝试: 使用 --stacktrace 选项运行以获取堆栈跟踪。使用 --info 或 --debug 选项运行以获得更多日志输出。运行 --scan 以获得完整的见解。

在运行 gradle "--stacktrace" 中:

enter image description here

enter image description here

enter image description here

enter image description here

代码还在运行我不确定照片是否会上传,而且照片很多,所以我不能在这里复制粘贴,我会尝试过去我认为重要的内容

FAILURE:构建失败并出现异常。

  • 出了什么问题:配置根项目“ProTestD__H”时出现问题。

无法解析配置“:classpath”的所有工件。 无法下载 commons-logging-1.1.1.jar (commons-logging:commons-logging:1.1.1) > 无法获取资源 'ttps://repo.maven.apache.org/maven2/commons-logging/commons-logging/1.1.1/commons-logging-1.1.1.jar'。 > 无法 HEAD 'ttps://repo.maven.apache.org/maven2/commons-logging/commons-logging/1.1.1/commons-logging-1.1.1.jar'。 > SSTap

  • 尝试:使用 --info 或 --debug 选项运行以获得更多日志输出。运行 --scan 以获得完整的见解。

  • 异常是:org.gradle.api.ProjectConfigurationException:配置根项目“ProTestD__H”时出现问题。在 org.gradle.configuration.project.LifecycleProjectEvaluator.wrapException(LifecycleProjectEvaluator.java:75)

原因: org.gradle.api.internal.artifacts.ivyservice.DefaultLenientConfiguration$ArtifactResolveException: 无法解析配置“:classpath”的所有工件。

原因:org.gradle.internal.resolve.ArtifactResolveException:可能 不下载 commons-logging-1.1.1.jar (commons-logging:commons-logging:1.1.1)

原因:org.gradle.api.resources.ResourceException:无法获取 资源 'ttps://repo.maven.apache.org/maven2/commons-logging/commons-logging/1.1.1/commons-logging-1.1.1.jar'。

原因: org.gradle.internal.resource.transport.http.HttpRequestException: 无法 HEAD 'ttps://repo.maven.apache.org/maven2/commons-logging/commons-logging/1.1.1/commons-logging-1.1.1.jar'。

原因:java.net.UnknownHostException: SSTap

使用“--info”得到:

FAILURE:构建失败并出现异常。

  • 出了什么问题:配置根项目“ProTestD__H”时出现问题。

无法解析配置“:classpath”的所有工件。 无法下载 commons-logging-1.1.1.jar (commons-logging:commons-logging:1.1.1) > 无法获取资源 'ttps://repo.maven.apache.org/maven2/commons-logging/commons-logging/1.1.1/commons-logging-1.1.1.jar'。 > 无法 HEAD 'ttps://repo.maven.apache.org/maven2/commons-logging/commons-logging/1.1.1/commons-logging-1.1.1.jar'。 > SSTap

  • 尝试:使用 --stacktrace 选项运行以获取堆栈跟踪。使用 --debug 选项运行以获得更多日志输出。运行 --scan 以获得完整的见解。

使用“--scan”得到这个:

.\gradlew.bat --configure-on-demand -w --scan -x check

FAILURE:构建失败并出现异常。

  • 其中:使用 --scan 自动应用

  • 出了什么问题:插件 [id: 'com.gradle.enterprise', version: '3.4.1', artifact: 'com.gradle:gradle-enterprise-gradle-plugin:3.4.1'] 在以下任何来源中均未找到:

  • Gradle 核心插件(插件不在 'org.gradle' 命名空间中)
  • 插件存储库(无法解析插件工件 'com.gradle:gradle-enterprise-gradle-plugin:3.4.1') 以下存储库: Gradle Central 插件库
  • 尝试:使用 --stacktrace 选项运行以获取堆栈跟踪。使用 --info 或 --debug 选项运行以获得更多日志输出。运行 --scan 以获得完整的见解。

  • 在 ttps://help.gradle.org 获得更多帮助

在 2 秒内构建失败

我在尝试解决和信任该项目时得到了这个

SSTap<br/>Could not HEAD 'https://repo.maven.apache.org/maven2/commons-logging/commons-logging/1.1.1/commons-logging-1.1.1.jar'.<br/>Could not get resource 'https://repo.maven.apache.org/maven2/commons-logging/commons-logging/1.1.1/commons-logging-1.1.1.jar'.<br/>Could not download commons-logging-1.1.1.jar (commons-logging:commons-logging:1.1.1)<br/>Could not resolve all artifacts for configuration ':classpath'.<br/>A problem occurred configuring root project 'ProTestD__H'.<br/>A problem occurred configuring root project 'ProTestD__H'.<br/>Could not run build action using connection to Gradle installation 'C:\......\.gradle\wrapper\dists\gradle-6.7.1-bin\bwlcbys1h7rz3272sye1xwiv6\gradle-6.7.1'.

我也尝试按照LibGDX tutorials LibGDX tutorials 中的教程进行操作 尝试使用桌面文件夹在 android 中运行项目时 我得到了“警告:在模块'Test'中找不到类'com.my.game.desktop.DesktopLauncher'”,我申请了,尝试运行并得到: 无法从“https://services.gradle.org/distributions/gradle-6.7.1-bin.zip”安装 Gradle 发行版。

这是我的 build.gradle

buildscript {
    

    repositories {
        mavenLocal()
        mavenCentral()
        gradlePluginPortal()
        maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
        google()
    }
    dependencies {
        classpath 'org.wisepersist:gwt-gradle-plugin:1.0.13'
        classpath 'org.gretty:gretty:3.0.2'
        classpath 'com.android.tools.build:gradle:3.5.4'
        classpath 'com.mobidevelop.robovm:robovm-gradle-plugin:2.3.12'
        

    } }

allprojects {
    apply plugin: "eclipse"

    version = '1.0'
    ext {
        appName = "Kiya"
        gdxVersion = '1.10.0'
        roboVMVersion = '2.3.12'
        box2DLightsVersion = '1.5'
        ashleyVersion = '1.7.3'
        aiVersion = '1.8.2'
        gdxControllersVersion = '2.1.0'
    }

    repositories {
        mavenLocal()
        mavenCentral()
        google()
        gradlePluginPortal()
        maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
        maven { url "https://oss.sonatype.org/content/repositories/releases/" }
    } }

project(":desktop") {
    apply plugin: "java-library"


    dependencies {
        implementation project(":core")
        api "com.badlogicgames.gdx:gdx-backend-lwjgl:$gdxVersion"
        api "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-desktop"
        api "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-desktop"
        
    } }

project(":android") {
    apply plugin: "com.android.application"

    configurations { natives }

    dependencies {
        implementation project(":core")
        api "com.badlogicgames.gdx:gdx-backend-android:$gdxVersion"
        natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-armeabi-v7a"
        natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-arm64-v8a"
        natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-x86"
        natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-x86_64"
        api "com.badlogicgames.gdx:gdx-box2d:$gdxVersion"
        natives "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-armeabi-v7a"
        natives "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-arm64-v8a"
        natives "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-x86"
        natives "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-x86_64"
        
    } }

project(":ios") {
    apply plugin: "java-library"
    apply plugin: "robovm"


    dependencies {
        implementation project(":core")
        api "com.mobidevelop.robovm:robovm-rt:$roboVMVersion"
        api "com.mobidevelop.robovm:robovm-cocoatouch:$roboVMVersion"
        api "com.badlogicgames.gdx:gdx-backend-robovm:$gdxVersion"
        api "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-ios"
        api "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-ios"
        
    } }

project(":html") {
    apply plugin: "java-library"
    apply plugin: "gwt"
    apply plugin: "war"
    apply plugin: "org.gretty"


    dependencies {
        implementation project(":core")
        api "com.badlogicgames.gdx:gdx-backend-gwt:$gdxVersion"
        api "com.badlogicgames.gdx:gdx:$gdxVersion:sources"
        api "com.badlogicgames.gdx:gdx-backend-gwt:$gdxVersion:sources"
        api "com.badlogicgames.gdx:gdx-box2d:$gdxVersion:sources"
        api "com.badlogicgames.gdx:gdx-box2d-gwt:$gdxVersion:sources"
        
    } }

project(":core") {
    apply plugin: "java-library"


    dependencies {
        api "com.badlogicgames.gdx:gdx:$gdxVersion"
        api "com.badlogicgames.gdx:gdx-box2d:$gdxVersion"
        
    } }

【问题讨论】:

    标签: java class netbeans libgdx package


    【解决方案1】:

    不确定我是否正确理解了这个问题,但如果你的问题是,DesctopLauncher 不知道 Testo 类,你只需要导入它import com.supa.testa.Testo

    您还应该将像 Testo 这样的游戏类(和包)放在核心项目中,因为它将在所有项目(桌面和 ios)中使用。

    你应该看看libGDX tutorials
    特别是SetupHello World 应该包含您要搜索的内容。

    【讨论】:

    • 我也试过了,但是不行,我知道我应该把它写在核心上,但是如果我这样做了,我将无法运行该项目。
    • 据我所知,如果我在核心中创建一个类,它应该在项目中创建:桌面、android、html 和 IO,但它没有。我试图自己创建包,也尝试自己导入它们,但这不起作用我可以在同一个项目中创建相同的类,但不能在同一个包中创建,但我仍然无法在另一个类中调用该类
    • 如果在核心项目中创建一个类,其他所有项目都可以使用,但不会在所有项目中复制任何类。您的 build.gradle 文件中似乎存在问题,导致构建失败。您可以更新您的问题并添加 build.gradle 的内容吗? (根目录下的那个,桌面、android、html文件夹都放在那里)
    • 我已经添加了 build.gradle
    • build.gradle 文件对我来说似乎没问题。失败的 apache commons-logging-1.1.1.jar 可能只是第一个被拉取的传递依赖。这可能是您的 gradle 的普遍问题。我真的不知道是什么原因造成的。也许这值得提出一个新问题......
    【解决方案2】:

    我还有这个帖子...Removing the proxy and host from Netbeans 我刚刚修复了它....即使包在核心或桌面项目中仍然不可见,如果我在核心中创建一个类并将一些代码放入其中并且从 Desktoplauncher 运行它,即使它显示错误 找不到符号(类),它也能正常工作,但项目运行完美......现在 O_O

    这些类仍然是在没有包的情况下创建的,如果包是我自己创建(键入)的,它会显示错误,但现在它可以工作了。即使是使用 ScreenAdapter 的项目

    这就是我所做的......

    我进入了我在 C:\Users\User 中找到的 gradle.properties 文件。 gradle里面是这样的:

        ## For more details on how to configure your build environment visit
        # http://www.gradle.org/docs/current/userguide/build_environment.html
        #
        # Specifies the JVM arguments used for the daemon process.
        # The setting is particularly useful for tweaking memory settings.
        # Default value: -Xmx1024m -XX:MaxPermSize=256m
        # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
        #
        # When configured, Gradle will run in incubating parallel mode.
        # This option should only be used with decoupled projects. More details, visit
        # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
        # org.gradle.parallel=true
        #Sat Dec 25 18:51:22 CST 2021 
    systemProp.http.proxyHost=SSTap 
    systemProp.https.proxyHost=SSTap 
    systemProp.https.proxyPort=25378 
    systemProp.http.proxyPort=25378 
    systemProp.https.nonProxyHosts=127.0.0.1
    systemProp.http.nonProxyHosts=127.0.0.1
    

    我删除了最后 6 行,在 LibGDX 中使用 Desktop、Android、IOs、HTML 创建了一个新项目,使用 gradle 信任所有项目,创建类时没有包,如果我自己创建或导入它们(在桌面项目)。即使它在核心路径中说“找不到符号”(类),例如导入 com.pokedemon.game.Hello;代码运行

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-09-06
      • 1970-01-01
      • 2016-05-01
      • 2011-07-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-10-14
      相关资源
      最近更新 更多