Question

java.lang.NumberFormatException: For input string: ":"  

What does this mean? I get the above error if I run the code (below).I am a beginner here. and..

  stacktrace:[Ljava.lang.StackTraceElement;@e596c9

the code:

try
{
    Class.forName("java.sql.DriverManager");
    Connection con=DriverManager.getConnection("jdbc:mysql://localhost/bvdb","root","enter")
            Statement stm=con.createStatement();
    String m="-",t="-",w="-",th="--",f="-",st="--",s="-",runson;
    if(jCheckBox1.isSelected()==true){
        m="m";}

    if(jCheckBox2.isSelected()==true){
        t="t";}
    if(jCheckBox3.isSelected()==true){
        w="w";}
    if(jCheckBox4.isSelected()==true){
        th="th";}
    if(jCheckBox5.isSelected()==true){
        f="f";}
    if(jCheckBox6.isSelected()==true){
        st="st";}
    if(jCheckBox7.isSelected()==true){
        s="s";}
    runson= m + t + w + th + f + st + s ;
    int h1=Integer.valueOf(jTextField10.getText().substring(0,2)
            int mins1=Integer.valueOf(jTextField10.getText().substring(3,5));
    int h2=Integer.valueOf(jTextField12.getText().substring(0,2));
    int mins2=Integer.valueOf(jTextField12.getText().substring(2,3));
    Boolean x=jTextField10.getText().substring(2,3).equals(":");
    Boolean y=jTextField12.getText().substring(2,3).equals(":");
    String time1=jTextField10.getText().substring(0,2)+jTextField10.getText().substring (2,3)+jTextField10.getText().substring(3,5);
    String time2=jTextField12.getText().substring(0,2)+jTextField12.getText().substring(2,3)+jTextField12.getText().substring(3,5);
    String tfac1=jTextField13.getText();
    String tfac2=jTextField14.getText();
    String  tfac3=jTextField15.getText();
    String tfsl=jTextField16.getText();
    if(Integer.valueOf(jTextField3.getText())==0){
        tfac1="0";
        if(Integer.valueOf(jTextField4.getText())==0){
            tfac2="0";}
        if(Integer.valueOf(jTextField5.getText())==0){
            tfac3="0";}
        if(Integer.valueOf(jTextField6.getText())==0){
            tfsl="0";}
        if(y==true&&x==true&&jTextField1.getText().trim().length()<=6&&jTextField2.getText().trim().length()<=30&&h1<=24&&h2<=24&&mins1<=59&&mins2<=59){
            String q="INSERT INTO TRAININFO VALUE ("+jTextField1.getText()+",'"+jTextField2.getText()+"','"+jTextField9.getText()+"','"+time1+"','"+jTextField11.getText()+"','"+time2+"','"+runson+"',"+tfac1+","+tfac2+ ","+tfac3+","+tfsl+","+jTextField3.getText()+","+jTextField4.getText()+","+jTextField5.getText()+","+jTextField6.getText()+");";

            stm.executeUpdate(q);

            JOptionPane.showMessageDialog("ADDED");
        }
    }
    catch (Exception e){
        e.printStackTrace();
    }
Was it helpful?

Solution

that means you can not convert the String ":" to Number like integer or double

see below link

http://docs.oracle.com/javase/7/docs/api/java/lang/NumberFormatException.html

According to java docs

Thrown to indicate that the application has attempted to convert a string to one of the numeric types, but that the string does not have the appropriate format.

OTHER TIPS

It means you want to convert ":" to a number which is not allowed. Hence you are getting the exception. Better show your code

The best way you get responses faster & answered your question is posting your code. You cannot convert String to number.

As others have said Java can't convert "15:" into a number because ":" is not a digit. And the most probable cause for this is a line like this one:

int h1 = Integer.valueOf(jTextField10.getText().substring(0,2));

where you are splitting a time string at the wrong index which is why you have ":" in it.

UPDATE

Better way of splitting a time string like "12:35:09" is by using String.split():

String timeString = "12:35:09";
String[] parts = timeString.split(":");
boolean validTimeString = parts.length == 3;

The code above will result in the following values:

timeString = "12:35:09"
parts[0] = "12"
parts[1] = "35"
parts[2] = "09"
validTimeString = true

String.split(DELIMITER) will split the string into N + 1 strings where N is the number of occurences of the DELIMITER in target string.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top