用 eclipse 创建javafx 可以运行但是报错的解决方法

版权声明:本文为博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/qq_20936333/article/details/83988729

解决办法:

Eclipse 默认把这些受访问限制的API设成了ERROR。只要把Windows-Preferences-Java-Complicer- Errors/Warnings里面的Deprecated and restricted API中的Forbidden references(access rules)选为Warning就可以编译通过。

展开阅读全文

javaFX报错

04-06

Exception in Application start methodrnjava.lang.reflect.InvocationTargetExceptionrn at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)rn at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)rn at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)rn at java.lang.reflect.Method.invoke(Unknown Source)rn at com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:389)rn at com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:328)rn at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)rn at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)rn at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)rn at java.lang.reflect.Method.invoke(Unknown Source)rn at sun.launcher.LauncherHelper$FXHelper.main(Unknown Source)rnCaused by: java.lang.RuntimeException: Exception in Application start methodrn at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:917)rn at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$155(LauncherImpl.java:182)rn at java.lang.Thread.run(Unknown Source)rnCaused by: javafx.fxml.LoadException: rn/D:/Users/Thinkpad/workspace/Example/bin/application/fxml_example.fxml:10rnrn at javafx.fxml.FXMLLoader.constructLoadException(FXMLLoader.java:2601)rn at javafx.fxml.FXMLLoader.access$700(FXMLLoader.java:103)rn at javafx.fxml.FXMLLoader$ValueElement.processAttribute(FXMLLoader.java:922)rn at javafx.fxml.FXMLLoader$InstanceDeclarationElement.processAttribute(FXMLLoader.java:971)rn at javafx.fxml.FXMLLoader$Element.processStartElement(FXMLLoader.java:220)rn at javafx.fxml.FXMLLoader$ValueElement.processStartElement(FXMLLoader.java:744)rn at javafx.fxml.FXMLLoader.processStartElement(FXMLLoader.java:2707)rn at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2527)rn at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2441)rn at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3214)rn at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3175)rn at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3148)rn at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3124)rn at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3104)rn at javafx.fxml.FXMLLoader.load(FXMLLoader.java:3097)rn at application.Example.start(Example.java:15)rn at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$162(LauncherImpl.java:863)rn at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$175(PlatformImpl.java:326)rn at com.sun.javafx.application.PlatformImpl.lambda$null$173(PlatformImpl.java:295)rn at java.security.AccessController.doPrivileged(Native Method)rn at com.sun.javafx.application.PlatformImpl.lambda$runLater$174(PlatformImpl.java:294)rn at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)rn at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)rn at com.sun.glass.ui.win.WinApplication.lambda$null$148(WinApplication.java:191)rn ... 1 morernCaused by: java.lang.ClassNotFoundException: Controller_examplern at java.net.URLClassLoader.findClass(Unknown Source)rn at java.lang.ClassLoader.loadClass(Unknown Source)rn at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)rn at java.lang.ClassLoader.loadClass(Unknown Source)rn at javafx.fxml.FXMLLoader$ValueElement.processAttribute(FXMLLoader.java:920)rn ... 22 morernException running application application.Examplernrn以上是报错信息, 总说找不到Controller类和hxml文件, 但明明就在那里, 命名的问题也是反复检查也没发现问题, 真的很晕, 请大佬们指点一下, 以下是代码rnrnrn[code=text]rnrnrnrnrnrnrnrnrnrn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rnrnrnrnrn[/code]rnrn[code=java]package application;rnrnimport javafx.fxml.FXML;rnrnimport javafx.scene.control.TextField;rnrnimport javafx.event.ActionEvent;rnrnpublic class Controller_example rn @FXMLrn private TextField actionTarget;rnrn // Event Listener on Button.onActionrn @FXMLrn public void handleAction(ActionEvent event) rn actionTarget.setText("pressed");rn rn[/code]rnrn[code=java]package application;rnrnimport java.io.IOException;rnrnimport javafx.application.Application;rnimport javafx.fxml.FXMLLoader;rnimport javafx.scene.Parent;rnimport javafx.scene.Scene;rnimport javafx.stage.Stage;rnrnpublic class Example extends Application rnrn @Overridern public void start(Stage stage) throws IOException rn Parent root = FXMLLoader.load(getClass().getResource("fxml_example.fxml"));rn Scene scene = new Scene(root, 300, 275);rn stage.setTitle("FXML Welcome");rn stage.setScene(scene);rn stage.show();rn rnrn public static void main(String[] args) rn Application.launch(Example.class, args);rn rnrn[/code]rnrn 论坛

