LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 1414|回复: 8

在Windows下已编译通过的源文件怎么在Linux下编译失败呢?

[复制链接]
发表于 2006-3-7 15:45:23 | 显示全部楼层 |阅读模式
首先我运行Windows下编译出来的.class文件(java Caculate)
终端提示为:
Exception in thread "main" java.lang.NoClassDefFoundError: Caculate$linkList
        at Caculate.main(Caculate.java:20)
然后我把.java文件编译。
终端提示为:
Caculate.java:9: \u9519\u8bef\uff1aUnrecognized character for encoding 'UTF-8'\u3002
   \u01bd            JFrame frame = new JFrame("\u01bd\uffff\uffff\u01ab\uffff\uffff\uffff\uffff\u01bd\uffff\uffff\uffff\uffff\uffff\uffff");
                                               ^
1 error
我把中文都改成了英文后,再编译
终端提示为:
Caculate.java:159: 警告:An empty declaration is a deprecated feature that should not be used。
        };
     ^
Caculate.java:121: 错误:Class ‘Caculate$linkList$5’ doesn't define the abstract method ‘java.lang.Object java.util.Iterator.next()’ from interface ‘java.util.Iterator’. This method must be defined or class ‘Caculate$linkList$5’ must be declared abstract。
                        return new Iterator(){
                           ^
1 error, 1 warning
请各位大虾指点。
我的代码如下:
import javax.swing.*;

import java.util.Iterator;

import java.awt.*;

import java.awt.event.*;

class Caculate{

        private static int numInputted = 0;



        public static void main(String[] args) {

                JFrame frame = new JFrame("平均偏差与平均方差");        //定义界面

                final JLabel label = new JLabel("请输入数据:");

                final JTextField inputLine = new JTextField(1);
                label.setLabelFor(inputLine);

                JPanel pane = new JPanel();        //加入一个JPanel用于加入下四个按键


                JButton addButton = new JButton("添加数据");//加入数据

                JButton button1 = new JButton("求平均偏差");//计算平均偏差

                JButton button2 = new JButton("求平均方差");//计算平均方差

                JButton retButton = new JButton("回零");//打输入清零



                final linkList list = new linkList();//用于装数据的链表



                pane.add(addButton);

                addButton.addActionListener(new ActionListener(){//定义点击addButton的响应

                                public void actionPerformed(ActionEvent ae){

                                        double data = 0;

                                        try{

                                                data = Double.parseDouble(inputLine.getText());

                                        }catch(NumberFormatException e){

                                                label.setText("输入格式不正确,请检查后继续输入:");

                                                throw e;

                                        }finally{

                                                inputLine.setText("");

                                                inputLine.grabFocus();

                                        }

                                        list.add(data);

                                        numInputted ++ ;

                                        label.setText("您已输入" + numInputted + "个数据,请输入数据:");

                                }

                        });

                pane.add(button1);

                button1.addActionListener(new ActionListener(){//定义点击button1的响应

                                public void actionPerformed(ActionEvent ae){

                                        Iterator it = list.iterator();

                                        double average = 0;

                                        double sum = 0;

                                        int amount = 0;

                                        while (it.hasNext()){

                                                sum += ((Double) it.next()).doubleValue();

                                                amount ++ ;

                                        }

                                        if (amount == 0){

                                                inputLine.grabFocus();

                                                return;

                                        }

                                        average = sum / amount;

                                        sum = 0;

                                        it = list.iterator();

                                        while (it.hasNext()){

                                                sum += Math.abs(((Double) it.next()).doubleValue() - average);

                                        }

                                        average = sum / amount;

                                        inputLine.setText(Double.toString(average));

                                        inputLine.grabFocus();

                                }

                        });

                pane.add(button2);

                button2.addActionListener(new ActionListener(){//定义点击button2的响应

                                public void actionPerformed(ActionEvent ae){

                                        Iterator it = list.iterator();

                                        double average = 0;

                                        double sum = 0;

                                        int amount = 0;

                                        while (it.hasNext()){

                                                sum += ((Double) it.next()).doubleValue();

                                                amount ++ ;

                                        }

                                        if (amount == 0){

                                                inputLine.grabFocus();

                                                return;

                                        }

                                        average = sum / amount;

                                        sum = 0;

                                        it = list.iterator();

                                        while (it.hasNext()){

                                                sum += Math.pow(Math.abs(((Double) it.next()).doubleValue() - average),2);

                                        }

                                        average = Math.sqrt(sum / amount);

                                        inputLine.setText(Double.toString(average));

                                        inputLine.grabFocus();

                                }

                        });

                pane.add(retButton);

                retButton.addActionListener(new ActionListener(){//定义点击retButton的响应

                                public void actionPerformed(ActionEvent ae){

                                        list.dispose();

                                        label.setText("请输入数据:");

                                        numInputted = 0;

                                        inputLine.setText("");

                                        inputLine.grabFocus();

                                }

                        });



                frame.getContentPane().add(pane,java.awt.BorderLayout.SOUTH);//加入各组件

                frame.getContentPane().add(label,java.awt.BorderLayout.NORTH);

                frame.getContentPane().add(inputLine,java.awt.BorderLayout.CENTER);

                frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

                frame.pack();

                frame.setVisible(true);

        }



        public static class linkList{ //定义链表类

                private class linkListStructure{//链表结构类

                        private double element;

                        private linkListStructure next;

                }



                linkListStructure head = null;

                linkListStructure current = null;



                public Iterator iterator(){ //返回一个迭代器

                        return new Iterator(){//返回一个实现了Iterator接口的匿名类

                                private linkListStructure current = head;

                                private linkListStructure pre = null;

                                public boolean hasNext(){

                                        if (current == null)

                                        {

                                                return false;

                                        }

                                        return true;

                                }       



                                public Double next(){

                                        pre = current;

                                        current = current.next;

                                        return pre.element;

                                }



                                public void remove(){

                                        pre.next = current.next;

                                }

                        };

                }



                public void add(double data){//添加链表元素

                        linkListStructure temp;

                        temp = new linkListStructure();

                        if(head == null)

                                head = temp;

                        else

                                current.next = temp;

                        current = temp;

                        current.element = data;

                }

               

                public void dispose(){//清空链表

                        head = null;

                        current = null;

                }

        };

}
发表于 2006-3-7 16:18:09 | 显示全部楼层
不是提示了吗?Caculate.java:159: 警告:An empty declaration is a deprecated feature that should not be used。
};
你把分号去掉。
而且class Caculate必须是public!如果你能在Windows下运行,那就是你见鬼了!

楼主的错误都是语法错误,请看看书。
回复 支持 反对

使用道具 举报

 楼主| 发表于 2006-3-7 18:09:24 | 显示全部楼层
我在Windows下的确是可以编译成功的,同时也是可以运行的.
至于那个";"是一下警告不是错误.是由于我在Windows一用EditPlus编写时,程序自动生成的,由于可以编译我就没有管他了.
哪为什么,会出现
Caculate.java:9: \u9519\u8bef\uff1aUnrecognized character for encoding 'UTF-8'\u3002
\u01bd JFrame frame = new JFrame("\u01bd\uffff\uffff\u01ab\uffff\uffff\uffff\uffff\u01bd\uffff\uffff\uffff\uffff\uffff\uffff");
^
1 error
这样的错误呢.
还有就是可以让Interator接口的next()方法反回double而不是一个对象吗?
在Windows下我可以让它返回Double对象,不过在Linux下编译时却说找不到Double的标认符.
请各位再指点.或者推荐一些有关的文章或或书来看一下.
在这多谢ideawu兄弟的的帖子.不过希望可以说得详细一点.
回复 支持 反对

使用道具 举报

发表于 2006-3-7 19:57:01 | 显示全部楼层
不好意思楼主。我第一次编译的时候确实是那两个错误。现在你的代码我完全能编译和运行,我感到奇怪。环境:
Debian amd64
java version "1.5.0_06"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_06-b05)
Java HotSpot(TM) 64-Bit Server VM (build 1.5.0_06-b05, mixed mode)

可能你的文件包含了Windows下能识别的但是Linux不能识别的字符。你用gedit打开原来的文件,然后复制所有文字到另一个文件保存试试。
回复 支持 反对

使用道具 举报

发表于 2006-3-7 20:38:01 | 显示全部楼层
可以编译并运行 ,我的环境是 FREEBSD 6.0  jdk-1.5.0p2_6
回复 支持 反对

使用道具 举报

发表于 2006-3-7 20:38:03 | 显示全部楼层
可以编译并运行 ,我的环境是 FREEBSD 6.0  jdk-1.5.0p2_6
回复 支持 反对

使用道具 举报

 楼主| 发表于 2006-3-7 21:07:56 | 显示全部楼层
在我机子上还是不能编译,我的环境是ubuntu, jdk-1.4.2
编译器提示,迭代器的next()方法,返回值不匹配,还有就是不能把double转化为Double.
我试过把返回值改为Double(pre.element),同时把返回值改为Object.
不过出现了没有Double(double)未定义,我已经import java.lang.*;了。
不知道是不是我的环境有问题呢。你们的都是没有修改就编译成功了吗?
回复 支持 反对

使用道具 举报

发表于 2006-3-8 21:33:20 | 显示全部楼层
编码问题, 把文件的编码转换为 utf8 在编译试试。
回复 支持 反对

使用道具 举报

 楼主| 发表于 2006-3-9 09:42:57 | 显示全部楼层
终于找到了编译不通过的原因了,原来是因为我在Windows下用的是jdk1.5而在Linux下是用jdk1.4.现在装了1.5就可以编译通过,运行也成功了。不过中文还是乱码,我的编码方式已经是utf8了。
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表