Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/kotlin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
&引用;找不到符号“;在java程序中_Java_Classpath_Javac - Fatal编程技术网

&引用;找不到符号“;在java程序中

&引用;找不到符号“;在java程序中,java,classpath,javac,Java,Classpath,Javac,因此,这是一个两难的问题: 我正在用两个不同的类和两个不同的包编写一个程序。然而,当我试图从BaseGame调用一个方法时(使用该方法的类)。我检查了拼写,我只是感到困惑 代码如下: 来自Automobile.java: package mygame.model; import com.jme3.bullet.BulletAppState; import com.jme3.app.SimpleApplication; import com.jme3.bounding.BoundingBox;

因此,这是一个两难的问题: 我正在用两个不同的类和两个不同的包编写一个程序。然而,当我试图从BaseGame调用一个方法时(使用该方法的类)。我检查了拼写,我只是感到困惑

代码如下:

来自Automobile.java:

package mygame.model;

import com.jme3.bullet.BulletAppState;
import com.jme3.app.SimpleApplication;
import com.jme3.bounding.BoundingBox;
import com.jme3.bullet.PhysicsSpace;
import com.jme3.bullet.collision.shapes.CollisionShape;
import com.jme3.bullet.collision.shapes.MeshCollisionShape;
import com.jme3.bullet.control.VehicleControl;
import com.jme3.bullet.nodes.PhysicsNode;
import com.jme3.bullet.objects.VehicleWheel;
import com.jme3.bullet.util.CollisionShapeFactory;
import com.jme3.input.KeyInput;
import com.jme3.input.controls.ActionListener;
import com.jme3.input.controls.KeyTrigger;
import com.jme3.light.DirectionalLight;
import com.jme3.material.Material;
import com.jme3.math.FastMath;
import com.jme3.math.Matrix3f;
import com.jme3.math.Vector2f;
import com.jme3.math.Vector3f;
import com.jme3.renderer.queue.RenderQueue.ShadowMode;
import com.jme3.scene.Geometry;
import com.jme3.scene.Node;
import com.jme3.scene.Spatial;
import com.jme3.scene.shape.Box;
import com.jme3.shadow.BasicShadowRenderer;
import com.jme3.texture.Texture.WrapMode;
import mygame.BaseGame;

public class Automobile extends Model {
    float stiffness;
    float compValue;
    float dampValue;
    float mass;
    Node node;
    VehicleControl vehicle;
    float wheelRadius;

