Guten Abend,
ich hätte mal kurz eine Frage zu einem Code-Abschnitt.
Ich habe einen Taschenrechner geschrieben, und zwar mit einem unüblicherem Algorithmus.
Aber jetzt zu meiner Frage:
In folgendem Code-Abschnitt taucht untenstehender Fehler auf:
Code:
Und das ist der Fehler der rauskommt:
Der Fehler taucht anscheinend im rot markierten Teil auf.
Wäre cool wenn sich das mal jemand anschauen könnte.
LG hi9hi98
ich hätte mal kurz eine Frage zu einem Code-Abschnitt.
Ich habe einen Taschenrechner geschrieben, und zwar mit einem unüblicherem Algorithmus.
Aber jetzt zu meiner Frage:
In folgendem Code-Abschnitt taucht untenstehender Fehler auf:
Code:
Java:
public String term ="";
public double end;
private String[] z = new String[3];
private ArrayList<String> list;
int iz=1;
public String ergebnis(String erg, String newOp){
erg = erg+newOp;
return erg;
}
public String addTerm(String newPart){
term = term + newPart;
String x = term;
System.out.println(x);
return x;
}
public String removeLastChar() {
term = term.substring(0,term.length()-1);
return term;
}
public String reset() {
term = "";
return term;
}
public double StringToDouble(String s){
double e = Double.parseDouble(s);
return e;
}
public double rech(){
list = new ArrayList<String>();
for(int i=0; i<=term.length()-1;i++){
String a = Character.toString(term.charAt(i));
list.add(i,a);
}
for(int i=0; i<=list.size();i=i++){
String b = list.get(i);
System.out.println(b);
end = end +classify(b);
}
return end;
}
private double classify(String s){
if(iz==1){
if(s=="0"||s=="1"||s=="2"||s=="3"||s=="4"||s=="5"||s=="6"||s=="7"||s=="8"||s=="9"){
z[0]=z[0]+s;
}
else if(s=="+"||s=="-"||s=="*"||s=="/"){
iFunc(iz);
z[2]=s;
}
else {System.out.println("Syntax-Fehler");}}
else if(iz==-1){
if(s=="0"||s=="1"||s=="2"||s=="3"||s=="4"||s=="5"||s=="6"||s=="7"||s=="8"||s=="9"){
z[1]=z[1]+s;
}
else if(s=="+"||s=="-"||s=="*"||s=="/"){
iFunc(iz);
z[2]=s;
}
else {System.out.println("Syntax-Fehler");}
}
Term t = new Term();
System.out.println(StringToDouble(z[0]));
return t.ergebnis(StringToDouble(z[0]),StringToDouble(z[1]), z[2]);
}
private void iFunc(int i){
i=i*-1;
}
}
Code:
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at sun.misc.FloatingDecimal.readJavaFormatString(Unknown Source)
at sun.misc.FloatingDecimal.parseDouble(Unknown Source)
at java.lang.Double.parseDouble(Unknown Source)
at operatorClass.StringToDouble(operatorClass.java:34)
at operatorClass.classify(operatorClass.java:82)
at operatorClass.rech(operatorClass.java:48)
at guiClass.actionPerformed(guiClass.java:206)
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.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$500(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(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)
Wäre cool wenn sich das mal jemand anschauen könnte.
LG hi9hi98
Zuletzt bearbeitet von einem Moderator: