简体   繁体   English

我不断收到错误消息:无法找到或加载主类,无法找出原因?

[英]I keep getting Error: Could not find or load main class and cant figure out why?

I am extremely brand new at coding and trying to teach myself some tricks, but they arent working. 我在编码和尝试教自己一些技巧方面是全新的,但是他们没有工作。 Here is my code, someone told me that my braces may be wrong but I cant understand why it wont compile. 这是我的代码,有人告诉我我的花括号可能是错误的,但是我不明白为什么它无法编译。 I keep getting the Error:Could not find or load main class. 我不断收到错误消息:找不到或加载主类。 Perhaps I am accessing it incorrectly? 也许我访问不正确? Thank you in advance for helping me learn how to do this correctly. 预先感谢您帮助我学习如何正确执行此操作。

public class Point3D {
    public int x;
    public int y;
    public int z;

    public Point3D (int xAxis, int yAxis, int zAxis) {
    }
    public int getxAxis (int x) {
        return x;
    }
    public int getyAxis (int y) {
        return y;
    }
    public int getzAxis (int z) {
        return z;
    }
    public void setx(int xAxis){
        this.x = xAxis;
    }
    public void sety(int yAxis){
        this.y = yAxis;
    }
    public void setz(int zAxis){
        this.z = zAxis;
    }
    public int getDistanceToOrigin (int x, int y, int z, int x1, int y1, int z1) {
        return getDistanceToOrigin = ((int x1-int x); (int y1-int y); (int z1-int z));
    }
    public int getDistance (int x, int y, int z, int x1, int y1, int z1) {
        return getDistance = ((5 - int x); (7 - int y); (9-int z));
    }

    public void howFar (){
        System.out.println ("Your original point is at: " 
                 +Point3D +"and is: " +getDistanceToOrigin +" away from the "
                 + "origin of 0, 0, 0");
    }
    public static void main(String[] args) {
        Point3D location = new Point3D();
            location.setx(3);
            location.sety(2);
            location.setz(1);
            location.getDistance();
            location.howFar();
    }
}

Mistakes 误区

1.make your variables private if you are accessing them from getter/setters. 1.如果您要从getter / setter访问变量,则将它们设为私有。

public int x;
public int y;
public int z;
  1. Default constructors 默认构造函数

    Point3D location = new Point3D(); this will make a call to the default constructor but in your case there is none. 这将调用默认构造函数,但是在您的情况下,没有任何构造函数。 This will also create an error. 这也会产生错误。 Either create a default constructor or make objects like 创建默认的构造函数或使对象类似
    Point3D location = new Point3D(1,2,3);

  2. Mistake 3(Dont know what are yr trying to do here ) 错误3(不知道您打算在这里做什么)

    public int getDistanceToOrigin (int x, int y, int z, int x1, int y1, int z1) {

      return getDistanceToOrigin = ((int x1-int x); (int y1-int y); (int z1-int z)); } public int getDistance (int x, int y, int z, int x1, int y1, int z1) { return getDistance = ((5 - int x); (7 - int y); (9-int z)); } 

return getDistanceToOrigin = ((int x1-int x); (int y1-int y); (int z1-int z)); A return statement can return only one thing, it cannot have ; return语句只能返回一件事,而不能返回; in between it will return only one interger value, if you want to return two or more numbers then you may have to return an array of numbers. 两者之间将仅返回一个整数值,如果要返回两个或多个数字,则可能必须返回一个数字数组。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么我找不到或加载主类错误? - Why am I getting could not find or load main class error? 我一直收到错误消息“找不到或加载主类gradebooktest.GradeBookTest”,我不确定为什么 - I keep getting an error saying “Could not find or load main class gradebooktest.GradeBookTest” I am not sure why 我不断收到此错误错误:无法找到或加载主类javaclass.Javaclass - i keep getting this error Error: Could not find or load main class javaclass.Javaclass 在Eclipse中,为什么会出现错误“错误:找不到或加载主类Coordinator.java”? - In Eclipse, why am I getting the error “Error: Could not find or load main class Coordinator.java”? 为什么在NetBeans中出现“无法找到或加载主类……”错误? - Why am I getting “Could not find or load main class …” error in NetBeans? 不断出错:尽管设置了PATH和CLASSPATH变量,却找不到或加载主类 - Keep getting Error: Could not find or load main class although set the PATH and CLASSPATH variables 无法弄清楚为什么我不断收到找不到符号编译错误 - Can't figure out why i keep getting cannot find symbol compile error 错误:无法找到或加载主类... - Eclipse中的Maven项目 - Error: Could not find or load main class … - Maven project out of Eclipse 即使我在清单文件中定义了Main-class,也会出现“错误:找不到或加载类” - Getting “Error: Could not find or load class” even though I have the Main-class defined in a Manifest File 无法弄清楚如何运行我的jar文件“找不到或加载主类” - Can't figure out how to run my jar file “could not find or load main class”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM