• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

throws ExceptionIO error

 
Greenhorn
Posts: 13
1
C++
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator




I am trying to run this code but I am getting error in line "throw io.IOException;"(line 11) I have downloaded the TextIO file...I am not sure how to debug this,
Any help will be greatly appreciated ^.^
 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That code should be



This tells Java that the method might (or might not) throw an IOException when running.
 
Greenhorn
Posts: 18
Android IntelliJ IDE Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't have any idea what you did with the line but as far as i know, surrounding the statement with a try catch or adding to your main method signature will definitely make it work.
 
Sarah Singh
Greenhorn
Posts: 13
1
C++
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
@Jeanne Boyarsky

Gotchya! Thanks for clarifying that When I apply the edits,I think it goes into an infinite loop...since its not producing any output...unless I am doing something wrong :\



===========================================================================================
@Debdeep Ganguly

Yes! The code works with the suggested ammendment! Although I do not get the expected results

-------------------------------
Expected output

Help on:
1. if
2. switch
3. while
4. do-while
5. for
Choose one:
4
The do-while
do{
statement;
}while(condition);

--------------------------------------
Output after suggested ammendment

Help on:
if:
switch:
while:
do - while:
for
:
choose one:
 
Sheriff
Posts: 7125
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What could you do to get the expected results?
 
Rancher
Posts: 5008
38
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Safe programming note: When coding a switch statement ALWAYS have a default: case that prints out a message saying what is wrong and shows the invalid input.
 
Marshal
Posts: 79151
377
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch

Don't use System.in.read(). It is a really awkward method to use. Try a Scanner, and you can use the words as options in the switch statement.
 
Sarah Singh
Greenhorn
Posts: 13
1
C++
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks everyone who looked into my problem ^.^ And thanks for all the suggestions <3
This is really silly, but I realized thatsome of my print statements are wrong which is why I am not getting expected output D:
Sorry about that :'( Also, there was a bug in java.io.IOException Line which in now fixed \(^.^)/
Regards

Editted Code


 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Thanks for providing your solution ... have a cow.

Henry
reply
    Bookmark Topic Watch Topic
  • New Topic