Click to See Complete Forum and Search --> : Am I blind or something?


Entertainer
04-25-2005, 04:59 AM
Alright, there seems to be an error, but i just have no idea what it could be or how i could solve it.

Could you guys look at it and maybe tell me where the error is? i'm getting a little bit annoyed by this ******* bull.

import java.awt.event.*;
import java.lang.Integer;
/*
* Created on 21-mrt-2005
* @author R. Knijntje
*
*
*
*
* Created by R. Knijnenburg
* Copyright @ R. Knijnenburg
*/

public class RekenMachineLuisteraar implements ActionListener
{
private RekenMachineModel m;
private RekenMachineView v;
private RekenMachineValidator rV;

public class RekenMachineValidator
{
private boolean correctheid;
private int foutNummer;
public String bericht;

public boolean getCorrectheid()
{
return (correctheid);
}

public String foutcodeToFoutmelding(int foutNummer)
{
String bericht = "";

switch(foutNummer)
{
case 0:
bericht = "Alles is goed ingevoerd";
case 1:
bericht = "Er kunnen niet meer dan 9 cijfers verwerkt worden";
case 2:
bericht = "Er is niets ingevuld in 1 van de velden";
case 3:
bericht = "Er mogen alleen getallen ingevuld worden";
default:
bericht = "Fout bij het controleren";
}

return(bericht);
}

public RekenMachineValidator()
{
foutNummer = 0;
correctheid = true;
}

public int checkFout(String checkString)
{
char tempChar;
correctheid = true;
foutNummer = 0;

if (checkString.length() > 9)
{
foutNummer = 1;
correctheid = false;
}

else if (checkString == "")
{
foutNummer = 2;
correctheid = false;
}

else
{
for (int i = 0; i < checkString.length(); i++)
{
tempChar = checkString.charAt(i);

if (!Character.isDigit(tempChar))
{
foutNummer = 3;
correctheid = false;
}
}

}

return foutNummer;

}
}



public RekenMachineLuisteraar(RekenMachineModel m , RekenMachineView v)
{
rV = new RekenMachineValidator();
this.m = m;
this.v = v;
}

public void actionPerformed(ActionEvent arg0)
{
String stringGetal1 = v.geefInvoer1();
String stringGetal2 = v.geefInvoer2();

System.out.println(v.geefInvoer1());
System.out.println(v.geefInvoer2());

int intGetal1;
int intGetal2;

intGetal1 = Integer.parseInt(stringGetal1);
intGetal2 = Integer.parseInt(stringGetal2);

m.setGetal1(intGetal1);
m.setGetal2(intGetal2);

if(rV.correctheid = false)
{
v.setUitkomst(rV.foutcodeToFoutmelding(1));
}

else
{
v.toonResultaat(m.geefOptelling());
}

}

}

buntine
04-25-2005, 05:45 AM
Which error message are you receiving?

Entertainer
04-25-2005, 05:52 AM
a huge one ^^ :

Exception in thread "AWT-EventQueue-0" java.lang.NumberFormatException: For input string: ""
at java.lang.NumberFormatException.forInputString(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at RekenMachineLuisteraar.actionPerformed(RekenMachineLuisteraar.java:116)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)

Entertainer
04-25-2005, 07:44 AM
Alright, i think i found the error, but now i have a new one :P

this is the starter of the program:

import javax.swing.JFrame;

/*
* Created on Feb 24, 2005
* @author R. Knijntje
*
*
*
*
* Created by R. Knijnenburg
* Copyright @ R. Knijnenburg
*/

public class RekenMachineStarter
{
public static void main(String[] args)
{
JFrame.setDefaultLookAndFeelDecorated(true);
RekenMachineView mijnView = new RekenMachineView();
RekenMachineModel mijnModel = new RekenMachineModel();
RekenMachineLuisteraar.RekenMachineValidator mijnValidator = new RekenMachineLuisteraar.RekenMachineValidator();
RekenMachineLuisteraar l = new RekenMachineLuisteraar(mijnModel, mijnView, mijnValidator);
mijnView.voegLuisteraarToe(l);
}
}

-----------------------------------------------------------------------------------

the code of the listener:

import java.awt.event.*;
import java.lang.Integer;

/*
* Created on 21-mrt-2005
* @author R. Knijntje
*
*
*
*
* Created by R. Knijnenburg
* Copyright @ R. Knijnenburg
*/

public class RekenMachineLuisteraar implements ActionListener
{
private RekenMachineModel m;
private RekenMachineView v;
private RekenMachineValidator rV;

public class RekenMachineValidator
{
private boolean correctheid;
private int foutNummer;
public String bericht;

public boolean getCorrectheid()
{
return (correctheid);
}

public String foutcodeToFoutmelding(int foutNummer)
{
String bericht = "";

switch(foutNummer)
{
case 0:
bericht = "Alles is goed ingevoerd";
case 1:
bericht = "Er kunnen niet meer dan 9 cijfers verwerkt worden";
case 2:
bericht = "Er is niets ingevuld in 1 van de velden";
case 3:
bericht = "Er mogen alleen getallen ingevuld worden";
default:
bericht = "Fout bij het controleren";
}

return(bericht);
}

public RekenMachineValidator()
{
foutNummer = 0;
correctheid = true;
}

public int checkFout(String checkString)
{
char tempChar;
correctheid = true;
foutNummer = 0;

if (checkString.length() > 10)
{
foutNummer = 1;
correctheid = false;
}

else if (checkString == "")
{
foutNummer = 2;
correctheid = false;
}

else
{
for (int i = 0; i < checkString.length(); i++)
{
tempChar = checkString.charAt(i);

if (!Character.isDigit(tempChar))
{
foutNummer = 3;
correctheid = false;
}
}

}

return foutNummer;

}
}



public RekenMachineLuisteraar(RekenMachineModel m , RekenMachineView v, RekenMachineValidator rV)
{
rV = new RekenMachineValidator();
this.m = m;
this.v = v;
}

public void actionPerformed(ActionEvent arg0)
{
String stringGetal1 = v.geefInvoer1();
String stringGetal2 = v.geefInvoer2();

System.out.println(v.geefInvoer1());
System.out.println(v.geefInvoer2());

int intGetal1;
int intGetal2;

intGetal1 = Integer.parseInt(stringGetal1);
intGetal2 = Integer.parseInt(stringGetal2);

m.setGetal1(intGetal1);
m.setGetal2(intGetal2);

if(rV.correctheid = false)
{
v.setUitkomst(rV.foutcodeToFoutmelding(1));
}

else
{
v.toonResultaat(m.geefOptelling());
}

}

}
----------------------------------------------------------------------------------

the error i get :

Exception in thread "main" java.lang.Error: Unresolved compilation problem:
No enclosing instance of type RekenMachineLuisteraar is accessible. Must qualify the allocation with an enclosing instance of type RekenMachineLuisteraar (e.g. x.new A() where x is an instance of RekenMachineLuisteraar).

at RekenMachineStarter.main(RekenMachineStarter.java:21)