首页 > Java > 线程'JavaFX应用程序线程”java.lang.NoClassDefFoundError中的异常:org/openqa/selenium/WebDriver

线程'JavaFX应用程序线程”java.lang.NoClassDefFoundError中的异常:org/openqa/selenium/WebDriver

WBOY
发布: 2024-02-22 14:30:09
转载
1393 人浏览过

php小编新一带来的Java问答:在开发JavaFX应用程序时,有时会遇到异常java.lang.NoClassDefFoundError,错误提示为org/openqa/selenium/WebDriver。这个异常通常表示缺少WebDriver类的依赖包,需要在项目中添加相应的依赖以解决该问题。接下来我们将详细介绍如何处理这种异常,并提供解决方案,让您顺利解决线程问题。

问题内容

根据我当前的代码,有什么可能导致此异常的线索吗?

运行以下代码时:

main.java

package application;
    
import java.io.ioexception;

import javafx.application.application;
import javafx.stage.stage;
import javafx.scene.scene;
import javafx.scene.control.button;
import javafx.scene.layout.gridpane;


public class main extends application {
    @override
    public void start(stage primarystage) throws ioexception {
        button runbutton = new button("run");

        runbutton.setonaction(e -> {
            test test = new test();
        });
        
        gridpane gridbox = new gridpane();
        
        gridbox.add(runbutton, 0, 0);

        scene scene = new scene(gridbox, 380, 150);
        
        primarystage.setscene(scene);
        primarystage.show();
    }
    
    public static void main(string[] args) {
        launch(args);
    }
}
登录后复制

测试.java

package application;

import org.openqa.selenium.webdriver;
import org.openqa.selenium.chrome.chromedriver;

public class test {
    webdriver driver;
    
    public static void main(string[] args) {
        test obj = new test();
        obj.setupwebsite();
    }
    
    public void setupwebsite() {
        //creates chrome window.
        driver = new chromedriver();
        
        //sets up window to maximize and go to brink website.
        driver.manage().window().maximize();
        driver.get("https://www.google.com");
    }
}
登录后复制

我得到的只是以下内容:

Exception in thread "JavaFX Application Thread" java.lang.NoClassDefFoundError: org/openqa/selenium/WebDriver
    at application.Main.lambda$0(Main.java:18)
    at [email protected]/com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:86)
    at [email protected]/com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:232)
    at [email protected]/com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:189)
    at [email protected]/com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
    at [email protected]/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
    at [email protected]/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
    at [email protected]/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
    at [email protected]/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
    at [email protected]/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
    at [email protected]/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
    at [email protected]/com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
    at [email protected]/com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:49)
    at [email protected]/javafx.event.Event.fireEvent(Event.java:198)
    at [email protected]/javafx.scene.Node.fireEvent(Node.java:8875)
    at [email protected]/javafx.scene.control.Button.fire(Button.java:203)
    at [email protected]/com.sun.javafx.scene.control.behavior.ButtonBehavior.mouseReleased(ButtonBehavior.java:207)
    at [email protected]/com.sun.javafx.scene.control.inputmap.InputMap.handle(InputMap.java:274)
    at [email protected]/com.sun.javafx.event.CompositeEventHandler$NormalEventHandlerRecord.handleBubblingEvent(CompositeEventHandler.java:247)
    at [email protected]/com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:80)
    at [email protected]/com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:232)
    at [email protected]/com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:189)
    at [email protected]/com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
    at [email protected]/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
    at [email protected]/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
    at [email protected]/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
    at [email protected]/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
    at [email protected]/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
    at [email protected]/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
    at [email protected]/com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
    at [email protected]/com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:54)
    at [email protected]/javafx.event.Event.fireEvent(Event.java:198)
    at [email protected]/javafx.scene.Scene$MouseHandler.process(Scene.java:3984)
    at [email protected]/javafx.scene.Scene.processMouseEvent(Scene.java:1890)
    at [email protected]/javafx.scene.Scene$ScenePeerListener.mouseEvent(Scene.java:2708)
    at [email protected]/com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:411)
    at [email protected]/com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:301)
    at java.base/java.security.AccessController.doPrivileged(AccessController.java:400)
    at [email protected]/com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleMouseEvent$2(GlassViewEventHandler.java:450)
    at [email protected]/com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(QuantumToolkit.java:424)
    at [email protected]/com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:449)
    at [email protected]/com.sun.glass.ui.View.handleMouseEvent(View.java:551)
    at [email protected]/com.sun.glass.ui.View.notifyMouse(View.java:937)
    at [email protected]/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
    at [email protected]/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:185)
    at java.base/java.lang.Thread.run(Thread.java:1583)
Caused by: java.lang.ClassNotFoundException: org.openqa.selenium.WebDriver
    at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641)
    at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:526)
    ... 46 more
登录后复制

我已确认我的所有 jar 文件都位于正确的位置。我可以单独运行 test.java 文件。我有这个代码的更大版本,最初认为这是由于整个代码有问题,但发现即使精简到这个,它仍然会继续。

解决方法

想通了。我必须将所有 JAR 文件添加到运行配置类路径中。

以上是线程'JavaFX应用程序线程”java.lang.NoClassDefFoundError中的异常:org/openqa/selenium/WebDriver的详细内容。更多信息请关注PHP中文网其他相关文章!

相关标签:
来源:stackoverflow.com
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板