Won't recognise code in try block

I've got a try block which has a line of code in it as shown:
     public static String ProcessUserInput(){          
          BufferedReader kbd = new BufferedReader(new InputStreamReader(System.in));
          try{
     String line = kbd.readLine();
catch (IOException ex)
System.out.println( "Error reading keyboard input." );
return line;
When i compile this it gives me this error:
cannot resolve symbol
symbol : variable line
location: class UserException
return line;
It seem like it does not recognise what is in the try block why is this.

A variable's scope--the piece of your code where it's visible--is the nearest enclosing block. In this case, line is only visible in the try block.
String line = null;
try {
    line = kbe.readLine();
catch (...) {
return line;Side note: Just printing an error message is NOT the way to handle exceptions. First, it lets subsequent code continue executing as if everything's fine--you've taken away its way of knowing that things are NOT fine. You should either actually handle the exception (by providing some default behavior, or retrying), or else just let it be thrown, or wrap it and rethrow it.

Similar Messages

  • GREP style won't recognise codes for Uppercase?

    I've tried [A-Z] and \u and can't get them to work. I can use Find Change to get them.
    I want to GREP style words that are capitals and give them a no break - so they don't hyphenate.

    I'm an idiot never mind
    I was just doing \<\u and trying to add a No Break
    But that was adding the No Break char style to the first letter of the word
    What I needed was
    \<[A-Z]\w+
    Long day...

  • My iPad won't recognise my air printer, it is connected as I checked by typing in IP address into Safari, but when I try to print it just says cannot find any air printers.

    my Ipad won't recognise my printer. It is connected as I have typed the IP address into Safari which confirms connectivity. Spoken with canon who suggest it it is a problem with IOS not recognising the functionality. When I try to print it says cannot find any air printers. Printer is working via LAN set up on my laptop. Don't want to have to spend £25 to speak to an apple support team. Has anyone else experienced this problem. Printer is a canon MG 3250.

    A few things you could try:
    Reboot your modem/router.
    Turn your printer off then on again & make sure it's connected to the network.
    Reboot your iPad holding down the home & sleep/wake buttons simultaneously until the apple logo appears then release & let the iPad boot up normally.
    Try going into Settings on your iPad & select General->Reset->Reset Network Settings.
    Also, have a look at this:
    http://www.canon.ca/support_images/KB_Images/Shared_wifi_documents/How_to_Print_ Using_Apple_AirPrint_NEW.pdf

  • Oracle JSP Exception code too large for try block

    My jsp is exceeding the memory limit (64KB for Oracle 10g App server i think its the JVM limit),
    so it is throwing exception ,code too large for try block,how to over come this,I cant minimize the use of logic tags because it is business requirement.please help me out.

    I think you need to give a value to the attribute buffer in the <%@ page%> directive to solve the problem.
    There will not be any need of going for pagination then.
    buffer="none | 8kb | sizekb"The buffer size in kilobytes used by the out object to handle output sent from the compiled JSP page to the client Web browser. The default value is 8kb. If you specify a buffer size, the output is buffered with at least the size you specified.
    check the documentation at
    http://java.sun.com/products/jsp/tags/11/syntaxref11.fm7.html
    Uday

  • Compile time errors for large code in try-catch blocks

    Hi, Has anyone ever faced this problem of a compile time error, where the Java compiler returns with the following error that Code is too large for try block.
    I have about 5000 thousand lines in my try-catch block and am facing this problem. Please suggest possible solutions

    1) Are you sure that your try/catch blocks contain 5 million lines?! I seriously don't believe this.Sounds like generated code. The generator needs to be a bit cleverer. In particular, it seems to be generating repeated blocks of code that ought to be stuffed into methods somewhere.

  • Every time i try to sync my 4th gen ipod touch itunes won't recognise it and the ipod keeps beeping - is there anything I can do?

    This is really frustrating.  Every time i try to sync my 4th gen ipod touch itunes won't recognise it and the ipod keeps beeping - is there anything I can do? I've tried using different cables. Itunes works fine with my family members ipod's & iphones...

     The best way to manage your music when you have multiple iPods is to change the settings under "Options" so that you manually manage your music instead of it doing an automatic synch each time you connect.  To add only the songs you want, highlight them and then "click and drag" them to your iPod.  This way none of your daughter's music gets added and you're not in danger of deleting your playlist as well.  It will show you how many songs you've added and you can then click on your iPod to verify.  To delete her songs off your iPod now, click on the music tab under your iPod so show everything you have stored.  Find those songs you want to delete, click on them to highlight then go up to the Edit window and click delete. This will erase them off your iPod but be careful when you highlight.  I did that and then had to reload a cd on my boyfriend's, lol. hope this helps

  • Hi. Recently my iPad has been stolen I was wondering if I could give you the cereal code and try locate it or if you can wipe it or block it permanently so it cannot be used

    Hi. Recently my iPad has been stolen I was wondering if I could give you the serial code and try locate it or if you can wipe it or block it permanently so it cannot be used

    We are fellow users here on these forums, you're not talking to iTunes Support nor Apple.
    Unless you had Find My iPad enabled on it then there isn't any way to locate it. If you did have it enabled then you could try locating it either via http://icloud.com on a computer or Find My iPhone on another device - but that will only work if it's connected to a network and the device hasn't already been wiped and/or Find My iPad disabled on it (as your tagline shows iOS 7 then it should be harder to remove from your account).
    You've reported it to the police ? You should also change your iTunes account password, your email account passwords, and any passwords that you'd stored on websites/emails/notes etc., and if it was a cellular model then you should also contact your carrier.

  • I cloud password different from apple ID? won't recognise my password, so I reset it as want to give my phone to my daughter. Having MAJOR problems!!

    I want to give my old iphone4 to my daughter but it won't let me reset anything without my iCloud password. Unfortunately it did not recognise my password and when I requested to reset it I was taken to Apple ID. I changed the password but my email is not an iCloud one so it still won't recognise it or my original i cloud password. Help!! Apple have been no help at all....

    Hey! What way did you try to reset your iphone?
    The easiest thing (please correct me if i'm wrong now) is:
    settings, general, reset -> reset all ("contents and settings")
    You just need the unlock-code for this.
    What iOS are you running on that phone?
    If this doesn't help, please let us know!

  • BLACKBERRY TORCH - won't turn on and desktop manager won't recognise it - I can't get my contacts

    Hi all,
    I'm new to this so please bare with me.
    I'll try and be as brief as possible. Up until last week I had the Blackberry Torch 9800. I was due an upgrade and about two days before I went to contact my network provider my Torch battery died (it wasn't broken at this point, it just was drained and needed charged) so I went to charge it and it did that thing where the battery was so dead it wouldn't even switch on whilst charging.
    I plugged it in and rather than charge like normal it was completely dead and the only activity it offered me was two red flashing lights as it 'charged'. From that moment on it has not turned on. Dead as can be. If I plug to charge (wall charger OR USB port) I get the two bright red flashing notification lights but it will not go on.
    Anyway rather than send it to be repaired I opted for a new phone as I was due an upgrade anyway and intended on doing so whether the Torch was alive and kicking at this point or not. Cut a long story short I got my new blackberry (9360 curve) it is all set up with my e-mail etc, media card and same sim card swapped over but as Blackberry insist on your contact numbers being saved to the handset and not the sim my contacts are stuck in my Torch 9800.
    When I go to plug the Torch in to Desktop manager to get the contacts saved to there and then sync over to my new handset the Torch is so dead that DManager won't even read/recognise it. My network say since this is not an issue with network etc they can't really help and gave me a number for Blackberry services in England somewhere (they are office hrs so can't phone until Monday morning).
    Please can someone help? I have my new 9360 all up and running but my contacts are stuck in my Torch and that is the only place they are? DManager won't recognise the Torch because it is dead - except the two flashing lights - and therefore won't let me at the contacts that way.
    ANY help would be appreciated - please not too techinal as not great with all of that side of things!
    Sorry for the long post.
    Sco123.

    Sco123 wrote:
    Sorry for the long post.
    Sco123.
    Then let me counter with a short reply:
    www.blackberry.com/btsc/KB10144 .
    Cheers. 
    - If my response has helped you, please click "Options" beside my post and mark it as solved. Clicking the "thumbs up" icon near the bottom of my response would also be appreciated.

  • ITunes won't recognise my iPod on USB 2.0, only 1.1

    my computer won't recognise my iPod touch 1.1.4 when it is connected via my USB 2.0 PCI card, only when it is plugged in via the motherboards inbuilt USB 1.1 ports. I have plugged it into other computers (all pc's) and it works fine on their USB 2.0 ports.
    What could be causing this?
    cheers.

    Try this if you have not already. This removes and reinstalls ALL Apple software and sometimes that is required.

  • Old Itunes library (from PC) on external hard drive - Mac won't recognise

    I feel like I've tried absolutely everything, so hopefully someone here can help.
    I had my Itunes library stored on an external disc. This was when I was using Itunes on a PC. It all ran fine....
    Now we've upgraded to a Mac and for the life of me I cannot get Itunes to recognise the library.
    First I just tried changing the folder location with no luck. Now I've tried holding down alt when starting Itunes, I've located the folder, and at first it seemed all was well as the albums (sans artwork) all appeared in Itunes. But when I try to play them or send songs to my Iphone, it says it can't locate the file. I've tried to then manually point it to the external drive and the old library and it still won't recognise it.
    Can anyone suggest anything??

    AnnieeR wrote:
    Can anyone suggest anything??
    these two reads may be helpful: one and two.

  • Txt file read in- StringTokenizer- Try Block Catch for errors

    Hello
    So I am having a few issues with a school project. First is with my ReadWithScanner. It does not read in the file giving me a NullPointerException error on the line <Scanner in = new>. I have tried a few other read in files and they do not seem to be working.
    I am also stuck on the logic on the try block catch statement. How does a person set up a �custom� try block that looks for errors like the ones below? I have attempted to start in the commented code.
    The text file has to read in 1000 individual lines of code and are separated by �;� and should be separated into tokens with the StringTokenizer class what I attempted to do below also. Both are mere attempts and need help�
    This is some what of the logic I thought of doing
    1.Read the first line in first with the scanner class
    2.use delimiter separated by �;�
    3.Tokenizer the line into separate tokens- invoiceCode, fName, lName�
    4.Check classes- check Name, check Date, checkPrice, checkPrice, checkGenre, checkShippingDate invoiceCode = "Error Code" checkInvoiceCode(String invoiceCode)checkName(String name), checkPrice(String price), checkGenre(String genre)
    5.Apply the regular expressions to each try block statement
    a.Assign a letter to each error for example if invoice was to short it would be assigned a letter A
    b.If invoice does have the right characters it would be assigned B
    c.If name has to few words it would be assigned D
    d.�
    This is an example of a good field from the text file
    XYG726;Smith,Mr. John M.;29.96;comedy;101008;100604
    Not so good line
    Lu15;Will, Mark;50.00;Science;030305;030807
    The file should then be printed out in the program not to a text file. It only needs to print the invoice number and error code letter assignment.
    If you have any questions feel free to let me know. Thanks for all or any help you have to offer.
    Invoice
    Three upper case letters followed by three digits
    Regular Expression "[A-Z]{3}[0-9]{3}"
    Customer Name
    Should be in the form: last name followed by a <,> optional title (Mrs. Mrs�) then first name optional middle initial Titles must be
    So regular expression something like �[a-z][A-Z]+([A-Z]{1}?[a-z][./})+[a-z][A-Z]�
    Sale Price
    Two decimal digits to the left of the decimal point. The price should not have a leading zero.
    Regular Expression [0-9]{2}*./[0-9]
    Genre
    The genre should only contain lowercase letters. Regular expression �[a-z]�
    ShipDate and Order Date-
    Must be standard dates- MMDDYY. The order date and shipping date has to be after today�s date. Regular expression �[0-9]{2}+[0-9]{2}+[0-9]{2}�
    package Project3;
    import java.util.StringTokenizer;
    import java.util.regex.Matcher;
    import java.util.regex.Pattern;
    import java.io.*;
    import java.util.Scanner;
    public class ReadWithScanner {
    private final File fFile;
    public static void main (String args[]){
    Scanner in = new Scanner(new File("e:\\work_space_java\\Project\\Package3\\movie.txt"));
    Scanner.processLineByLine();
    public ReadWithScanner(String aFileName){
    fFile = new File(aFileName);
    public final void processLineByLine(){
    try {
    //use a Scanner to get each line
    Scanner scanner = new Scanner(fFile);
    while ( scanner.hasNextLine() ){
    processLine( scanner.nextLine() );
    scanner.close();
    catch (IOException ex){
    protected void processLine(String aLine){
    //use a second scanner again to raed the content of each line
    Scanner scanner = new Scanner(aLine);
    scanner.useDelimiter(";");
    if (scanner.hasNext() ){
    //read each file?
    String name = scanner.next();
    String value = scanner.next();
    else {
    scanner.close();
    //Token Names that are seperated
    StringTokenizer st;
    String invoiceCode = st.nextToken();
    String fname = st.nextToken();
    String lname = st.nextToken();
    String price = st.nextToken();
    String genre = st.nextToken();
    String orderDate = st.nextToken();
    String shipDate = st.nextToken();
    String invoiceCode;
    invoiceCode = "A" checkInvoiceCode(String invoiceCode);
    Pattern p = Pattern.compile("[a-z]{6}[A-Z]{6}[0-9]{6}");
    Matcher m = p.matcher(invoiceCode);
    p.matcher(invoiceCode);
    if(m.matches()) {
    System.out.println(invoiceCode);
    else {
    System.out.println ("A");
    try
    invoiceCode = Integer.parseInt(String);
    catch (NumberFormatException e)
    { System.out.println ("B"); System.exit(1); }
    */

    I have made a quite a few updates to my code. Please look it over again. I have also made many comments to help with the logic. Once again if you have any questions please feel free to ask. Sorry about not using the tags before- I was no aware of them. Thanks for the advice sabre150.
    package Project3;
    import java.util.StringTokenizer;
    import java.util.regex.Matcher;
    import java.util.regex.Pattern;
    import java.io.*;
    import java.util.Scanner;
    public class ReadWithScanner {
         private final File fFile;
         public static void main (String args[]){
                   //read in text file from directory currently it can not read the file
                  Scanner in = new Scanner(new File("e:\\work_space_java\\Project\\Package3\\movie.txt"));
                  //Scans each line of the text in
                  Scanner.processLineByLine();
                //assigns new file name to file
                public ReadWithScanner(String aFileName){
                  fFile = new File(aFileName); 
                public final void processLineByLine(){
                  try {
                    //use a Scanner to get each line from the processLineByLine
                    Scanner scanner = new Scanner(fFile);
                    while ( scanner.hasNextLine() ){
                      processLine( scanner.nextLine() );
                    scanner.close();
                  catch (IOException ex){
                protected void processLine(String aLine){
                  //use a second scanner again to read the content of each line
                   //delmiter should then break each line in the text file into seperate "tokens"
                  Scanner scanner = new Scanner(aLine);
                  scanner.useDelimiter(";");
                  if (scanner.hasNext() ){
                       //reads each line from scanner
                    String name = scanner.next();
                  else {
                  scanner.close();
               /*Convert Tokens from Scanner into String Tokenizer with assigment to each variable
                * I am missing something
                * Need to convert each line read from the scanner (name variable) to the String
                * Tokenizer class
              //Tokens names now assigned a varaible
              StringTokenizer st;
              String invoice = st.nextToken();
              String name = st.nextToken();
              String price  = st.nextToken();
              String genre = st.nextToken();
              String orderDate = st.nextToken();
              String shipDate = st.nextToken();
          /*If statments (Try Block Statements?) with Regular Expressions
          * This is where I have the most issues on how to set up
          * "custom" try and block errors trying to match what I have
          * in the regular expressions. 
          * I believe try and catch statements
          * make this easier but I have used 'match' and 'pattern' with if
          * statments.  If try block statements are easier please show!
          * Regular Expressions may not be correct either
           invoice = checkInvoiceCode(invoice);
           //Defined cerita for Inovice are:
           //Error A = Invoice code is too short  
           //Error B = Invoice code does not have the right characters 
           //Error C = Invoice code digits are all zero
           //Checks for error A
           //Has at least six characters
            Pattern invoiceShort = Pattern.compile("{6}");
            Matcher shortInvoice = invoiceShort.matcher(invoice);
            p.matcher(invoiceCode);
            if(m.matches()) {
                 System.out.println(invoice);      
            else {
                 System.out.println ("A");
            //Checks for error B
            //3 Upper Case Letters followed by three numbers,
            Pattern rightChar = Pattern.compile("[A-Z]{3}[0-9]^0{3}");
            Matcher charRight = rightChar.matcher(invoice);
            p.matcher(invoiceCode);
            if(m.matches()) {
                 System.out.println(invoice);
            else {
                     System.out.println ("B");
            //Checks for error C
            //Where the last three digits are not all zeros
            Pattern notZero = Pattern.compile("*{3}^0{3}");
            Matcher ZeroNot = notZero.matcher(invoice);
            p.matcher(invoiceCode);
            if(m.matches()) {
                 System.out.println(invoice); 
                 else {
                     System.out.println ("C");
         //name = checkFullName(name);
         //Error D = Name field has fewer than two words
         //Error E = Name field has more than four words
         //Error F = Name field has no comma
         //Error G = Name field has a bad title 
         //Error H = Name field has a bad initial 
        /*Have a lot more to do...
        * Still need to go through the same if statement or Try Block statements with this data:
        *      String fname = st.nextToken();
              String lname = st.nextToken();
              String price  = st.nextToken();
              String genre = st.nextToken();
              String orderDate = st.nextToken();
              String shipDate = st.nextToken();
        * But for now I would like to see an example of an if statement I could use
        * (if mine is even right) or catch statement- the rest of the project we look
        * for similar certia as defined in the reg exp for invoice
         /*Writes to Report in the Console
         * Prints data into two columns:
         * Invoice Code and Error Type
         //Prints both column Headings
         private void columnHeadings ()
         System.out.println (padL("",5) +
         padL("Invoice",20) +padL("",20)+
         padL("Error Code",40));
         //movie is the name of the text file
         private void printMovie(Movie aReport) {
         System.out.println(aReport.getInvoiceCode()+"\t"+
               aReport.getErrorType()+"\t");
      *This method pads the string start to the length newLength leaving the
      *string left justified and returning the result.
      private String padL (String start, int newLength)
         String result = new String (start);
         while (result.length() <= newLength) result += " ";
         return result;
      } // end padL
       * This method pads the string start to the length newLength leaving the
       * string right justified and returning the result.
      private String padR (String start, int newLength)
         String result = new String (start);
         while (result.length() <= newLength) result = " " + result;
         return result;
    // end padRThanks a lot.

  • Handling socket exception - Retrying a "try" block

    I have a program which attempts to retrieve an object through a socket. However sometimes I get the following exception:
    java.net.SocketException: Connection reset
    This is a problem as I need the object to continue program execution.
    An overview of the code is:
    try {
                UrlServerObject crawlUrlObj = getUrlToCrawl();
                // Download webpage at the url returned by getUrlToCrawl()
                webpage = loadPage(crawlUrlObj);
    catch(java.net.SocketException ex) {
              System.err.println("An exception occurred.\n" +
                        "The exception was: " + ex.toString());
            }The getUrlToCrawl() method simply opens a socket a communicates with a server which sends back an object.
    My question is what is the best way to catch the exception and "retry" the complete "try" block until an object is read?
    Thanks

    When you say a loop, do you mean something along the
    lines of:
    boolean gotUrl = false;
    while(!gotUrl) {
    UrlServerObject crawlUrlObj = getUrlToCrawl();
    if(crawlUrlObj != null) gotUrl = true;
    }The exception would be thrown in the catch block
    still though?getUrlToCrawl is presumably the code you originally posted? Yep, that's about the size of it. Although I wouldn't keep trying until you got a URL, you should consider the possibility that there isn't one, and deal with that. I'd try it a set number of times, and move on after that

  • Return statement inside try block

    what is wrong if i write code like as below...please explain me since i am new to java
    class sample{
    public String method(){
    try{
    String str="abc";
    return abc;
    catch(Exception e){}
    }

    veldhanas wrote:
    return abc;In your code there is no varible declared as abc. It is a value assigned in str.
    Suppose if the code in try statement throws exception the return statement is skipped and the
    associated catch block will get executed. So your catch block must return a result of type String.... or throw another (or the same) exception.
    In this case, since there's no way the code in the given "try" block can throw an exception, it would have been better to not even have a try/catch block in the first place.
    And almost never just swallow exceptions like that (an empty catch block). There are only a few cases where it's ok to swallow them (such as in finally blocks where you're cleaning up resources which may throw exceptions while cleaning up, and you want to continue cleaning up and ignore those kinds of exceptions).

  • My iMac won't recognise blank cd-r's.

    My Imac, mid 2007, processor 2.8 GHz Intel Core 2 Duo won't recognise black cd's.  It will recognise normal cd-r's and dvd's but not blank cd-r's.  The cd drive makes a whiring sound like it's trying to accept the cd-r, then after 5-6 seconds, to ejects it again.

    black
    Typo?
    Another help source (if you haven't already done so).
    Go to your OS Help Menu.  In the search field type dvd
    Click on all the troubleshooting topics & Support Articles that pertain to  your issue.
    You can also do the same in Disk Utility.  Open same up.
    At the bottom left of the window, click on the purple button w/the "?" in the middle.
    This will bring up the Help Menu.
    ===============
    Try a different brand.  Top forum favorites
    CDs
    FUJI
    TDK
    Verbatim
    DVDs
    Maxell
    Verbatim
    ==============
    Apple's Disc Burning Quick Assist
    http://support.apple.com/kb/HT2801 Apple Computers: Troubleshooting the slot-loading SuperDrive
    *** Your drive may need cleaning.  Cleaning kits can be purchased from any store that sells CD/DVDs. ***

Maybe you are looking for

  • Restoring--Argghh! Why does everything have to be so difficult?

    I have been thrilled with my new iPhone for almost a month now, however it has crashed completely twice over the last couple of days, (Just the Apple Logo even after a Home/Power reset) It crashed once when I connected to computer and instructed it t

  • IPhoto Transfer to External Hard Drive

    I'm trying to export about 10000 pics and vids from iphoto to an external hard drive.  Each time I try about 500 files won't copy and I get an error message for each. Short of copy down each file and moving them over separately, is there something el

  • When I'm on a Skype, Mac Air display won't sleep?

    I often have a Skype call connected as my boyfriend and I are having a long distance. The display would sleep when I was having a call and out of the room when I was using OS X 10.6.8 but since I've changed to use mountain Lion 10.8.2, It won't sleep

  • Colums aren't displayed in column chart

    Hello, I have a problem with Xcelsius. It's not displaying the columns of my column chart in the preview and in the excel-export. The legend is being displayed. Thx for answering, Simon

  • Lync 2013 IP Phone error getting web ticket

    Hi, I have been unable to get a Polycom CX500 phone working on our network (first IP phone), the phone connects but gets "an account matching this phone number cannot be found" I have run the DHCP commands through and everything looks OK and all opti