Results 1 to 8 of 8
  1. #1
    Sudde-J is offline Member
    Join Date
    Apr 2009
    Posts
    5
    Rep Power
    0

    Thumbs down Exception in thread "main" java.lang.NullPointerException

    Hi,
    I installed jdk1.6.0_13 and Eclipse Release 3.4.2 this morning. But when I tried to run my first program I got error
    "Exception in thread "main" java.lang.NullPointerException".
    I run actually the same program on my laptop without any problem.
    Do you have any idea?
    Thanks in advance.
    Suude-j

  2. #2
    PhHein's Avatar
    PhHein is offline Senior Member
    Join Date
    Apr 2009
    Location
    Germany
    Posts
    1,430
    Rep Power
    7

    Default

    No idea. Post your code.

  3. #3
    Sudde-J is offline Member
    Join Date
    Apr 2009
    Posts
    5
    Rep Power
    0

    Thumbs up "Exception in thread "main" java.lang.NullPointerException".

    Hi,
    I installed jdk1.6.0_13 and Eclipse Release 3.4.2 this morning. But when I tried to run my first program I got error
    "Exception in thread "main" java.lang.NullPointerException".
    I run actually the same program on my laptop without any problem.
    Do you have any idea?
    Thanks in advance.
    Suude-j

    Sorry, I forgot enclosed codes:


    import java.awt.BorderLayout;
    import java.awt.Dimension;
    import java.awt.GridLayout;
    import javax.swing.JButton;
    import javax.swing.JRadioButton;
    import javax.swing.ButtonGroup;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    import javax.swing.JTextField;
    import javax.swing.JComponent;
    import javax.swing.text.AttributeSet;
    import javax.swing.text.BadLocationException;
    import javax.swing.text.Document;
    import javax.swing.text.PlainDocument;
    import java.text.DecimalFormat;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.awt.event.KeyListener;
    import java.awt.event.WindowAdapter;
    import java.awt.event.WindowEvent;
    import java.awt.event.KeyEvent;
    import java.lang.Math;
    import java.awt.Toolkit;
    import java.awt.Image;

    class DoubleTextDocument extends PlainDocument
    { public void insertString(int offs, String str,
    AttributeSet a)
    throws BadLocationException
    { if (str == null) return;
    String oldString = getText(0, getLength());
    String newString = oldString.substring(0, offs)
    + str + oldString.substring(offs);
    try
    {
    if (Double.parseDouble(newString ) < 100) {
    int i = newString.lastIndexOf(".");
    int j = newString.lastIndexOf(",");
    int l = newString.length();
    if (( i < 0 || l <= i+2 )||(j < 0 || l <= j+2))
    super.insertString(offs, str, a);
    }

    }
    catch(NumberFormatException e)
    {
    }
    }
    }

    class DoubleTextField extends JTextField
    { public DoubleTextField( int size)
    { super("", size);
    }

    protected Document createDefaultModel()
    { return new DoubleTextDocument();
    }

    public boolean isValid()
    { try
    { Integer.parseInt(getText());
    return true;
    }
    catch(NumberFormatException e)
    { return false;
    }
    }

    public double getValue()
    { try
    {
    if (getText() == "") return 0;
    return Double.parseDouble(getText());
    }
    catch(NumberFormatException e)
    { return 0;
    }
    }
    }
    public class test implements ActionListener {

    private JFrame frame;
    private JLabel tablForm;
    private JRadioButton tablFormC;
    private JRadioButton tablFormFR;
    private JRadioButton tablFormR;
    private JRadioButton tablFormFF;
    private JLabel maxTjocklek;
    private JLabel maxBredd;
    private JLabel maxLängd;




    private DoubleTextField maxTjocklekField;

    private DoubleTextField maxBreddField;
    private DoubleTextField maxLängdField;
    private JTextField kodField;

    private JButton kodButton;


    public static void main(String[] args) {
    test mgr = new test();
    }

    public test(){

    frame = new JFrame();
    frame.setTitle("Kassett Kods Förslag");
    frame.setLayout(new BorderLayout());
    frame.setVisible(true);



    //Border
    BorderLayout layout = new BorderLayout(10,10);
    frame.setLayout(layout);


    //North Panel
    JPanel northPanel = new JPanel();
    northPanel.setLayout(new GridLayout(5,1));

    tablForm = new JLabel("Tabletts Form:");
    tablFormC = new JRadioButton("C", false);
    tablFormFR = new JRadioButton("FR", true);

    tablFormR = new JRadioButton("R", false);
    tablFormFF = new JRadioButton("FF", false);
    ButtonGroup bGroup = new ButtonGroup();

    bGroup.add(tablFormC);
    bGroup.add(tablFormFR);
    bGroup.add(tablFormR);
    bGroup.add(tablFormFF);
    northPanel.add(tablForm);
    northPanel.add(tablFormFR);
    northPanel.add(tablFormR);
    northPanel.add(tablFormFF);
    northPanel.add(tablFormC);

    tablFormFR.addActionListener(this);
    // tablFormFR.addKeyListener(this);
    tablFormR.addActionListener(this);
    // tablFormR.addKeyListener(this);
    tablFormFF.addActionListener(this);
    // tablFormFF.addKeyListener(this);
    tablFormC.addActionListener(this);
    // tablFormC.addKeyListener(this);
    //West Panel
    JPanel westPanel = new JPanel();
    westPanel.setLayout(new GridLayout(3,2));


    maxTjocklek = new JLabel("MaxTjocklek");
    maxTjocklekField = new DoubleTextField(3);

    maxBredd = new JLabel("MaxBredd");
    maxBreddField = new DoubleTextField (3);

    maxLängd = new JLabel("MaxLängd");
    maxLängdField = new DoubleTextField (3);

    maxLängdField.disable();

    westPanel.add(maxTjocklek);
    westPanel.add(maxTjocklekField);
    westPanel.add(maxBredd);
    westPanel.add(maxBreddField);
    westPanel.add(maxLängd);
    westPanel.add(maxLängdField);


    //South Panel
    JPanel southPanel = new JPanel();
    southPanel.setLayout(new GridLayout(1,2));
    kodButton = new JButton("Kod");

    kodField = new JTextField (13);

    southPanel.add(kodButton);

    southPanel.add(kodField);
    kodButton.addActionListener(this);




    //Frame
    frame.add(northPanel, BorderLayout.NORTH);
    frame.add(westPanel, BorderLayout.WEST);
    frame.add(southPanel, BorderLayout.SOUTH);

    frame.pack();

    Toolkit tk = Toolkit.getDefaultToolkit();
    Dimension d = tk.getScreenSize();
    int screenHeith = d.height;
    int screenWidth = d.width;
    frame.setSize(screenWidth / 3, screenHeith / 3);
    frame.setLocation(screenWidth / 5, screenHeith / 5);
    Image img = tk.getImage("icon.gif");
    frame.setIconImage(img);

    }
    public void KeyListener(KeyEvent e) {
    int key = e.getKeyCode();
    if (key == KeyEvent.VK_ENTER) {
    e.setKeyCode(KeyEvent.VK_TAB);

    }
    }
    public void KeyPressed(KeyEvent e){}
    public void KeyReleased(KeyEvent e) {}
    public void KeyTyped(KeyEvent e) {}


    public void actionPerformed(ActionEvent e) {
    Object source = e.getSource();

    if (tablFormFR.isSelected() || tablFormR.isSelected() || tablFormFF.isSelected()) {
    maxLängdFieldDisable();

    }
    else{
    maxBreddFieldDisable();
    }

    if (source == kodButton) {

    codeSearching();
    }
    }

    private void maxLängdFieldDisable(){
    maxLängdField.setText("");
    maxLängdField.disable();
    maxBreddField.enable();
    maxTjocklek.setNextFocusableComponent(maxBreddFiel d);
    }
    private void maxBreddFieldDisable(){
    maxBreddField.setText("");
    maxBreddField.disable();
    maxLängdField.enable();
    maxTjocklek.setNextFocusableComponent(maxLängdFiel d);
    }

    private void codeSearching(){



    if(tablFormC.isSelected()){
    double tjocklek = maxTjocklekField.getValue();
    double lengd = maxLängdField.getValue();
    if( (tjocklek > 3.9 && tjocklek < 5.0) && (lengd > 10.9 && lengd < 12.1)){
    kodField.setText("O5 4B80");
    }
    else if( (tjocklek > 4.9 && tjocklek < 5.6) && (lengd > 12.9 && lengd < 15.4)){
    kodField.setText("Q4 6B90");
    }
    else if( (tjocklek > 5.4 && tjocklek < 6.1) && (lengd > 15.4 && lengd < 16.2)){
    kodField.setText("R3 6B100");
    }
    else if( (tjocklek > 5.2 && tjocklek < 6.1) && (lengd > 15.2 && lengd < 17.0)){
    kodField.setText("S3 7B100");
    }
    else if( (tjocklek > 5.9 && tjocklek < 6.6) && (lengd > 16.9 && lengd < 18.0)){
    kodField.setText("T2 7B110");
    }
    else if( (tjocklek > 6.4 && tjocklek < 7.1) && (lengd > 17.9 && lengd < 20.0)){
    kodField.setText("W1 8C110");
    }
    else if( (tjocklek > 6.4 && tjocklek < 7.1) && (lengd > 19.9 && lengd < 21.0)){
    kodField.setText("X1 9C110");
    }
    else if( (tjocklek > 7.4 && tjocklek < 8.1) && (lengd > 20.9 && lengd < 22.1)){
    kodField.setText("Z0 9D120");
    }
    else if( (tjocklek > 7.4 && tjocklek < 8.1) && (lengd > 20.9 && lengd < 23.5)){
    kodField.setText("Z0 9C120");
    }
    else {
    kodField.setText("Finns ej!");
    }

    }
    else {
    double tjocklek = maxTjocklekField.getValue();
    double bredd = maxBreddField.getValue();
    if (tjocklek < 1.8 || tjocklek > 8.3 || bredd < 5.1 || bredd > 14.1) {
    kodField.setText("Finns Ej!");
    return;
    }
    int n = 0;
    int m = 0;
    m = Math.min(Math.max(((int) Math.ceil(((bredd - 5.1) * 2 ))) +1,1),19);

    if(tablFormFR.isSelected()){
    n = Math.min(Math.max(((int) Math.ceil(((tjocklek - 2) * 4))) +1,1),26);

    }
    else if(tablFormR.isSelected()) {
    n = Math.min(Math.max(((int) Math.ceil(((tjocklek - 1.8) * 4))) +1,1),26);
    }
    /* else{
    if ()
    }*/
    // A = 64
    char hjulbokstav = (char) (n+64);
    int hjulnr = 55 + m*5;

    int fonster;
    if (m < 3) { fonster = 1;}
    else if (m > 2 && m < 7) { fonster = 2;}
    else if (m > 6 && m < 11) { fonster = 3;}
    else if (m > 10 && m < 15){fonster = 4;}
    else { fonster = 5;}

    //else { fonster = ((int) (m-2) /4) + 2;}

    char fordelare;
    if (n < 6) { fordelare = 'A';}
    else if (n < 13) { fordelare = 'B';}
    else if (n < 21) { fordelare = 'C';}
    else { fordelare = 'D';}

    int pip = ((int) ((double) m -1)/2) * 10 + 75;
    if ( pip > 145) { pip = 155;}

    String result;
    result = String.format("%s%d %d%s%d S", hjulbokstav, hjulnr, fonster, fordelare, pip);
    if (result.equals("G60 1B75 S")){result = "H60 1B75 S";}
    else if (result.equals("Q145 5C155 S")){result = "R145 5C155 S";}
    else if (result.equals("U125 4D135 S")){result = "V125 4D135 S";}
    else if ((n==1 && m>5)||(n==2 && m>6)||(n==3 && m>7)||(n==4 && m>7)||
    (n==5 && m>9)||(n==6 && m>9)||(n==7 && m>11)||(n==8 && m>14)||
    (n==9 && m>15)||(n==10 && m>15)||(n==11 && m>15)
    ||(n==9 && m<2)||(n==10 && m<3)||(n==11 && m<3)||(n==12 && m<5)
    ||(n==13 && m<5)||(n==14 && m<5)||(n==15 && m<6)||(n==16 && m<7)
    ||(n==17 && m<7)||(n==18 && m<7)||(n==19 && m<7)||(n==20 && m<7)
    ||(n==21 && m<7)||(n==22 && m<12)||(n==23 && m<12)||(n==24 && m<12)
    ||(n==25 && m<12)||(n==26 && m<12))
    {result="Finns Ej!";}
    kodField.setText(result);}
    }

    }

  4. #4
    PhHein's Avatar
    PhHein is offline Senior Member
    Join Date
    Apr 2009
    Location
    Germany
    Posts
    1,430
    Rep Power
    7

    Default

    ok, now please post the exact stack trace.

  5. #5
    Sudde-J is offline Member
    Join Date
    Apr 2009
    Posts
    5
    Rep Power
    0

    Default

    sorry, I am new java user.
    Here you are!
    Exception in thread "main" java.lang.NullPointerException
    at javax.swing.text.JTextComponent.getText(Unknown Source)
    at DoubleTextField.isValid(test.java:64)
    at java.awt.Component.invalidateIfValid(Unknown Source)
    at java.awt.Component.setLocale(Unknown Source)

  6. #6
    Sudde-J is offline Member
    Join Date
    Apr 2009
    Posts
    5
    Rep Power
    0

    Default

    Hi again,
    This is what I got last time I run:
    Exception in thread "main" java.lang.NullPointerException
    at javax.swing.text.JTextComponent.getText(Unknown Source)
    at DoubleTextField.isValid(test.java:64)
    at java.awt.Component.invalidateIfValid(Unknown Source)
    at java.awt.Component.setLocale(Unknown Source)
    at javax.swing.JComponent.<init>(Unknown Source)
    at javax.swing.text.JTextComponent.<init>(Unknown Source)
    at javax.swing.JTextField.<init>(Unknown Source)
    at javax.swing.JTextField.<init>(Unknown Source)
    at DoubleTextField.<init>(test.java:55)
    at test.<init>(test.java:161)
    at test.main(test.java:108)

  7. #7
    Sudde-J is offline Member
    Join Date
    Apr 2009
    Posts
    5
    Rep Power
    0

    Question Exception in thread "main" java.lang.NullPointerException

    Hi,
    I installed jdk1.6.0_13 and Eclipse Release 3.4.2 last week. when I tried to run my first program I got error
    "Exception in thread "main" java.lang.NullPointerException".
    I run actually the same program on my laptop without any problem.

    Do you have any idea?

    Thanks in advance.
    Sudde-j
    ************************************************** ********
    The exception is:
    Exception in thread "main" java.lang.NullPointerException
    at javax.swing.text.JTextComponent.getText(Unknown Source)
    at DoubleTextField.isValid(minClass.java:73)
    at java.awt.Component.invalidateIfValid(Unknown Source)
    at java.awt.Component.setLocale(Unknown Source)
    at javax.swing.JComponent.<init>(Unknown Source)
    at javax.swing.text.JTextComponent.<init>(Unknown Source)
    at javax.swing.JTextField.<init>(Unknown Source)
    at javax.swing.JTextField.<init>(Unknown Source)
    at DoubleTextField.<init>(minClass.java:61)
    at minClass.<init>(minClass.java:145)
    at minClass.main(minClass.java:109)

    ************************************************** ********
    My code is:


    import java.awt.BorderLayout;
    import java.awt.Dimension;
    import java.awt.GridLayout;
    import javax.swing.JButton;
    import javax.swing.JRadioButton;
    import javax.swing.ButtonGroup;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    import javax.swing.JTextField;
    import javax.swing.JComponent;
    import javax.swing.text.AttributeSet;
    import javax.swing.text.BadLocationException;
    import javax.swing.text.Document;
    import javax.swing.text.PlainDocument;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.awt.event.KeyEvent;
    import java.awt.event.KeyAdapter;
    import java.lang.Math;
    import java.awt.Toolkit;
    import java.awt.Image;
    import javax.swing.KeyStroke;

    class DoubleTextDocument extends PlainDocument
    { public void insertString(int offs, String str,
    AttributeSet a)
    throws BadLocationException
    { if (str == null) return;

    String oldString = getText(0, getLength());
    String newString = oldString.substring(0, offs)
    + str + oldString.substring(offs);
    try
    {
    if(str.equals(",")){
    String s = newString;
    s = newString.substring(0,newString.length()-1) + ".";
    newString = s;
    }
    if (Double.parseDouble(newString ) < 100) {
    int i = newString.lastIndexOf(".");
    int j = newString.lastIndexOf(",");
    int l = newString.length();

    if (( i < 0 || l <= i+2 || j < 0 || l <= j+2)){
    if(str.equals(",")){super.insertString(offs, ".", a);}
    else
    super.insertString(offs, str, a);
    }
    }
    }
    catch(NumberFormatException e)
    {
    }
    }
    }
    class DoubleTextField extends JTextField
    { public DoubleTextField( int size)
    { super("", size); // at DoubleTextField.<init>(minClass.java:61)
    addKeyListener(new KeyAdapter() {
    public void keyPressed(KeyEvent evt) {
    int key = evt.getKeyCode();
    if (key == KeyEvent.VK_ENTER)
    transferFocus();}});
    }
    protected Document createDefaultModel()
    { return new DoubleTextDocument();
    }
    public boolean isValid()
    { try
    { Integer.parseInt(getText()); // at DoubleTextField.isValid(minClass.java:73)
    return true;
    }
    catch(NumberFormatException e)
    { return false;
    }
    }
    public double getValue()
    { try
    {
    if (getText() == "") return 0;
    return Double.parseDouble(getText());
    }
    catch(NumberFormatException e)
    { return 0;
    }
    }
    }
    public class minClass implements ActionListener
    {
    private JFrame frame;
    private JLabel tablForm;
    private JRadioButton tablFormC;
    private JRadioButton tablFormFR;
    private JRadioButton tablFormR;
    private JRadioButton tablFormFF;
    private JLabel maxTjocklek;
    private JLabel maxBredd;
    private JLabel maxLängd;
    private DoubleTextField maxTjocklekField;
    private DoubleTextField maxBreddField;
    private DoubleTextField maxLängdField;
    private JTextField kodField;
    private JButton kodButton;

    public static void main(String[] args) {
    minClass mgr = new minClass(); // at minClass.main(minClass.java:109)
    }
    public minClass() {
    frame = new JFrame();
    frame.setTitle("Kassett Kods Förslag");
    frame.setLayout(new BorderLayout());
    frame.setVisible(true);
    //Border
    BorderLayout layout = new BorderLayout(10,10);
    frame.setLayout(layout);
    //North Panel
    JPanel northPanel = new JPanel();
    northPanel.setLayout(new GridLayout(5,1));
    tablForm = new JLabel("Tabletts Form:");
    tablFormC = new JRadioButton("C", false);
    tablFormFR = new JRadioButton("FR", true);
    tablFormR = new JRadioButton("R", false);
    tablFormFF = new JRadioButton("FF", false);
    ButtonGroup bGroup = new ButtonGroup();
    bGroup.add(tablFormC);
    bGroup.add(tablFormFR);
    bGroup.add(tablFormR);
    bGroup.add(tablFormFF);
    northPanel.add(tablForm);
    northPanel.add(tablFormFR);
    northPanel.add(tablFormR);
    northPanel.add(tablFormFF);
    northPanel.add(tablFormC);
    tablFormFR.addActionListener(this);
    tablFormR.addActionListener(this);
    tablFormFF.addActionListener(this);
    tablFormC.addActionListener(this);
    //West Panel
    JPanel westPanel = new JPanel();
    westPanel.setLayout(new GridLayout(3,2));
    maxTjocklek = new JLabel("MaxTjocklek");
    maxTjocklekField = new DoubleTextField(3); // at minClass.<init>(minClass.java:145)
    maxBredd = new JLabel("MaxBredd");
    maxBreddField = new DoubleTextField (3);
    maxLängd = new JLabel("MaxLängd");
    maxLängdField = new DoubleTextField (3);
    maxLängdField.disable();
    westPanel.add(maxTjocklek);
    westPanel.add(maxTjocklekField);
    westPanel.add(maxBredd);
    westPanel.add(maxBreddField);
    westPanel.add(maxLängd);
    westPanel.add(maxLängdField);
    //South Panel
    JPanel southPanel = new JPanel();
    southPanel.setLayout(new GridLayout(1,2));
    kodButton = new JButton("Kod");
    kodField = new JTextField (13);
    southPanel.add(kodButton);
    southPanel.add(kodField);
    kodButton.addActionListener(this);
    enterPressesWhenFocused(kodButton);
    //Frame
    frame.add(northPanel, BorderLayout.NORTH);
    frame.add(westPanel, BorderLayout.WEST);
    frame.add(southPanel, BorderLayout.SOUTH);
    frame.pack();
    Toolkit tk = Toolkit.getDefaultToolkit();
    Dimension d = tk.getScreenSize();
    int screenHeith = d.height;
    int screenWidth = d.width;
    frame.setSize(screenWidth / 3, screenHeith / 3);
    frame.setLocation(screenWidth / 5, screenHeith / 5);
    Image img = tk.getImage("icon.gif");
    frame.setIconImage(img);
    }
    public static void enterPressesWhenFocused(JButton button)
    {

    button.registerKeyboardAction(
    button.getActionForKeyStroke(
    KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, 0, false)),
    KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0, false),
    JComponent.WHEN_FOCUSED);

    button.registerKeyboardAction(
    button.getActionForKeyStroke(
    KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, 0, true)),
    KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0, true),
    JComponent.WHEN_FOCUSED);

    }
    public void actionPerformed(ActionEvent e)
    {
    Object source = e.getSource();
    maxTjocklekField.requestFocus();
    if (tablFormFR.isSelected() || tablFormR.isSelected() || tablFormFF.isSelected())
    {
    maxLängdFieldDisable();
    }
    else
    {
    maxBreddFieldDisable();
    }
    if (source == kodButton)
    {
    codeSearching();
    }
    }
    private void maxLängdFieldDisable()
    {
    maxLängdField.setText("");
    maxLängdField.disable();
    maxBreddField.enable();
    maxTjocklek.setNextFocusableComponent(maxBreddFiel d);
    }
    private void maxBreddFieldDisable()
    {
    maxBreddField.setText("");
    maxBreddField.disable();
    maxLängdField.enable();
    maxTjocklek.setNextFocusableComponent(maxLängdFiel d);
    }
    private void codeSearching()
    {
    if(tablFormC.isSelected())
    {
    double tjocklek = maxTjocklekField.getValue();
    double lengd = maxLängdField.getValue();
    if( (tjocklek > 3.9 && tjocklek < 5.0) && (lengd > 10.9 && lengd < 12.1))
    {
    kodField.setText("O5 4B80");
    }
    else if( (tjocklek > 4.9 && tjocklek < 5.6) && (lengd > 12.9 && lengd < 15.4))
    {
    kodField.setText("Q4 6B90");
    }
    else if( (tjocklek > 5.4 && tjocklek < 6.1) && (lengd > 15.4 && lengd < 16.2))
    {
    kodField.setText("R3 6B100");
    }
    else if( (tjocklek > 5.2 && tjocklek < 6.1) && (lengd > 15.2 && lengd < 17.0))
    {
    kodField.setText("S3 7B100");
    }
    else if( (tjocklek > 5.9 && tjocklek < 6.6) && (lengd > 16.9 && lengd < 18.0))
    {
    kodField.setText("T2 7B110");
    }
    else if( (tjocklek > 6.4 && tjocklek < 7.1) && (lengd > 17.9 && lengd < 20.0))
    {
    kodField.setText("W1 8C110");
    }
    else if( (tjocklek > 6.4 && tjocklek < 7.1) && (lengd > 19.9 && lengd < 21.0))
    {
    kodField.setText("X1 9C110");
    }
    else if( (tjocklek > 7.4 && tjocklek < 8.1) && (lengd > 20.9 && lengd < 22.1))
    {
    kodField.setText("Z0 9D120");
    }
    else if( (tjocklek > 7.4 && tjocklek < 8.1) && (lengd > 20.9 && lengd < 23.5))
    {
    kodField.setText("Z0 9C120");
    }
    else
    {
    kodField.setText("Finns ej!");
    }
    }
    else
    {
    double tjocklek = maxTjocklekField.getValue();
    double bredd = maxBreddField.getValue();
    if (tjocklek < 1.8 || tjocklek > 8.3 || bredd < 5.1 || bredd > 14.1)
    {
    kodField.setText("Finns Ej!");
    return;
    }
    int n = 0;
    int m = 0;
    m = Math.min(Math.max(((int) Math.ceil(((bredd - 5.1) * 2 ))) +1,1),19);
    if(tablFormFR.isSelected())
    {
    n = Math.min(Math.max(((int) Math.ceil(((tjocklek - 2) * 4))) +1,1),26);
    }
    else if(tablFormR.isSelected())
    {
    n = Math.min(Math.max(((int) Math.ceil(((tjocklek - 1.8) * 4))) +1,1),26);
    }
    else if(tablFormFF.isSelected())
    {
    n = Math.min(Math.max(((int) Math.ceil(((tjocklek - 2) * 4))) +1,1),26);
    int nn = 0;
    int mm = (int) bredd;
    if (( mm == 5 && tjocklek == 1.9)
    ||(mm == 5 && tjocklek == 2.0)
    ||(mm == 6 && tjocklek == 1.9)){nn=2;}// B

    else if(( mm == 5 && tjocklek == 2.1)
    || (mm == 5 && tjocklek == 2.2)
    || (mm == 6 && tjocklek == 2.0)
    || (mm == 6 && tjocklek == 2.1)
    || (mm == 7 && tjocklek == 1.9)
    || (mm == 7 && tjocklek == 2.0)
    || (mm == 8 && tjocklek == 1.9)){nn=3;}// C

    else if(( mm == 5 && tjocklek == 2.3)
    || (mm == 5 && tjocklek == 2.4)
    || (mm == 6 && tjocklek == 2.2)
    || (mm == 6 && tjocklek == 2.3)
    || (mm == 7 && tjocklek == 2.1)
    || (mm == 8 && tjocklek == 2.0)
    || (mm == 9 && tjocklek == 1.9)
    || (mm == 10 && tjocklek == 1.9)){nn=4;}// D

    else if(( mm == 5 && tjocklek == 2.5)
    || (mm == 5 && tjocklek == 2.6)
    || (mm == 6 && tjocklek == 2.4)
    || (mm == 6 && tjocklek == 2.5)
    || (mm == 7 && tjocklek == 2.2)
    || (mm == 7 && tjocklek == 2.3)
    || (mm == 8 && tjocklek == 2.1)
    || (mm == 9 && tjocklek == 2.0)
    || (mm == 10 && tjocklek == 2.0)
    || (mm == 11 && tjocklek == 1.9)
    || (mm == 11 && tjocklek == 2.0)
    || (mm == 12 && tjocklek == 1.9)
    || (mm == 12 && tjocklek == 2.0)
    || (mm == 13 && tjocklek == 1.9)
    || (mm == 13 && tjocklek == 2.0)
    || (mm == 14 && tjocklek == 1.9)
    || (mm == 14 && tjocklek == 2.0)){nn=5;}// E

    else if(( mm == 5 && tjocklek == 2.7)
    || (mm == 6 && tjocklek == 2.6)
    || (mm == 7 && tjocklek == 2.4)
    || (mm == 7 && tjocklek == 2.5)
    || (mm == 8 && tjocklek == 2.2)
    || (mm == 8 && tjocklek == 2.3)
    || (mm == 9 && tjocklek == 2.1)
    || (mm == 9 && tjocklek == 2.2)
    || (mm == 10 && tjocklek == 2.1)
    || (mm == 11 && tjocklek == 2.1)
    || (mm == 12 && tjocklek == 2.1)
    || (mm == 13 && tjocklek == 2.1)
    || (mm == 14 && tjocklek == 2.1)){nn=6;}// F

    else if(( mm == 5 && tjocklek == 2.8)
    || (mm == 5 && tjocklek == 2.9)
    || (mm == 5 && tjocklek == 3.0)
    || (mm == 6 && tjocklek == 2.7)
    || (mm == 6 && tjocklek == 2.8)
    || (mm == 7 && tjocklek == 2.6)
    || (mm == 7 && tjocklek == 2.7)
    || (mm == 8 && tjocklek == 2.4)
    || (mm == 8 && tjocklek == 2.5)
    || (mm == 9 && tjocklek == 2.3)
    || (mm == 9 && tjocklek == 2.4)
    || (mm == 10 && tjocklek == 2.2)
    || (mm == 10 && tjocklek == 2.3)
    || (mm == 11 && tjocklek == 2.2)
    || (mm == 12 && tjocklek == 2.2)
    || (mm == 13 && tjocklek == 2.2)
    || (mm == 14 && tjocklek == 2.2)){nn=7;}// G

    else if (( mm == 5 && tjocklek == 3.1)
    || (mm == 5 && tjocklek == 3.2)
    || (mm == 6 && tjocklek == 2.9)
    || (mm == 6 && tjocklek == 3.0)
    || (mm == 7 && tjocklek == 2.8)
    || (mm == 7 && tjocklek == 2.9)
    || (mm == 8 && tjocklek == 2.6)
    || (mm == 8 && tjocklek == 2.7)
    || (mm == 9 && tjocklek == 2.5)
    || (mm == 9 && tjocklek == 2.6)
    || (mm == 10 && tjocklek == 2.4)
    || (mm == 10 && tjocklek == 2.5)
    || (mm == 11 && tjocklek == 2.3)
    || (mm == 11 && tjocklek == 2.4)
    || (mm == 11 && tjocklek == 2.5)
    || (mm == 12 && tjocklek == 2.3)
    || (mm == 12 && tjocklek == 2.4)
    || (mm == 13 && tjocklek == 2.3)
    || (mm == 13 && tjocklek == 2.4)
    || (mm == 14 && tjocklek == 2.3)){nn=8;}// H

    else if (( mm == 6 && tjocklek == 3.1)
    || (mm == 6 && tjocklek == 3.2)
    || (mm == 7 && tjocklek == 3.0)
    || (mm == 7 && tjocklek == 3.1)
    || (mm == 8 && tjocklek == 2.8)
    || (mm == 8 && tjocklek == 2.9)
    || (mm == 8 && tjocklek == 3.0)
    || (mm == 9 && tjocklek == 2.7)
    || (mm == 9 && tjocklek == 2.8)
    || (mm == 9 && tjocklek == 2.9)
    || (mm == 10 && tjocklek == 2.6)
    || (mm == 10 && tjocklek == 2.7)
    || (mm == 10 && tjocklek == 2.8)
    || (mm == 11 && tjocklek == 2.6)
    || (mm == 11 && tjocklek == 2.7)
    || (mm == 12 && tjocklek == 2.5)
    || (mm == 12 && tjocklek == 2.6)
    || (mm == 13 && tjocklek == 2.5)
    || (mm == 14 && tjocklek == 2.4)
    || (mm == 14 && tjocklek == 2.5)){nn=9;}// I

    else if (( mm == 6 && tjocklek == 3.3)
    || (mm == 7 && tjocklek == 3.2)
    || (mm == 8 && tjocklek == 3.1)
    || (mm == 9 && tjocklek == 3.0)
    || (mm == 10 && tjocklek == 2.9)
    || (mm == 11 && tjocklek == 2.8)
    || (mm == 12 && tjocklek == 2.7)
    || (mm == 13 && tjocklek == 2.6)
    || (mm == 14 && tjocklek == 2.6)){nn=10;}// J

    else if (( mm == 6 && tjocklek == 3.4)
    || (mm == 6 && tjocklek == 3.5)
    || (mm == 7 && tjocklek == 3.3)
    || (mm == 7 && tjocklek == 3.4)
    || (mm == 8 && tjocklek == 3.2)
    || (mm == 8 && tjocklek == 3.3)
    || (mm == 9 && tjocklek == 3.1)
    || (mm == 9 && tjocklek == 3.2)
    || (mm == 10 && tjocklek == 3.0)
    || (mm == 10 && tjocklek == 3.1)
    || (mm == 11 && tjocklek == 2.9)
    || (mm == 11 && tjocklek == 3.0)
    || (mm == 12 && tjocklek == 2.8)
    || (mm == 12 && tjocklek == 2.9)
    || (mm == 13 && tjocklek == 2.7)
    || (mm == 13 && tjocklek == 2.8)
    || (mm == 14 && tjocklek == 2.7)){nn=11;}// K

    else if (( mm == 6 && tjocklek == 3.6)
    || (mm == 7 && tjocklek == 3.5)
    || (mm == 8 && tjocklek == 3.4)
    || (mm == 9 && tjocklek == 3.3)
    || (mm == 10 && tjocklek == 3.2)
    || (mm == 11 && tjocklek == 3.1)
    || (mm == 12 && tjocklek == 3.0)
    || (mm == 13 && tjocklek == 2.9)
    || (mm == 14 && tjocklek == 2.8)){nn=12;}// L

    else if (( mm == 6 && tjocklek == 3.7)
    || (mm == 7 && tjocklek == 3.6)
    || (mm == 8 && tjocklek == 3.5)
    || (mm == 9 && tjocklek == 3.4)
    || (mm == 10 && tjocklek == 3.3)
    || (mm == 11 && tjocklek == 3.2)
    || (mm == 12 && tjocklek == 3.1)
    || (mm == 13 && tjocklek == 3.0)
    || (mm == 14 && tjocklek == 2.9)){nn=13;}// M

    else if (( mm == 7 && tjocklek == 3.7)
    || (mm == 7 && tjocklek == 3.8)
    || (mm == 8 && tjocklek == 3.6)
    || (mm == 8 && tjocklek == 3.7)
    || (mm == 9 && tjocklek == 3.5)
    || (mm == 9 && tjocklek == 3.6)
    || (mm == 10 && tjocklek == 3.4)
    || (mm == 10 && tjocklek == 3.5)
    || (mm == 11 && tjocklek == 3.3)
    || (mm == 11 && tjocklek == 3.4)
    || (mm == 12 && tjocklek == 3.2)
    || (mm == 12 && tjocklek == 3.3)
    || (mm == 13 && tjocklek == 3.1)
    || (mm == 13 && tjocklek == 3.2)
    || (mm == 14 && tjocklek == 3.0)
    || (mm == 14 && tjocklek == 3.1)){nn=14;}// N

    else if (( mm == 7 && tjocklek == 3.9)
    || (mm == 8 && tjocklek == 3.8)
    || (mm == 9 && tjocklek == 3.7)
    || (mm == 10 && tjocklek == 3.6)
    || (mm == 11 && tjocklek == 3.5)
    || (mm == 12 && tjocklek == 3.4)
    || (mm == 13 && tjocklek == 3.3)
    || (mm == 14 && tjocklek == 3.2)){nn=15;}// O

    else if (( mm == 7 && tjocklek == 4.0)
    || (mm == 8 && tjocklek == 3.9)
    || (mm == 9 && tjocklek == 3.8)
    || (mm == 10 && tjocklek == 3.7)
    || (mm == 11 && tjocklek == 3.6)
    || (mm == 12 && tjocklek == 3.5)
    || (mm == 13 && tjocklek == 3.4)
    || (mm == 14 && tjocklek == 3.3)){nn=16;}// P

    else if (( mm == 7 && tjocklek == 4.1)
    || (mm == 8 && tjocklek == 4.0)
    || (mm == 8 && tjocklek == 4.1)
    || (mm == 9 && tjocklek == 3.9)
    || (mm == 9 && tjocklek == 4.0)
    || (mm == 10 && tjocklek == 3.8)
    || (mm == 10 && tjocklek == 3.9)
    || (mm == 11 && tjocklek == 3.7)
    || (mm == 11 && tjocklek == 3.8)
    || (mm == 12 && tjocklek == 3.6)
    || (mm == 12 && tjocklek == 3.7)
    || (mm == 13 && tjocklek == 3.5)
    || (mm == 13 && tjocklek == 3.6)
    || (mm == 14 && tjocklek == 3.4)
    || (mm == 14 && tjocklek == 3.5)){nn=17;}// Q

    else if (( mm == 8 && tjocklek == 4.2)
    || (mm == 8 && tjocklek == 4.3)
    || (mm == 9 && tjocklek == 4.1)
    || (mm == 9 && tjocklek == 4.2)
    || (mm == 10 && tjocklek == 4.0)
    || (mm == 10 && tjocklek == 4.1)
    || (mm == 11 && tjocklek == 3.9)
    || (mm == 11 && tjocklek == 4.0)
    || (mm == 12 && tjocklek == 3.8)
    || (mm == 12 && tjocklek == 3.9)
    || (mm == 13 && tjocklek == 3.7)
    || (mm == 13 && tjocklek == 3.8)
    || (mm == 14 && tjocklek == 3.6)
    || (mm == 14 && tjocklek == 3.7)){nn=18;}// R

    else if (( mm == 8 && tjocklek == 4.4)
    || (mm == 8 && tjocklek == 4.5)
    || (mm == 9 && tjocklek == 4.3)
    || (mm == 9 && tjocklek == 4.4)
    || (mm == 10 && tjocklek == 4.2)
    || (mm == 10 && tjocklek == 4.3)
    || (mm == 11 && tjocklek == 4.1)
    || (mm == 11 && tjocklek == 4.2)
    || (mm == 12 && tjocklek == 4.0)
    || (mm == 12 && tjocklek == 4.1)
    || (mm == 13 && tjocklek == 3.9)
    || (mm == 13 && tjocklek == 4.0)
    || (mm == 14 && tjocklek == 3.8)
    || (mm == 14 && tjocklek == 3.9)){nn=19;}// S

    else if (( mm == 8 && tjocklek == 4.6)
    || (mm == 8 && tjocklek == 4.7)
    || (mm == 9 && tjocklek == 4.5)
    || (mm == 9 && tjocklek == 4.6)
    || (mm == 10 && tjocklek == 4.4)
    || (mm == 10 && tjocklek == 4.5)
    || (mm == 11 && tjocklek == 4.3)
    || (mm == 11 && tjocklek == 4.4)
    || (mm == 12 && tjocklek == 4.2)
    || (mm == 12 && tjocklek == 4.3)
    || (mm == 13 && tjocklek == 4.1)
    || (mm == 13 && tjocklek == 4.2)
    || (mm == 14 && tjocklek == 4.0)
    || (mm == 14 && tjocklek == 4.1)){nn=20;}// T

    else if (( mm == 8 && tjocklek == 4.8)
    || (mm == 8 && tjocklek == 4.9)
    || (mm == 9 && tjocklek == 4.7)
    || (mm == 9 && tjocklek == 4.8)
    || (mm == 10 && tjocklek == 4.6)
    || (mm == 10 && tjocklek == 4.7)
    || (mm == 11 && tjocklek == 4.5)
    || (mm == 11 && tjocklek == 4.6)
    || (mm == 12 && tjocklek == 4.4)
    || (mm == 12 && tjocklek == 4.5)
    || (mm == 13 && tjocklek == 4.3)
    || (mm == 13 && tjocklek == 4.4)
    || (mm == 14 && tjocklek == 4.2)
    || (mm == 14 && tjocklek == 4.3)){nn=21;}// U

    else if (( mm == 9 && tjocklek == 4.9)
    || (mm == 9 && tjocklek == 5.0)
    || (mm == 9 && tjocklek == 5.1)
    || (mm == 10 && tjocklek == 4.8)
    || (mm == 10 && tjocklek == 4.9)
    || (mm == 10 && tjocklek == 5.0)
    || (mm == 11 && tjocklek == 4.7)
    || (mm == 11 && tjocklek == 4.8)
    || (mm == 11 && tjocklek == 4.9)
    || (mm == 12 && tjocklek == 4.6)
    || (mm == 12 && tjocklek == 4.7)
    || (mm == 12 && tjocklek == 4.8)
    || (mm == 13 && tjocklek == 4.5)
    || (mm == 13 && tjocklek == 4.6)
    || (mm == 13 && tjocklek == 4.7)
    || (mm == 14 && tjocklek == 4.4)
    || (mm == 14 && tjocklek == 4.5)
    || (mm == 14 && tjocklek == 4.6)){nn=22;}// V

    else if (( mm == 9 && tjocklek == 5.2)
    || (mm == 9 && tjocklek == 5.3)
    || (mm == 9 && tjocklek == 5.4)
    || (mm == 10 && tjocklek == 5.1)
    || (mm == 10 && tjocklek == 5.2)
    || (mm == 10 && tjocklek == 3.3)
    || (mm == 11 && tjocklek == 5.0)
    || (mm == 11 && tjocklek == 5.1)
    || (mm == 11 && tjocklek == 5.2)
    || (mm == 12 && tjocklek == 4.9)
    || (mm == 12 && tjocklek == 5.0)
    || (mm == 12 && tjocklek == 5.1)
    || (mm == 13 && tjocklek == 4.8)
    || (mm == 13 && tjocklek == 4.9)
    || (mm == 13 && tjocklek == 5.0)
    || (mm == 14 && tjocklek == 4.7)
    || (mm == 14 && tjocklek == 4.8)
    || (mm == 14 && tjocklek == 4.9)){nn=23;}// W

    else if (( mm == 9 && tjocklek == 5.5)
    || (mm == 9 && tjocklek == 5.6)
    || (mm == 9 && tjocklek == 5.7)
    || (mm == 9 && tjocklek == 5.8)
    || (mm == 10 && tjocklek == 5.4)
    || (mm == 10 && tjocklek == 5.5)
    || (mm == 10 && tjocklek == 5.6)
    || (mm == 10 && tjocklek == 5.7)
    || (mm == 11 && tjocklek == 5.3)
    || (mm == 11 && tjocklek == 5.4)
    || (mm == 11 && tjocklek == 5.5)
    || (mm == 11 && tjocklek == 5.6)
    || (mm == 12 && tjocklek == 5.2)
    || (mm == 12 && tjocklek == 5.3)
    || (mm == 12 && tjocklek == 5.4)
    || (mm == 12 && tjocklek == 5.5)
    || (mm == 13 && tjocklek == 5.1)
    || (mm == 13 && tjocklek == 5.2)
    || (mm == 13 && tjocklek == 5.3)
    || (mm == 13 && tjocklek == 5.4)
    || (mm == 14 && tjocklek == 5.0)
    || (mm == 14 && tjocklek == 5.1)
    || (mm == 14 && tjocklek == 5.2)
    || (mm == 14 && tjocklek == 5.3)){nn=24;}// X

    else if (( mm == 10 && tjocklek == 5.8)
    || (mm == 11 && tjocklek == 5.7)
    || (mm == 11 && tjocklek == 5.8)
    || (mm == 12 && tjocklek == 5.6)
    || (mm == 12 && tjocklek == 5.7)
    || (mm == 12 && tjocklek == 5.8)
    || (mm == 13 && tjocklek == 5.5)
    || (mm == 13 && tjocklek == 5.6)
    || (mm == 13 && tjocklek == 5.7)
    || (mm == 13 && tjocklek == 5.8)
    || (mm == 14 && tjocklek == 5.4)
    || (mm == 14 && tjocklek == 5.5)
    || (mm == 14 && tjocklek == 5.6)
    || (mm == 14 && tjocklek == 5.7)){nn=25;}// Y

    else if (mm == 14 && tjocklek == 5.8){nn=26;}// Z
    else
    {
    kodField.setText("Finns Ej!");
    return;
    }
    n = (int)((n+nn+1)/2);
    }

    // A = 64
    char hjulbokstav = (char) (n+64);
    int hjulnr = 55 + m*5;
    int fonster;
    if (m < 3) { fonster = 1;}
    else if (m > 2 && m < 7) { fonster = 2;}
    else if (m > 6 && m < 11) { fonster = 3;}
    else if (m > 10 && m < 15){fonster = 4;}
    else { fonster = 5;}
    //else { fonster = ((int) (m-2) /4) + 2;}
    char fordelare;
    if (n < 6) { fordelare = 'A';}
    else if (n < 13) { fordelare = 'B';}
    else if (n < 21) { fordelare = 'C';}
    else { fordelare = 'D';}
    int pip = ((int) ((double) m -1)/2) * 10 + 75;
    if ( pip > 145) { pip = 155;}
    String result;
    result = String.format("%s%d %d%s%d S", hjulbokstav, hjulnr, fonster, fordelare, pip);
    if (result.equals("G60 1B75 S")){result = "H60 1B75 S";}
    else if (result.equals("Q145 5C155 S")){result = "R145 5C155 S";}
    else if (result.equals("U125 4D135 S")){result = "V125 4D135 S";}
    else if ((n==1 && m>5)||(n==2 && m>6)||(n==3 && m>7)||(n==4 && m>7)||
    (n==5 && m>9)||(n==6 && m>9)||(n==7 && m>11)||(n==8 && m>14)||
    (n==9 && m>15)||(n==10 && m>15)||(n==11 && m>15)
    ||(n==9 && m<2)||(n==10 && m<3)||(n==11 && m<3)||(n==12 && m<5)
    ||(n==13 && m<5)||(n==14 && m<5)||(n==15 && m<6)||(n==16 && m<7)
    ||(n==17 && m<7)||(n==18 && m<7)||(n==19 && m<7)||(n==20 && m<7)
    ||(n==21 && m<7)||(n==22 && m<12)||(n==23 && m<12)||(n==24 && m<12)
    ||(n==25 && m<12)||(n==26 && m<12))
    {result="Finns Ej!";}
    kodField.setText(result);
    }
    }
    }

  8. #8
    jinseek is offline Member
    Join Date
    Apr 2011
    Posts
    1
    Rep Power
    0

    Default "Exception in thread "main" java.lang.NullPointerException".

    Hi all,

    Recently, I had same problem mentioned above.
    Now I fixed it as follows.
    public boolean isValid()
    { try
    { Integer.parseInt(getText());
    return true;
    }
    catch(NullPointerException e) // add case for nullpointerexception
    { return true;
    }
    catch(NumberFormatException e)
    { return false;
    }
    }


    Thanks,

Similar Threads

  1. Replies: 4
    Last Post: 04-17-2009, 02:17 AM
  2. Exception in thread "main" java.lang.NullPointerException
    By farooqhussain786 in forum New To Java
    Replies: 10
    Last Post: 04-03-2009, 07:31 AM
  3. Exception in thread "main" java.lang.NullPointerException
    By vasavi.singh in forum New To Java
    Replies: 0
    Last Post: 02-24-2009, 02:19 PM
  4. Replies: 1
    Last Post: 02-17-2009, 11:54 AM
  5. Replies: 1
    Last Post: 07-16-2007, 07:32 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •