无法执行java程序[重复]

问题描述 投票:0回答:1

这个问题在这里已有答案:

当我尝试编译程序时,它编译成功。但是当我执行程序时,这是我在命令提示符下收到的输出

java.base / jdk.internal.math.FloatingDecimal.parseFloat(FloatingDecimal.java)中java.base / jdk.internal.math.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:1838)中的线程“main”java.lang.NullPointerException中的异常:122)在grade.main的java.base / java.lang.Float.parseFloat(Float.java:455)中(grade.java:9)

 import javax.swing.JOptionPane;

    class grade{ 
             public static void main(String[] args){


         String engmark=null;
         String mathmark=null;
         String sstmark=null;
         String scimark=null;
         String compmark=null;
         float sc=Float.parseFloat(scimark);
         float en=Float.parseFloat(engmark);
         float ss=Float.parseFloat(sstmark);
         float mt=Float.parseFloat(mathmark);
         float co=Float.parseFloat(compmark);

         float totmark= sc+en+ss+co+mt;


         String response;


          response= JOptionPane.showInputDialog("Enter the maximum marks of each subject : ");

                 if (response==null){JOptionPane.showMessageDialog(null,"You  clicked on the cancel button.");
                                         System.exit(0);
                                         }               
                     else
                     if (response.equals("")){JOptionPane.showMessageDialog(null,"You must make an entry in the input box");
                                      System.exit(0);
                                           }

                          else

                        engmark= JOptionPane.showInputDialog(null,"Enter the marks obtained in english :");

                                        if (engmark==null){JOptionPane.showMessageDialog(null,"You  clicked on the cancel button.");
                                         System.exit(0);
                                         }               
                     else
                     if (engmark.equals("")){JOptionPane.showMessageDialog(null,"You must make an entry in the input box");
                                      System.exit(0);
                                           }
                                else           
                                 mathmark= JOptionPane.showInputDialog(null,"Enter the marks obtained in mathematics :");
                                        if (mathmark==null){JOptionPane.showMessageDialog(null,"You  clicked on the cancel button.");
                                         System.exit(0);
                                         }               
                     else
                     if (mathmark.equals("")){JOptionPane.showMessageDialog(null,"You must make an entry in the input box");
                                      System.exit(0);
                                           }

                                else                                    
                                scimark= JOptionPane.showInputDialog(null,"Enter the marks obtained in science :");
                                        if (scimark==null){JOptionPane.showMessageDialog(null,"You  clicked on the cancel button.");
                                         System.exit(0);
                                         }               
                     else
                     if (scimark.equals("")){JOptionPane.showMessageDialog(null,"You must make an entry in the input box");
                                      System.exit(0);
                                           }

                                else                                    
                                sstmark= JOptionPane.showInputDialog(null,"Enter the marks obtained in S.st. :");
                                        if (sstmark==null){JOptionPane.showMessageDialog(null,"You  clicked on the cancel button.");
                                         System.exit(0);
                                         }               
                     else
                     if (sstmark.equals("")){JOptionPane.showMessageDialog(null,"You must make an entry in the input box");
                                      System.exit(0);
                                           }

                                else                                    
                                compmark= JOptionPane.showInputDialog(null,"Enter the marks obtained in computer :");
                                        if (compmark==null){JOptionPane.showMessageDialog(null,"You  clicked on the cancel button.");
                                         System.exit(0);
                                         }               
                     else
                     if (compmark.equals("")){JOptionPane.showMessageDialog(null,"You must make an entry in the input box");
                                      System.exit(0);
                                           }



                     else

                     JOptionPane.showMessageDialog(null,"Your total marks is :" + totmark);                          

}

}

java floating-point joptionpane string-conversion
1个回答
0
投票

你的代码在float sc=Float.parseFloat(scimark);爆炸了scimark的原因是null。把它变成别的东西并改变剩下的那些没有null作为parseFloat的论据。

© www.soinside.com 2019 - 2024. All rights reserved.