Hello,
I am running Parabola Gnu/linux with the 3.10 lts kernel (later kernels still have problems with the graphical part, so...)
I'm beginning to learn java and have some really easy code, that gives me a long list of errors at runtime. Also a fair bit of warnings in the code itself, but always the same: " The serializable class Oef0310 does not declare a static final serialVerionUID field of type long"
I've had this problmen since I've started doing these exercices, they don't give any problem.
When running code on Ubuntu & Eclipse Indigo, I get no error at all. I checked the Arch wiki page and found this: https://wiki.archlinux.org/index.php...font_rendering
But I don't understand what they mean by options. So here's my code:
import javax.swing.*; import java.awt.*; import java.awt.event.*; public class Oef0310 extends JFrame { public static void main(String args[]) { JFrame frame = new Oef0310(); frame.setSize(600, 300); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setTitle("Oef 3.10"); frame.setContentPane(new Optelpaneel0310()); frame.setVisible(true); } } // second class import javax.swing.*; import java.awt.*; import java.awt.event.*; public class Optelpaneel0310 extends JPanel { private JTextField invoervak1, invoervak2, optelVak, maalVak; private JButton plusKnop, maalKnop; public Optelpaneel0310() { invoervak1 = new JTextField(10); invoervak2 = new JTextField(10); optelVak = new JTextField(10); maalVak = new JTextField(10); plusKnop = new JButton(" + "); plusKnop.addActionListener(new PlusKnopHandler() ); maalKnop = new JButton(" * "); maalKnop.addActionListener(new MaalKnopHandler() ); add(invoervak1); add(invoervak2); add(plusKnop); add(maalKnop); add(optelVak); add(maalVak); } class PlusKnopHandler implements ActionListener { public void actionPerformed(ActionEvent e) { String invoerstring1 = invoervak1.getText(); int getal1 = Integer.parseInt(invoerstring1); String invoerstring2 = invoervak2.getText(); int getal2 = Integer.parseInt(invoerstring2); int resultaat = getal1 + getal2; optelVak.setText("" + resultaat ); } } class MaalKnopHandler implements ActionListener { public void actionPerformed(ActionEvent e) { String invoerstring1 = invoervak1.getText(); int getal1 = Integer.parseInt(invoerstring1); String invoerstring2 = invoervak2.getText(); int getal2 = Integer.parseInt(invoerstring2); int resultaat = getal1 * getal2; maalVak.setText("" + resultaat); } } }
And here are the errors
Exception in thread "main" java.lang.NullPointerException
at sun.awt.X11FontManager.getDefaultPlatformFont(X11F ontManager.java:779)
at sun.font.SunFontManager$2.run(SunFontManager.java: 432)
at java.security.AccessController.doPrivileged(Native Method)
at sun.font.SunFontManager.<init>(SunFontManager.java :375)
at sun.awt.X11FontManager.<init>(X11FontManager.java: 32)
at sun.reflect.NativeConstructorAccessorImpl.newInsta nce0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInsta nce(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newI nstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Construc tor.java:526)
at java.lang.Class.newInstance(Class.java:374)
at sun.font.FontManagerFactory$1.run(FontManagerFacto ry.java:83)
at java.security.AccessController.doPrivileged(Native Method)
at sun.font.FontManagerFactory.getInstance(FontManage rFactory.java:74)
at sun.font.SunFontManager.getInstance(SunFontManager .java:249)
at sun.font.FontDesignMetrics.getMetrics(FontDesignMe trics.java:264)
at sun.swing.SwingUtilities2.getFontMetrics(SwingUtil ities2.java:1003)
at javax.swing.JComponent.getFontMetrics(JComponent.j ava:1615)
at javax.swing.text.PlainView.calculateLongestLine(Pl ainView.java:639)
at javax.swing.text.PlainView.updateMetrics(PlainView .java:209)
at javax.swing.text.PlainView.setSize(PlainView.java: 490)
at javax.swing.plaf.basic.BasicTextUI$RootView.setSiz e(BasicTextUI.java:1714)
at javax.swing.plaf.basic.BasicTextUI.getPreferredSiz e(BasicTextUI.java:917)
at javax.swing.JComponent.getPreferredSize(JComponent .java:1651)
at javax.swing.JTextField.getPreferredSize(JTextField .java:424)
at java.awt.FlowLayout.layoutContainer(FlowLayout.jav a:609)
at java.awt.Container.layout(Container.java:1503)
at java.awt.Container.doLayout(Container.java:1492)
at java.awt.Container.validateTree(Container.java:168 8)
at java.awt.Container.validateTree(Container.java:169 7)
at java.awt.Container.validateTree(Container.java:169 7)
at java.awt.Container.validateTree(Container.java:169 7)
at java.awt.Container.validate(Container.java:1623)
at java.awt.Container.validateUnconditionally(Contain er.java:1660)
at java.awt.Window.show(Window.java:1033)
at java.awt.Component.show(Component.java:1651)
at java.awt.Component.setVisible(Component.java:1603)
at java.awt.Window.setVisible(Window.java:1014)
at Oef0310.main(Oef0310.java:15)
Also, I had other code compile and run without a problem on that machine, eg
import javax.swing.*;
import java.awt.*;
public class Tekenpaneel0306 extends JPanel { public Tekenpaneel0306() { setBackground(Color.WHITE); } public void paintComponent(Graphics g) { g.setColor(Color.BLACK); g.fillRect(0, 0, 50, 50); g.fillRect(100, 100, 50, 50); g.fillRect(100, 0, 50, 50); g.fillRect(50, 50, 50, 50); g.fillRect(0, 100, 50, 50); g.setColor(Color.WHITE); g.fillRect(50, 0, 50, 50); g.fillRect(0, 50, 50, 50); g.fillRect(100, 50, 50, 50); g.fillRect(50, 100, 50, 50); } }
What couldpossibly be wrong ? Someone told me something about fonts, but... Buh.
I appreciate any help.