已有259人关注
Java入门到精通 第4版 23章 23.7 问题 case 2: default: 参数异常 找不到文件??什么情况???着急...
发表在Java答疑区 2017-01-02
是否精华
版块置顶:

文件已在 src下面  为什么说File 异常啊???无解啊

blob.png

分享到:
精彩评论 8
麦_1482810758
学分:24 LV2
2017-01-02
沙发

isSupported 也支持该动作了啊  为什么找不到

blob.png

David
学分:914 LV7
TA的每日心情
最后的冲刺
2017-07-15 10:46:08
2017-01-03
板凳

请读者确认是“第4版 23章 例23.7”,经测试,例23.7将源码导入eclipse后运行正常。而且源码中没有default代码块。

麦_1482810758
学分:24 LV2
2017-01-03
地板

23章  桌面集成控件 那个案例 在光盘的23.13里面

David
学分:914 LV7
TA的每日心情
最后的冲刺
2017-07-15 10:46:08
2017-01-03
4L

源码没有问题,估计问题还是出现在项目结构上,请读者把自己的eclipse打开,将自己的项目结构截取图片并上传。

麦_1482810758
学分:24 LV2
2017-01-03
5L


import java.awt.BorderLayout;

import java.awt.Desktop;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import java.io.File;

import java.net.URI;


import javax.swing.JButton;

import javax.swing.JFrame;

import javax.swing.JPanel;


public class ExampleFrame_13 extends JFrame {


/**

*/

private static final long serialVersionUID = 1L;

public static void main(String[] args) {

ExampleFrame_13 frame = new ExampleFrame_13();

frame.setVisible(true);

}

public ExampleFrame_13() {

super();

setTitle("使用桌面集成控件");

setBounds(100, 100,  500, 375);

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

final JPanel panel = new JPanel();

getContentPane().add(panel, BorderLayout.NORTH);

final JButton dickButton = new JButton();

dickButton.setText("打开编程词典网");

dickButton.addActionListener(new ButtonListener(1));

panel.add(dickButton);

final JButton noteButton = new JButton();

noteButton.setText("打开记事本");

noteButton.addActionListener(new ButtonListener(2));

panel.add(noteButton);

final JButton docButton = new JButton();

docButton.setText("打开word文档");

docButton.addActionListener(new ButtonListener(0));

panel.add(docButton);

}

private class ButtonListener implements ActionListener {

int index;

public ButtonListener(int index) {

this.index = index;

}

public void actionPerformed(ActionEvent e) {

try{

if (Desktop.isDesktopSupported()) {

Desktop desktop = Desktop.getDesktop();

switch (index) {

case 1:

if (desktop.isSupported(Desktop.Action.BROWSE)) {

desktop.browse(new URI(

"http://www.mrbccd.com"));

break;

}

case 2:

if (desktop.isSupported(Desktop.Action.EDIT)) {

desktop.edit(new File("src/new.txt"));

break;

}

default:

if (desktop.isSupported(Desktop.Action.OPEN)) {

desktop.open(new File("src/new.doc"));

}

}

}

}catch(Exception e1){

e1.printStackTrace();

}

}

}

}


David
学分:914 LV7
TA的每日心情
最后的冲刺
2017-07-15 10:46:08
2017-01-03
6L

你好读者!这个是代码,我要的是项目结构的图片。eclipse的左侧部分,注意要把src文件夹完全展开后,再截图。

麦_1482810758
学分:24 LV2
David
学分:914 LV7
TA的每日心情
最后的冲刺
2017-07-15 10:46:08
2017-01-03
8L

src/test/java这样的写法是不规范的,正确的写法是

1.png

因为源码中的文件路径为"src/new.doc",其含义是在src文件夹下的new.doc文件。而读者的项目结构中用了不规范的写法,即“src/test/java”;且又有一个名为test2的包,这样,根据"src/new.doc"这个路径是无法找到new.doc文件。所以控制台就会输出报错信息。

首页上一页 1 下一页尾页 8 条记录 1/1页
手机同步功能介绍
友情提示:以下图书配套资源能够实现手机同步功能
明日微信公众号
明日之星 明日之星编程特训营
客服热线(每日9:00-17:00)
400 675 1066
mingrisoft@mingrisoft.com
吉林省明日科技有限公司Copyright ©2007-2022,mingrisoft.com, All Rights Reserved长春市北湖科技开发区盛北大街3333号长春北湖科技园项目一期A10号楼四、五层
吉ICP备10002740号-2吉公网安备22010202000132经营性网站备案信息 营业执照