Results 1 to 9 of 9
  1. #1
    sanshik is offline Member
    Join Date
    Jul 2011
    Location
    India
    Posts
    6
    Rep Power
    0

    Default Error in DataInputStream

    Hi,
    This is my first thread,iam using Jcreator IDE for running java programs
    I got the following error when i executed the program
    /*number1=Integer.parseInteger(in.readLine());
    number2=Integer.parseInteger(in.readLine());
    res=Integer.parseInteger(in.readLine());
    */
    Error: D:\jp\new6.java:13: cannot find symbol
    symbol : method parseInteger(java.lang.String)
    location: class java.lang.Integer
    number1=Integer.parseInteger(in.readLine());
    ^
    D:\jp\new6.java:14: cannot find symbol
    symbol : method parseInteger(java.lang.String)
    location: class java.lang.Integer
    number2=Integer.parseInteger(in.readLine());
    ^
    D:\jp\new6.java:15: cannot find symbol
    symbol : method parseInteger(java.lang.String)
    location: class java.lang.Integer
    res=Integer.parseInteger(in.readLine());
    ^
    Note: D:\jp\new6.java uses or overrides a deprecated API.
    Note: Recompile with -Xlint:deprecation for details.
    3 errors

    Process completed.

    Thanks in advance!

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,308
    Rep Power
    25

    Default

    I got the following error when i executed the program
    It looks like a compiler error, not an execution time error.
    The compiler can't find the parseInteger(java.lang.String) method in the class java.lang.Integer.

    Read the API doc for the Integer class to be sure you are spelling the method name correctly.

  3. #3
    sanshik is offline Member
    Join Date
    Jul 2011
    Location
    India
    Posts
    6
    Rep Power
    0

    Default

    Thanks for ur suggestion but i could not find out the error so i post the whole program below just check and provide a solution please
    import java.io.*;
    import java.lang.*;

    class new6
    {
    public static void main(String args[])
    {
    DataInputStream in =new DataInputStream(System.in);
    int number1;
    int number2;
    int res;
    System.out.println("Enter the two values for Addition");
    number1=Integer.parseInt(in.readLine());
    number2=Integer.parseInt(in.readLine());
    res=Integer.parseInt(in.readLine());
    res=number1+number2;
    System.out.println("The result is : " + res);

    }
    }

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,308
    Rep Power
    25

    Default

    provide a solution please
    Please explain what your problem is?
    Post the error messages here.

  5. #5
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    We aren't here to fix your code, instead we give you the information necessary to fixing the problem(links to API docs, or explaining why something isn't working), provide us with the errors. Not everyone is willing/able to compile and run the code.

    Read this link(mainly what it says about readLine()): http://download.oracle.com/javase/6/...putStream.html

    If you are simply reading from the console I suggest you use a scanner instead: http://download.oracle.com/javase/6/...l/Scanner.html

    And if you want to work with the streams instead, check this out: http://download.oracle.com/javase/tu.../essential/io/
    Last edited by sunde887; 07-10-2011 at 04:33 AM.

  6. #6
    sanshik is offline Member
    Join Date
    Jul 2011
    Location
    India
    Posts
    6
    Rep Power
    0

    Default

    I posted the errors ,.suggest me a solution

    D:\jp\new6.java:13: unreported exception java.io.IOException; must be caught or
    declared to be thrown
    number1=Integer.parseInt(in.readLine());
    ^
    D:\jp\new6.java:14: unreported exception java.io.IOException; must be caught or
    declared to be thrown
    number2=Integer.parseInt(in.readLine());
    ^
    D:\jp\new6.java:15: unreported exception java.io.IOException; must be caught or
    declared to be thrown
    res=Integer.parseInt(in.readLine());
    ^
    Note: D:\jp\new6.java uses or overrides a deprecated API.
    Note: Recompile with -Xlint:deprecation for details.
    3 errors

  7. #7
    sanshik is offline Member
    Join Date
    Jul 2011
    Location
    India
    Posts
    6
    Rep Power
    0

    Default

    Hi,I get u that u r not there to fix our code,.
    I posted the errors now
    suggest a solution
    Thanks in advance

  8. #8
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,308
    Rep Power
    25

    Default

    java.io.IOException; must be caught
    The statement that is referred to throws an IOException. You should put that code inside of a try{}catch(){} block that catches that exception.

  9. #9
    sanshik is offline Member
    Join Date
    Jul 2011
    Location
    India
    Posts
    6
    Rep Power
    0

    Default

    Thank you Very much
    The code works very well with ur solution
    thanks again !

    Output:
    D:\jp>java new6
    Enter the two values for Addition
    1
    2
    The result is : 3

Similar Threads

  1. DataInputStream
    By robs in forum Java Gaming
    Replies: 7
    Last Post: 04-14-2011, 06:27 PM
  2. DataInputStream to file
    By jasondeegan in forum New To Java
    Replies: 5
    Last Post: 06-16-2010, 03:35 PM
  3. Problem with DataInputStream
    By ZivonHunter in forum New To Java
    Replies: 1
    Last Post: 11-21-2008, 05:10 AM
  4. DataInputStream readLine()
    By ravian in forum New To Java
    Replies: 2
    Last Post: 11-26-2007, 10:44 PM
  5. Replies: 1
    Last Post: 08-07-2007, 07:16 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
  •