eclipse运行java报错

12-30

求解!!新装eclipse运行一下代码报错 Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0rn at ch4.SwitchDemo.main(SwitchDemo.java:20)rnrn请各位大侠看一下代码rn/**rn *rn *rn */rnrnpackage ch4;rnrn/**rn * @author Administratorrn *rn */rnpublic class SwitchDemo rnrn /**rn * @param argsrn */rn public static void main(String[] args) rn // TODO Auto-generated method stubrn // get year,monthrn int year = Integer.parseInt(args[0]);rn int month = Integer.parseInt(args[1]);rn boolean flag = true; // declare is 'flag' the flag of leap year(闰年)rn int days = -1; // declare the days of a monthrn // switch statement, rn switch(month)rn // when month is in 1,3,5,7,8,10,12, days are 31rn case 1:rn case 3:rn case 5:rn case 7:rn case 8:rn case 10:rn case 12:rn days = 31;rn break;rn // when month is in 4, 6, 9, 11, days are 30rn case 4:rn case 6:rn case 9:rn case 11:rn days = 30;rn break;rn // when month is February, is year leap yearrn case 2:rn if((year%4==0&&year%100!=0)||(year%400==0)) // is the year a leap yearrn flag = true;rn days = 29;rn rn else // year is not a leap yearrn flag = false;rn days = 28;rn rn rn if(flag) // if year is a leap year, and then print year is leap yearrn System.out.println(year + "是闰年[is a leap year!]");rn rn elsern System.out.println(year + "year不是闰年[is not a leap year!]");rn rn System.out.println(year + "年" + "" + month + "月" + "" + days +"天!"); // print the year, month and daysrnrn rnrnrn谢谢各位大侠的真知灼见 论坛

eclipse web项目可以运行.jsp但是不知如何运行.java

11-24

我用eclipse创建了一个web项目,运行jsp文件没问题,但现在我要运行java文件,但是不知道如何运行,我start了一个tomcat,然后试过用Run on Server,结果没用,如下是我加入项目的java文件代码rnimport java.io.BufferedReader;rnimport java.io.DataInputStream;rnimport java.io.DataOutputStream;rnimport java.io.InputStreamReader;rnimport java.net.ServerSocket;rnimport java.net.Socket;rnrnpublic class Main rn public static final int PORT = 8888;//监听的端口号 rnrn public static void main(String[] args) rn System.out.println("服务器启动...\n");rn Main server = new Main();rn server.init();rn rnrn public void init() rn try rn ServerSocket serverSocket = new ServerSocket(PORT);rn while (true) rn // 一旦有堵塞, 则表示服务器与客户端获得了连接 rn Socket client = serverSocket.accept();rn // 处理这次连接 rn new HandlerThread(client);rn rn catch (Exception e) rn System.out.println("服务器异常: " + e.getMessage());rn rn rnrn private class HandlerThread implements Runnable rn private Socket socket;rn public HandlerThread(Socket client) rn socket = client;rn new Thread(this).start();rn rnrn public void run() rn try rn // 读取客户端数据 rn DataInputStream input = new DataInputStream(socket.getInputStream());rn String clientInputStr = input.readUTF();//这里要注意和客户端输出流的写方法对应,否则会抛 EOFExceptionrn // 处理客户端数据 rn System.out.println("客户端发过来的内容:" + clientInputStr);rnrn // 向客户端回复信息 rn DataOutputStream out = new DataOutputStream(socket.getOutputStream());rn System.out.print("请输入:\t");rn // 发送键盘输入的一行 rn String s = new BufferedReader(new InputStreamReader(System.in)).readLine();rn out.writeUTF(s);rnrn out.close();rn input.close();rn catch (Exception e) rn System.out.println("服务器 run 异常: " + e.getMessage());rn finally rn if (socket != null) rn try rn socket.close();rn catch (Exception e) rn socket = null;rn System.out.println("服务端 finally 异常:" + e.getMessage());rn rn rn rn rn rn 论坛

报错但是不能运行

10-08

#includern#includern#define NULL 0rntypedef struct linknodernrn int data;rn struct linknode *next;rnnode;rnnode *p,*q,*s,*head;//定义全部变量rnint j=0,i;rn//主函数rnvoid main()rn rn int x,y,cord;rn node *creat();rn void print(node *head);rn void insert(node *head,int x,int y);rn void search(node *head,int x);rn int length(node *head);rn void deletes(node * head,int x);rn head=creat();rn print(head);rn dorn printf("\n 主菜单 \n");rn printf(" 1 求链表长度 \n");rn printf(" 2 插入一个元素 \n");rn printf(" 3 查找一个元素 \n");rn printf(" 4 删除一个元素 \n");rn printf(" 0 结束程序运行 \n");rn printf("-----------------------------------------\n");rn printf(" 请输入您的选择(1, 2, 3, 4, 0)\n");rn scanf("%d",&cord);rn switch(cord)rn rn case 1:printf("链表长度为j=%d",j=length(head));break;rn case 2:rn rn printf("请输入要插入元素的位置x:");rn scanf("%d",&x);rn printf("请输入插入的数据y:");rn scanf("%d",&y);rn insert(head,x,y);rn print(head);rn break;rn case 3:rn rn printf("请输入要查找的元素x");rn scanf("%d",&x);rn search(head,x);rn break;rn case 4:rn rn printf("删除的数x=?");rn scanf("%d",&x);rn deletes(head,x);rn print(head);rn break;rn case 0:rn rn exit(0);rn break;rn rn while(cord<=4&&cord>=0);rnrn//*函数菜单rnrnrnrn//建立一个单链表!rnnode * creat()rn rn node *head,*p,*s;rn int x;rn head=(node*)malloc(sizeof(node));rn p=head;rn printf("请输入链表数据!\n");rn while(x!=0)rn rn scanf("%d",&x);rn s=(node*)malloc(sizeof(node));rn s->data=x;rn p->next=s;rn p=s;rn rn head=head->next;rn p->next=NULL;rnreturn(head);rnrn//输出链表rnvoid print(node *head)rn rn node *p;rn p=head;rn printf("输出链表!\n");rn if(head==NULL)rn printf("链表为空!");rn elsern rn while(p->next!=NULL)rn rn printf("%d->",p->data);rn p=p->next;rn rn printf("%d",p->data);// 输出链表结束标志!rn rn printf("\n");rnrn//*查找某个结点rnvoid search(node *head,int x)rnrn node *p;rn p=head;rn while(p->data!=x&&p!=NULL)rn p=p->next;rn if(p!=NULL)rn printf("找到了!\n");rn elsern printf("未找到!\n");rnrn//求链表的长度rnint length(node *head)rnrn int n=0;rn node *p;rn p=head;rn while(p!=NULL)rn rn p=p->next;rn n++;rn rn return(n);rnrn//插入某个结点rnvoid insert(node *head,int y)rnrn node *p,*q;rn s=(node*)malloc(sizeof( node));rn s->data=y;rn q=head;p=head->next;rn if(p!=NULL)rn rn q=p;rn p=p->next;rn rn elsern q->next=s;rn s->next=p;rn rnrn//删除结点rnvoid deletes(node * head,int x)rnrn node *p,*q;rn if(head==NULL) printf("链表为空!\n");rn if(head->data==x)rn rn p=head;rn head=head->next;rn free(p);rn rn elsern rn p=head;rn while(p->next!=NULL&&p->next->data!=x) p=p->next;rn if(p==NULL)rn printf(" x 不存在!\n");rn elsern rn q=p->next;rn p->next=q->next;rn free(q);rn rn rnrnrn rnrnrn rnrnrn rnrnrnrnrnrn rn 论坛

没有更多推荐了,返回首页