Java unreported exception reading an input stream [duplicate]











up vote
-2
down vote

favorite













This question already has an answer here:




  • Error message “unreported exception java.io.IOException; must be caught or declared to be thrown”

    5 answers




My code for reading an input stream of numbers and sorts them into an array, returns
error:



unreported exception IOException; must be caught or declared to be thrown



on String lines = br.readLine();



 public int inputArr()  {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String lines = br.readLine();
String strs = lines.trim().split("\s+");
int a = new int [strs.length];
for (int i = 0; i < strs.length; i++) {
a[i] = Integer.parseInt(strs[i]);
}
return a ;
}


Any help please on this?










share|improve this question













marked as duplicate by Hovercraft Full Of Eels java
Users with the  java badge can single-handedly close java questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 7 at 20:36


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.















  • Either you add a throws IOException to your method signature or you try {} catch (IOException e) {} it... You have those two options to report possible Exceptions.
    – deHaar
    Nov 7 at 20:34












  • Please Google your error message (please click on link) before asking as most questions have been asked before, and in this case many times before.
    – Hovercraft Full Of Eels
    Nov 7 at 20:37

















up vote
-2
down vote

favorite













This question already has an answer here:




  • Error message “unreported exception java.io.IOException; must be caught or declared to be thrown”

    5 answers




My code for reading an input stream of numbers and sorts them into an array, returns
error:



unreported exception IOException; must be caught or declared to be thrown



on String lines = br.readLine();



 public int inputArr()  {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String lines = br.readLine();
String strs = lines.trim().split("\s+");
int a = new int [strs.length];
for (int i = 0; i < strs.length; i++) {
a[i] = Integer.parseInt(strs[i]);
}
return a ;
}


Any help please on this?










share|improve this question













marked as duplicate by Hovercraft Full Of Eels java
Users with the  java badge can single-handedly close java questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 7 at 20:36


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.















  • Either you add a throws IOException to your method signature or you try {} catch (IOException e) {} it... You have those two options to report possible Exceptions.
    – deHaar
    Nov 7 at 20:34












  • Please Google your error message (please click on link) before asking as most questions have been asked before, and in this case many times before.
    – Hovercraft Full Of Eels
    Nov 7 at 20:37















up vote
-2
down vote

favorite









up vote
-2
down vote

favorite












This question already has an answer here:




  • Error message “unreported exception java.io.IOException; must be caught or declared to be thrown”

    5 answers




My code for reading an input stream of numbers and sorts them into an array, returns
error:



unreported exception IOException; must be caught or declared to be thrown



on String lines = br.readLine();



 public int inputArr()  {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String lines = br.readLine();
String strs = lines.trim().split("\s+");
int a = new int [strs.length];
for (int i = 0; i < strs.length; i++) {
a[i] = Integer.parseInt(strs[i]);
}
return a ;
}


Any help please on this?










share|improve this question














This question already has an answer here:




  • Error message “unreported exception java.io.IOException; must be caught or declared to be thrown”

    5 answers




My code for reading an input stream of numbers and sorts them into an array, returns
error:



unreported exception IOException; must be caught or declared to be thrown



on String lines = br.readLine();



 public int inputArr()  {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String lines = br.readLine();
String strs = lines.trim().split("\s+");
int a = new int [strs.length];
for (int i = 0; i < strs.length; i++) {
a[i] = Integer.parseInt(strs[i]);
}
return a ;
}


Any help please on this?





This question already has an answer here:




  • Error message “unreported exception java.io.IOException; must be caught or declared to be thrown”

    5 answers








java arrays input compiler-errors






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 7 at 20:33









A.Cvijanovic

21




21




marked as duplicate by Hovercraft Full Of Eels java
Users with the  java badge can single-handedly close java questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 7 at 20:36


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.






marked as duplicate by Hovercraft Full Of Eels java
Users with the  java badge can single-handedly close java questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 7 at 20:36


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.














  • Either you add a throws IOException to your method signature or you try {} catch (IOException e) {} it... You have those two options to report possible Exceptions.
    – deHaar
    Nov 7 at 20:34












  • Please Google your error message (please click on link) before asking as most questions have been asked before, and in this case many times before.
    – Hovercraft Full Of Eels
    Nov 7 at 20:37




















  • Either you add a throws IOException to your method signature or you try {} catch (IOException e) {} it... You have those two options to report possible Exceptions.
    – deHaar
    Nov 7 at 20:34












  • Please Google your error message (please click on link) before asking as most questions have been asked before, and in this case many times before.
    – Hovercraft Full Of Eels
    Nov 7 at 20:37


















Either you add a throws IOException to your method signature or you try {} catch (IOException e) {} it... You have those two options to report possible Exceptions.
– deHaar
Nov 7 at 20:34






Either you add a throws IOException to your method signature or you try {} catch (IOException e) {} it... You have those two options to report possible Exceptions.
– deHaar
Nov 7 at 20:34














Please Google your error message (please click on link) before asking as most questions have been asked before, and in this case many times before.
– Hovercraft Full Of Eels
Nov 7 at 20:37






Please Google your error message (please click on link) before asking as most questions have been asked before, and in this case many times before.
– Hovercraft Full Of Eels
Nov 7 at 20:37














1 Answer
1






active

oldest

votes

















up vote
0
down vote













BufferedReader.readLine() throws an IOException:



public String readLine() throws IOException {


So any call to it must handle it by either:




  • Surrounding with try/catch block

  • Declaring that your method also throws that exception.






share|improve this answer




























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    0
    down vote













    BufferedReader.readLine() throws an IOException:



    public String readLine() throws IOException {


    So any call to it must handle it by either:




    • Surrounding with try/catch block

    • Declaring that your method also throws that exception.






    share|improve this answer

























      up vote
      0
      down vote













      BufferedReader.readLine() throws an IOException:



      public String readLine() throws IOException {


      So any call to it must handle it by either:




      • Surrounding with try/catch block

      • Declaring that your method also throws that exception.






      share|improve this answer























        up vote
        0
        down vote










        up vote
        0
        down vote









        BufferedReader.readLine() throws an IOException:



        public String readLine() throws IOException {


        So any call to it must handle it by either:




        • Surrounding with try/catch block

        • Declaring that your method also throws that exception.






        share|improve this answer












        BufferedReader.readLine() throws an IOException:



        public String readLine() throws IOException {


        So any call to it must handle it by either:




        • Surrounding with try/catch block

        • Declaring that your method also throws that exception.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 7 at 20:36









        Mike

        1,174716




        1,174716















            這個網誌中的熱門文章

            Academy of Television Arts & Sciences

            L'Équipe

            1995 France bombings