Can not return a String

Why can't I return the String e?
public String test()
      String t;
      try
           // some code that requires a try statement
           t = "test";
       }catch(Exception e) { System.out.print(e.getMessage()); }
       return e;
}The return statement complies about that variable e "might not have been initialized". But it is initialized in the try statement. I don´t see the logic.

Roxxor wrote:
Why can't I return the String e?
public String test()
String t;
try
// some code that requires a try statement
t = "test";
}catch(Exception e) { System.out.print(e.getMessage()); }
return e;
}The return statement complies about that variable e "might not have been initialized". But it is initialized in the try statement. I don´t see the logic.for starters, e is an Exception, not a String.
I think you mean to do something more like this:
public String test()
      String t = null;
      try
           // some code that requires a try statement
           t = "test";
      catch(Exception e)
         System.out.print(e.getMessage());
         t = e.getMessage();
       return t;
}when the compiler tells you something, believe it.
%

Similar Messages

  • Good morning a few weeks ago  I send the request for the replacement program of my ipod nano 1st generation and they sent me the shipping box but I did not get the label to go back,  and I can not  return it , i need to you sent me again the box for retu

    Good morning a few weeks ago  I send the request for the replacement program of my ipod nano 1st generation and they sent me the shipping box but I did not get the label to go back,  and I can not  return it , i need to you sent me again the box for return the ipod

    Best thing would be to call Apple up again, and let them what has happened and they'll help you!

  • Delphi 4 can not move a string to VARCHAR2 field

    Hi,
    I'm using Oracle 8 version 8.0.4.0.0 and Delphi 4. I can not move a string data (20 characters) over VARCHAR2 field, so I'm also using the BDE (5.11) and ODBC to do this. The message sent by Delphi is 'Operation not applicable'.
    TIA,
    Roberto.

    Hi,
    I'm using Oracle 8 version 8.0.4.0.0 and Delphi 4. I can not move a string data (20 characters) over VARCHAR2 field, so I'm also using the BDE (5.11) and ODBC to do this. The message sent by Delphi is 'Operation not applicable'.
    TIA,
    Roberto.

  • I can not return the version stored in the ICloud

    I can not return the version stored in the ICloud  for new IPhone

    What exactly are you trying to do?  Restore from an icloud backup?  If so what error message are you getting?
    Giving more details about your issue would go a long way.

  • Spry can not  parse xml string

    while designind an mvc architecutre in php I found display
    data on site was slow so I generate a xml sheet an used spry Data
    loading was fast an dproduced and I also performed many operations
    like sorting ,galeery making ..etc... but main thing is that I can
    not parse a xml string using spry only a xml file can be parsed
    my application required to parse xml string

    I'm not sure if this is valid in your situation, but OC4J comes with Oracle XMLParser.
    Simply use the JAXP API to parse/build/modify XML and the Oracle XMLParser implementation will be used behind the scenes.
    If you must use xerces/xalan, try putting the jars in OC4J_HOME/j2ee/home/lib instead.
    HTH //Anders

  • Webservice not returning a String

    I am running this block of code against an asp.net web
    service. When I test the service through Internet Explorer, it
    returns;
    <string xmlns="
    http://tempuri.org/">Success</string>
    So I know its return "Success" as a String. I created
    wsOwners as a String variable and set it to the result of the
    webservice. I set the result to a label to make sure it is working.
    The the label displays;
    [object asyncToken]
    How do I get the result to display "Success" and why is it
    displaying that object message?
    private function newOwner():void
    var wsOwners:WebService = new WebService();
    wsOwners.wsdl = "
    http://localhost:1711/Owners/Owners.asmx?WSDL";
    wsOwners.loadWSDL();
    var wsResult:String = wsOwners.NewOwner(tbxFirstName.text,
    tbxLastName.text,
    tbxAddress1.text,
    tbxAddress2.text,
    tbxCity.text,
    tbxState.text,
    tbxZip.text,
    tbxCountry.text,
    tbxPhone.text,
    tbxFax.text,
    tbxEmail.text);
    lblResult.text = wsResult;

    you have to wait for the web service to return before the
    result will be loaded. i haven't used WebService, but the way
    you're using it looks like you expect it to be a synchronous call,
    where in fact it is asynchronous.
    you probably have to register a callback on the complete or
    result event and set your text there.
    ./paul

  • When visiting some sites i can not return without quiting and opening foxpro a second time

    When I got to some sites and then click the down area to return where I was before is not available and I have to quit the site and open foxpro all over again.

    Step by step, how did you arrive at seeing this agreement?

  • Why my method can not receive the string from JNI

    JNIEXPORT jstring JNICALL Java_playaudio_BeatTrack_myBeatTrack
    (JNIEnv *env, jobject obj, jstring wavfile)
    const char* filename = env->GetStringUTFChars(wavfile,0);
    BeatTrack(filename);
    env->ReleaseStringUTFChars(wavfile,filename);
    return NULL;
    }for my BeatTrack method, I just need the filename, then it can run, if I comment the BeatTrack(filename);, then no problem, for the java calling, of course, my BeatTrack(const *char filename) has no problem, cause I have test it,,
    but I call this method in java, the error is as follows,
    Java VM: Java HotSpot(TM) Client VM (10.0-b19 mixed mode, sharing windows-x86) # Problematic frame: # C [beattrack.dll+0x130b] # # An error report file with more information is saved as: # D:\programs\playAudio\hs_err_pid11684.log # # If you would like to submit a bug report, please visit: # http://java.sun.com/webapps/bugreport/crash.jsp # The crash happened outside the Java Virtual Machine in native code. # See problematic frame for where to report the bug. any idea??

    1) What class is "missing?"
    2) Where is it?

  • All of a sudden, my display screen with fox fire enlarged, I can not return it to the original size, can not find the button to reduce it. If I go on line with Internet Explorer, the page size is normal?

    I thought it might have happened with an update - I used the
    computer software to look for any problems - I turned the power off and on again, fired irefox back up and still get the large display?

    I don't have ML so I can't comment on the back button but the problem with screen size may be a matter of you scrolling while pressing the CMD or CTRL buttons.     You should be able to adjust which of these to use through Systems Pref > Mouse and then Zoom control in the bottom box.

  • How can i read a string with nextToken() of StreamTokenizer

    I need for my class paper to read a string from a file and i used the StreamTokenizer's method nextToken but i can not read a string with it. my code is:
    StreamTokenizer st = new StreamTokenizer(the code that gets the input from the file)
    String line;
    while ((line !=br.readLine()) != null) {
    String surname = (st.nextToken()).trim();
    but it gets me some error of:
    int can not be dereferenced
    what should I do to get the string i need?

    Look at the API for java.io.StreamTokenizer. In particular, look at the return type for nextToken().
    Good luck.

  • Help!!urgent!!can not insert/update clob:the row containing the lob is not locked

    Hi,
    could you do me help?
    i can not insert a string into a oracle clob field, it echo as:
    ORA22920 row containing the lob value is not locked. ORA 06512 at "SYS.DBMS_LOB" line 708
    ORA 06512 at line 1;
    what its means? please.
    my table defined as : create table clob1(id number(5),mclob clob default empty_clob()); the id is create by a sequece of test_sequence automaticly.
    my code as belows:
    import java.io.*;
    import java.sql.*;
    //import oracle.sql.*;
    public class test4 {
    public static void main(String args[]) {
    String url_String
    = "jdbc:oracle:thin:test/test@myhost:1521:myorcl";
    try {
    Class.forName
    ("oracle.jdbc.driver.OracleDriver");
    java.sql.Connection con =
    java.sql.DriverManager.getConnection(url_String);
    con.setAutoCommit(true);
    Statement stmt
    =con.createStatement();
    String sqlStr ="insert into
    clob1 (mclob) " + "values(empty_clob())";
    stmt.executeUpdate(sqlStr);
    String query = "select
    test_seq.CURRVAL from dual";
    ResultSet rs =stmt.executeQuery
    (query);
    rs.next();
    int currval =rs.getInt(1);
    query = "select * from clob1 where
    id="+currval;
    String str
    ="abcedefhijklmnopqrstuvwxyz";
    rs =stmt.executeQuery(query);
    rs.next();
    java.sql.Clob clob1
    =rs.getClob(2);
    oracle.sql.CLOB clob=
    (oracle.sql.CLOB)clob1;
    System.out.print(clob);
    java.io.Writer
    wr=clob.getCharacterOutputStream();
    wr.write(str);
    wr.flush();
    wr.close();
    stmt.close();
    con.close();
    } catch(Exception ex) {
    System.err.println("SQLException: "
    + ex.getMessage());
    null

    Hi,
    To avoid ORA-22920 error while selecting lob column, use the 'for update' clause in the select statement like :
    query = "select * from clob1 where id="+currval+" FOR UPDATE" ;
    This should solve the problem. However, after fixing this, you might get the error :
    java.sql.SQLException: ORA-1002: fetch out of sequence
    I got this error when testing your code. To avoid this error, before executing 'select ... for update' statement Set AutoCommit to OFF, like :
    query = "select * from clob1 where id="+currval+" FOR UPDATE" ;
    con.setAutoCommit(false);
    rs =stmt.executeQuery(query);
    Hope that Helps,
    Srinivas

  • How can I return my Bookmarks from esktop back to Firefox Bookmarks

    For some reason ( unknown to me) the bookmarks in Firefox were sent to my Desktop and I can not return them back to the Bookmarks in Firefox. Would appreciate any assistance in accomplishing the return of my Bookmarks.

    Hello,
    Firefox automatically creates backups of your bookmarks, which can be helpful if your bookmarks are lost or missing. To recover them, follow the instructions below.
    #Use <u>one</u> of these methods to open the Bookmarks Library window:
    #*Click the ''[[Display the Firefox button menu instead of the menu toolbar|Firefox button]]'' to open the menu and click on ''Bookmarks''.
    #*Click the ''Bookmarks'' menu and click on ''Show All Bookmarks''.
    # At the top of the Library window, click the "Import and Backup" menu and select Restore.
    # Click the date of the bookmark backup you want to recover.
    # In the new window that appears, click OK.
    # Your bookmarks from the selected date should now be restored.
    For more information, see the [[Restore bookmarks from backup or move them to another computer]] article. For other solutions, see the [[Recover lost or missing Bookmarks]] article.
    Did this fix your problems? Please report back to us!
    Thank you.

  • Please, help .. return not working. string can not be resolved to a variabl

    Greetings..
    I am writing a Java code that encrypt a String using DES. After encryption, I want to return the String, but I get error that says: variable can not be resolved. Please, help me to find out what is the problem ?? Thanks in advance.
    Here is the code:
    import javax.crypto.*;
    import java.security.*;
    public class Client {
         public String DESEncrypt(String cardnum)
              try{
              //create cipher object for DES
              Cipher c=Cipher.getInstance("DES");
              // craete the symmetric key for DES
              KeyGenerator kg=KeyGenerator.getInstance("DES");
              Key key=kg.generateKey();
              // DO the ecryption steps then display the result
              c.init(Cipher.ENCRYPT_MODE, key);
              //Dofinal accepts byts only. Thats why we use getbytes method.
              byte[] cardNoBytes=cardnum.getBytes("UTF8");
              //get the encrypted bytes
              byte[] encryptedCardNoBytes=c.doFinal(cardNoBytes);
              //convert bytes to string
              String cardNoString=new String(encryptedCardNoBytes);
              } catch(Exception e){ System.out.print("Error");
              return cardNoString;
         } //end the DESEncrypt method
    public static void main (String[] args) {
    try{
         Client cl=new Client();
         String x2=cl.DESEncrypt("123");
         System.out.println("The Encrypted text using DES is: " + x2+'\n');
    } catch(Exception e){ System.out.print("Error");
    }//end main
    }

    Next time, paste in the exact, complete error message and indicate clearly exactly which line is causing it.
    Your problem is that you declare cardNoString inside the try block, but you try to return it outside. Local variables only exist in the narrowest block in which they're declared. Once you exit try, that variable does not exist.
    You also have a logical problem. If an error occurs, you're just printing out :"Error", but you're not actually handling it. You're going on as if everything is fine. Catching an exception doesn't fix the error. If you can't fix it, don't catch it.
    What do you think your method will return if an exception occurs before you set cardNoString? What do you think it will do to the caller to have some arbitrary, meaningless value returned when he thinks everything went fine and he got a valid result?

  • Can not make a jax-rcp web service returning string[][]

    I want to return a string[][] from my web service, but when trying to do it with Jdeveloper it says:
    The return type java.lang.String[][] of method
    <my method> cannot be serialized into XML, and no
    custom serializer has been defined for it.
    How can i define a serializer for the array???

    I got the Same problem and only today i tried web services
    Is it right to do this way.
    If so Please See the thng i've done.
    Otherwise Please Suggest alternatives
    I created Two Projects
    1. Web Service
    2. Web Client.
    A Bean (It is in Web service Project)
    public class Results
    private int sum;
    private int difference;
    private int multi;
    private float division;
    /** Creates a new instance of Results */
    public Results ()
    public Results (int sum,int difference,int multi,float division)
    this.difference=difference;this.division=division;
    this.multi=multi;
    this.sum=sum;
    A Service Method
    public class myService
    // It works Fine in the client
    @WebMethod
    public int addTwoNumbers (@WebParam(name = "var1") int var1, @WebParam(name = "var2") int var2)
    // TODO implement operation
    return var1+var2;
    // How do Get this Stuff Work at the Client
         @WebMethod
    public Results getResults (@WebParam(name = "var1") int var1, @WebParam(name = "var2") int var2)
    Results aResult=new Results((var1+var2),(var1-var2),(var1*var2),(var1/var2));
    return aResult;
    Now, How do I get this working in the Client.
    In the Ide Get get Error (Using Netbeans5.5 -Tomcat).

  • TS4002 I bought iPad and I can not access, A message appears asking me account and password when i return to the person who I purchased it from him, he told me that he forgot the account and password I want a solution to the problem, because in this way I

    I bought iPad and I can not access, A message appears asking me account and password when i return to the person who I purchased it from him, he told me that he forgot the account and password
    I want a solution to the problem, because in this way I will not benefit from the iPad

    There is no solution.  You have to provide the ID and password.  There is no way around it.  If the person you bought it from can't provide it, return it and get your money back.

Maybe you are looking for