    // <editor-fold defaultstate="collapsed" desc="findGeom">
private Geometry findGeom(Spatial spatial, String name) {
    if (spatial instanceof Node) {
        Node node = (Node) spatial;
        for (int i = 0; i < node.getQuantity(); i++) {
            Spatial child = node.getChild(i);
            Geometry result = findGeom(child, name);
            if (result != null) {
                return result;
            }
        }
    } else if (spatial instanceof Geometry) {
        if (spatial.getName().startsWith(name)) {
            return (Geometry) spatial;
        }
    }
    return null;
}// </editor-fold>
    private void buildVehicle() {
    //Load model and get chassis Geometry
    node = (Node)loadModel("Models/Ferrari/Car.scene");
    node.setShadowMode(ShadowMode.Cast);
    Geometry chasis = findGeom(node, "Car");
    BoundingBox box = (BoundingBox) chasis.getModelBound();

    //Create a hull collision shape for the chassis
    CollisionShape carHull = CollisionShapeFactory.createDynamicMeshShape(chasis);

    //Create a vehicle control
    vehicle = new VehicleControl(carHull, mass);
    node.addControl(vehicle);

    //Setting default values for wheels
    vehicle.setSuspensionCompression(compValue * 2.0f * FastMath.sqrt(stiffness));
    vehicle.setSuspensionDamping(dampValue * 2.0f * FastMath.sqrt(stiffness));
    vehicle.setSuspensionStiffness(stiffness);
    vehicle.setMaxSuspensionForce(10000);

    //Create four wheels and add them at their locations
    //note that our fancy car actually goes backwards..
    Vector3f wheelDirection = new Vector3f(0, 1, 0);
    Vector3f wheelAxle = new Vector3f(-1, 0, 0);

    Geometry wheel_fr = findGeom(node, "WheelFrontRight");
    wheel_fr.center();
    box = (BoundingBox) wheel_fr.getModelBound();
    wheelRadius = box.getYExtent();
    float back_wheel_h = (wheelRadius * 1.7f) - 1f;
    float front_wheel_h = (wheelRadius * 1.9f) - 1f;
    vehicle.addWheel(wheel_fr.getParent(), box.getCenter().add(0, -front_wheel_h, 0),
            wheelDirection, wheelAxle, 0.2f, wheelRadius, true);

    Geometry wheel_fl = findGeom(node, "WheelFrontLeft");
    wheel_fl.center();
    box = (BoundingBox) wheel_fl.getModelBound();
    vehicle.addWheel(wheel_fl.getParent(), box.getCenter().add(0, -front_wheel_h, 0),
            wheelDirection, wheelAxle, 0.2f, wheelRadius, true);

    Geometry wheel_br = findGeom(node, "WheelBackRight");
    wheel_br.center();
    box = (BoundingBox) wheel_br.getModelBound();
    vehicle.addWheel(wheel_br.getParent(), box.getCenter().add(0, -back_wheel_h, 0),
            wheelDirection, wheelAxle, 0.2f, wheelRadius, false);

    Geometry wheel_bl = findGeom(node, "WheelBackLeft");
    wheel_bl.center();
    box = (BoundingBox) wheel_bl.getModelBound();
    vehicle.addWheel(wheel_bl.getParent(), box.getCenter().add(0, -back_wheel_h, 0),
            wheelDirection, wheelAxle, 0.2f, wheelRadius, false);

    vehicle.getWheel(2).setFrictionSlip(4);
    vehicle.getWheel(3).setFrictionSlip(4);

}
public Automobile(Spatial sp){
    super(sp);
}
}
*编辑 下面是错误:

E:\Game\BasicGame\src\mygame\model\Automobile.java:64: cannot find symbol
symbol  : method loadModel(java.lang.String)
location: class mygame.model.Automobile
    node = (Node)loadModel("Models/Ferrari/Car.scene");

而且,我确实导入了该类。

loadModel
是一种非静态方法。您需要从类的对象实例调用它

此外,即使它是一个静态方法,您也应该从它的类中调用它,例如
BaseGame.loadModel(“somestring”)

在你编辑了你的答案后,我认为这显然是问题所在:

  • 您在main(
    BaseGame app=newbasegame();
    )中实例化了一个
    BaseGame
    对象,但您似乎没有为它实现任何特殊功能
  • 在一个单独的包中有一个单独的类,它没有对
    BaseGame
    实例的引用,因为没有人向它传递这样的引用,
    import
    而不是一个实例化

编译失败的代码行是什么?消息是什么?能否粘贴整个代码(不仅仅是片段)以及整个错误消息(请逐字记录)?好的,但是如果
Automobile
出于某种奇怪的原因是
BaseGame
的子类呢?;-)或者,可能
Automobile
有自己的
loadModel
方法调用
base.loadModel(…)
?:-P(这正是我要求提供全部代码文件,而不仅仅是代码片段的原因。)@Chris-你的评论是合理的,但因为OP没有提到这件事,而且名字似乎也不相关。。。还有,我只是在发布后才看到你的评论…我知道我做了什么。非常感谢。现在,我必须找出访问
assetManager
的最佳方式。
E:\Game\BasicGame\src\mygame\model\Automobile.java:64: cannot find symbol
symbol  : method loadModel(java.lang.String)
location: class mygame.model.Automobile
    node = (Node)loadModel("Models/Ferrari/Car.scene");