Unreported exception java.rmi.RemoteException; must be caught or declared t

I am receiving an:
unreported exception java.rmi.RemoteException; must be caught or declared to be thrown
error when I attempt to compile the Client.java file.
The Client.java file implements the ATMListener.java interface.
As you will see below, I've stripped them down by taking out all of the code, yet I still receive this error.
Any ideas...
ATMListener.java
import java.rmi.*;
import java.rmi.server.UnicastRemoteObject;
* @author Eddie Brodie
* @version %I%, %G%
public interface ATMListener extends java.rmi.Remote
Client.java
import java.net.MalformedURLException;
import java.rmi.Naming;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;
import java.rmi.UnknownHostException;
public class Client extends java.rmi.server.UnicastRemoteObject implements ATMListener

Well first off unless I am missing something in the API java.rmi.Remote is an interface not a class so implements not inherits, but I do not really know these classes so I cannot be sure I am not missing something.
As for the unreported exception. What could be causing something like this would be an exception thrown by the constructor of the parent class. Even if you have no constructor written for your class it still has a default constructor which will by default call the super constrcutpor meaning an exception could be thrown from the super constrcutor down to your default constructor where you would not know what to do with it.

Similar Messages

  • Unreported exception; java.sql.SQLException; must be caught or declared to

    Hi everyone,
    For my Java course assignment we need to make a small application that uses a MS Access database. But de code below gives me a "Unreported exception; java.sql.SQLException; must be caught or declared to be thrown at line xx" error.
    public class ConnectieBeheer
      private static Connection con;
      private static Statement stmt;
      private static ResultSet res;
      private static ResultSetMetaData md;
      private ConnectieBeheer(){}
      public static void openDB() {
        Driver driver = new JdbcOdbcDriver();
        Properties info = new Properties();
        String url = "jdbc:odbc:theater";
        con = driver.connect(url, info);       <--- Error here
        if (con != null)
          stmt =  con.createStatement();      <--- Error here
          DatabaseMetaData dma = con.getMetaData();      <--- Error here
      }So I tried this :
    public static void openDB() throws SQLException {Now I do not get an error.
    The OpenDB method is called from a different class like this :
      public static void test1(){
        ConnectieBeheer.openDB();
        System.out.println("DB opened");
      }But now it gives the same "Unreported exception; java.sql.SQLException; must be caught or declared to be thrown at line xx" error but now at the line ConnectieBeheer.openDB();
    Why is this? And what can I do to correct this?
    Thanks!
    Steven.

    you should read the sun tutoriel about exceptions handling ;
    there are two ways to handle an exception : either you redirects it (using "throws" statement, what you did for the openDB method), or you catch it using a try { ... } catch (Exception exc) {}
    if you want to get rid of the error what you can do is :
      public static void test1(){
        try {
            ConnectieBeheer.openDB();
        } catch (java.sql.SQLException sqle) {
            sqle.printStackTrace();
        System.out.println("DB opened");
      }

  • Unreported exception java.sql.SQLException; must be caught or declared to b

    I dont know much about java Please help.
    I have created following class
    import java.sql.*;
    public class Updatedb{
         private String cofeename ;
         private int supid;
         public void getfields(String COFNAM , int SUP_ID){
              cofeename = COFNAM;
              supid = SUP_ID;
         public void indb()
         throws SQLException {
              Connection con = null;
    PreparedStatement pstmt = null;
         try {
         con = DriverManager.getConnection("jdbc:odbc:myDataSource");
         pstmt = con.prepareStatement(
    "UPDATE COFFEES SET SUP_ID = " + supid + "WHERE COF_NAME =" + cofeename );
    //pstmt.setInt(1, SUP_ID);
    //pstmt.setInt(2, COFNAM);
    pstmt.executeUpdate();
    finally {
    if (pstmt != null) pstmt.close();
    Now I am calling above class when button is clicked
    private void UPDATEActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_UPDATEActionPerformed
    // TODO add your handling code here:
    String input = INPUTFIELD.getText();
    Updatedb updateclass = new Updatedb();
    updateclass.getfields(input , 20);
    updateclass.indb( );
    INPUTFIELD.setText( "" );
    I am getting above error. Please help me to solve it.
    Thanks in advance

    A word of honest advice: If you don't understand much of Java, and specifically, if you don't understand how checked exceptions work, you're in over your head looking at JDBC. Step away from it for now, and learn the basics a bit better. Seriously, if you soldier on this way, you'll never really understand what you're doing

  • Java.lang.Exception,java.rmi.RemoteException

    Hi ,
    Whem I'm deploying my appliucation on WLS 10.3 I'm getting the following exception.
    ####<Nov 13, 2008 1:32:21 PM IST> <Warning> <EJB> <swetha> <AdminServer> <[STANDBY] ExecuteThread: '1' for queue: 'weblogic.kernel.Default (self-tuning)'> <<WLS Kernel>> <> <> <1226563341175> <BEA-012035> <The Remote interface method: 'public abstract java.util.Collection com.bt.resmgt.aam.model.absence.book.AttendanceManager.findAbsences(com.bt.fieldpeople.security.models.Subject,com.bt.resmgt.aam.model.employee.Employee,java.util.List,java.lang.String,java.lang.String,java.util.List,java.util.Date,java.util.Date,java.util.Date,boolean,boolean,boolean,boolean,boolean,boolean,boolean,java.lang.String[]) throws java.lang.Exception,java.rmi.RemoteException' in EJB 'AttendanceManager' contains a parameter of type: 'java.util.List' which is not Serializable. Though the EJB 'AttendanceManager' has call-by-reference set to false, this parameter is not Serializable and hence will be passed by reference. A parameter can be passed using call-by-value only if the parameter type is Serializable.>
    could anybody please help me out?
    any type of jelp will be greatly appreciated.
    Thanks,
    Neeraj

    Your problem is here:
    «'java.util.List' which is not Serializable»
    You're trying to deploy a remote bean. Local beans can work with a parameter that isn't serializable, because their access is made by reference (pointers). But for remote beans, the whole object must be serialized and send over the network to be received by the client. Thus, the java.util.List can't be serialised, so WL complains.
    You must choose a container that can be serialized like java.util.ArrayList, a LinkedList or a vector in case of lists, or use local beans. Anyway, I think serialised objects should always be used with bean functions parameters.

  • Error: java.sql.SQLException; must be caught or declared to be thrown.

    in a servlet, I have a class like:
    class mydb
    public static Connection conn;
    public static void init() throws SQLException
    // Load the Oracle JDBC driver
    DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
    conn = DriverManager.getConnection ("jdbc:oracle:oci8:@baby", "scott", "tiger");
    public static String getValue() throws SQLException
    String curValue="";
    // Create a Statement
    Statement stmt = conn.createStatement ();
    // Select the ENAME column from the EMP table
    ResultSet rset = stmt.executeQuery ("select ENAME from EMP");
    // Iterate through the result and print the employee names
    if (rset.next ())
    curValue = rset.getString (1);
    // Close the RseultSet
    rset.close();
    // Close the Statement
    stmt.close();
    return(curValue);
    public static void destroy() throws SQLException
    // Close the connection
    conn.close();
    but when it is called, errors "java.sql.SQLException; must be caught or declared to be thrown." encountered, how to solve this problem? please help.

    This is part of the Java language.
    If a method throws an exception, then
    it is telling you that the exception is
    something that you should be aware of.
    If you call a method which throws this exception, then the method must either catch this exception, or you may decide that this exception should be caught by the calling method.
    So, your choices are:
    1. Wrap the method call in a try{...} catch block
    -or-
    2. Change the (calling) method's signature to reflect the fact that this method can cause this exception to be thrown (add a 'throws SQLException' ) at end of signature.
    -John
    null

  • Mailing attachments; java.io.IOException; must be caught or declared to be

    I seem to be having trouble setting up to attach a file and I'm getting the error message
    java.io.IOException; must be caught or declared to be
    //other related code
        String bookingFilename = "what ever filename";
    // create some properties and get the default Session
         Properties props = new Properties();
         props.put("mail.smtp.host", host);
         Session session = Session.getInstance(props, null);
         //session.setDebug(debug);
         try {
             // create a message
             MimeMessage msg = new MimeMessage(session);
             msg.setFrom(new InternetAddress(from));
             InternetAddress[] address = {new InternetAddress(to)};
             msg.setRecipients(Message.RecipientType.TO, address);
             msg.setSubject(subject);
             msg.setSentDate(new Date());
             // create and fill the first message part
             MimeBodyPart mbp1 = new MimeBodyPart();
             mbp1.setText(msgText1);
             // create and fill the second message part
             MimeBodyPart mbp2 = new MimeBodyPart();
                //PROBLEM LINE
                mbp2.setFilename(bookingFilename);
             // create the Multipart and its parts to it
             Multipart mp = new MimeMultipart();
             mp.addBodyPart(mbp1);
             mp.addBodyPart(mbp2);
             // add the Multipart to the message
             msg.setContent(mp);
             // send the message
             Transport.send(msg);
         } catch (MessagingException mex) {
             mex.printStackTrace();
             Exception ex = null;
             if ((ex = mex.getNextException()) != null) {
              ex.printStackTrace();the following is the problem code
    mbp2.setFilename(bookingFilename);am I putting the filename in the wrong format?
    I'm hoping to specify the exact filename using "if" statements so the current
    String bookingFilename = "what ever filename";is just a placeholder
    I'd be very grateful for any assitance
    eventually I intend to email out 3 seperate attachments at the same time,
    from a bank of about 10 files which are either pdf's or word doc's
    Dioxin

    Lets not go into my lack of Java training just yet :-P
         } catch (IOException ioex) {
             ioex.printStackTrace();was the block I was missing
    I'd also miswritten the problem code...cos I'd been fiddling with other commands
    mbp2.attachFile(bookingFilename);well it appears to compile... now to fire off a test email!
    cheers
    Dioxin

  • How to slove follwoing error "Unreported exception java.io.IOException;"

    Currently I'm using following:
    XP Professional
    J2sdk1.4.2_01
    Xerces-2_5_0
    Xalan-j_2_5_1
    Jakarta-tomcat-4.1.27
    Jdom-b9
    Current Classpath setting
    User variables
    PATH = c:\bmrt2.5\bin; c:\j2sdk\bin;%PATH%;%JAVA_HOME%\bin;
    CLASSPATH=.;c:\xerces\xmlParserAPIs.jar;c:\xerces\xercesImpl.jar;
    c:\xerces\xercesSamples.jar;c:\xalan\xercesImpl.jar;c:\xalan\xmlapis.jar;c:\xalan\xalan.jar;c:\tomcat\lib\webserver.jar;c:\tomcat\lib\jasper.jar;c:\tomcat\lib\xml.jar;c:\tomcat\common\lib\serlet.jar;c:\tomcat\lib\tools.jar; c:\tomcat\lib\tools.jar;c:\jdom\build\jdom.jar;
    CATALINA_HOME= c:\tomcat
    JAVA_HOME= c:\j2sdk
    System variables
    PATH=%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;
    c:\j2sdk\bin;%Path%;%JAVA_HOME%\bin;
    CLASSPATH=.;c:\xerces\xmlParserAPIs.jar;c:\xerces\xercesImpl.jar;
    c:\xerces\xercesSamples.jar;c:\xalan\xercesImpl.jar;c:\xalan\xmlapis.jar;c:\xalan\xalan.jar;c:\tomcat\lib\webserver.jar;c:\tomcat\lib\jasper.jar;c:\tomcat\lib\xml.jar;c:\tomcat\common\lib\serlet.jar;c:\tomcat\lib\tools.jar; c:\tomcat\lib\tools.jar;
    CATALINA_HOME= c:\tomcat
    JAVA_HOME= c:\j2sdk
    Program
    import java.io.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    import org.jdom.*;
    import org.jdom.Element;
    import org.jdom.Document;
    import org.jdom.output.XMLOutputter;
    import org.jdom.input.SAXBuilder;
    import org.jdom.Attribute;
    import java.util.List;
    public class AddToList extends HttpServlet
         public Document getDocument(File sourceFile, PrintWriter errorsOut)
              try
                   SAXBuilder builder = new SAXBuilder();
                   Document document = builder.build(sourceFile);
                   return document;
              catch(JDOMException e)
                   errorsOut.print("there was a problem building the document: " e. getMessage()"<br/>"+ "Returning blank document.");
                   return new Document(new Element("blank"));
         public void saveDocument(Document saveDoc, File saveFile, PrintWriter errorsOut)
              try
                   FileOutputStream outStream= new FileOutputStream(saveFile);
                   XMLOutputter outToFile= new XMLOutputter(" ",true);
                   outToFile.output(saveDoc, outStream);
                   outStream.flush();
                   outStream.close();
              catch (IOException e)
                   errorsOut.print("Can't save order.xml: " + e.getMessage()+"<br />");
         public void addItem(Element orderElement, String product_id, String quant)
              Element newItem =new Element("item");
              newItem.setAttribute("product_id", product_id);
              Element quantity =new Element("quantity");
              quantity.addContent(quant);
              newItem.addContent(quantity);
              orderElement.addContent(newItem);
         public void doGet(HttpServletRequest request, HttpServletResponse response)
              throws IOException, ServletException
              String thisProduct_id=request.getParameter("addProduct_id");
              String thisQuantity=request.getParameter("addQuantity");
              response.setContentType("text/html");
              PrintWriter out= response.getWriter();
              out.print("Adding "+ thisQuantity + "of item to chart "+ thisProduct_id +" ... ");
              File orderFile = new File ("file:///c:/jdk1.3/orders.xml");
              if(!orderFile.exists())
                   out.print("Creating ordersrocks....<br />");
                   Element root= new Element("orders");
                   root.addContent(" ");
                   Document document = new Document(root);
                   saveDocument (document, orderFile, out);
              else
                   out.print("Orders File Exists.");
              Document document =getDocument(orderFile, out);
              HttpSession session =request.getSession(true);
              String session_id= session.getId();
              Element root =document.getRootElement();
              List orders =root.getChildren();
              int num_orders =orders.size();
              boolean orderExists =false;
              int orderIndex =0;
              for(int i=0; i<num_orders; i++)
                   Element iOrder=(Element)orders.get(i);
                   String iOrder_id=iOrder.getAttributeValue("order_id");
                   if (iOrder_id.equals(session_id))
                        orderExists=true;
                        orderIndex=i;
                        break;
              if(!orderExists)
                   Element order =new Element("order");
                   order.setAttribute("order_id", session_id);
                   Element status =new Element("order_status");
                   status.setText("open");
                   order.addContent(status);
                   addItem(order, thisProduct_id, thisQuantity);
                   root.addContent(order);
              else
                   Element thisOrder=(Element)orders.get(orderIndex);
                   boolean itemExists=false;
                   int itemIndex =0;
                   List items =thisOrder.getChildren("item");
                   int num_items =items.size();
                   for(int i=0; i<num_items; i++)
                        Element iItem=(Element)items.get(i);
                        String iProduct_id =iItem.getAttribute("product_id").getValue();
                        if(iProduct_id.equals(thisProduct_id))
                             itemExists =true;
                             itemIndex =i;
                             break;
                   if(itemExists)
                        Element thisItem=(Element)items.get(itemIndex);
                        String currentQuantity= thisItem.getChildText("quantity");
                        int newQuantity = Integer.parseInt(currentQuantity)+ Integer.parseInt(thisQuantity);
                        String strQuantity= new String().valueOf(newQuantity)+1;
                        thisItem.getChild("quantity").setText(strQuantity);
                   else
                        addItem(thisOrder, thisProduct_id, thisQuantity);
              saveDocument (document, orderFile, out);
         public void doPost(HttpServletRequest request, HttpServletResponse response)
              throws IOException, ServletException
              doGet(request, response);
    When I compile above program, it gives me following error.
    Error
    C:\tomcat\webapps\book\WEB-INF\classes>javac AddToList.java
    AddToList.java:19: unreported exception java.io.IOException; must be caught
    or declared to be thrown
    Document document = builder.build(sourceFile);
    ^
    1 error
    Any help regarding this will be appreciated
    Thank you
    Rocks

    Obadare
    Thank for your help, my program compile successfully. But now I�m facing different kind of error on Tomcat; why it gives me following error and how do I solve it
    http://localhost:8080/rock/servlet/AddToList
    Following Error generate by Tomcat:
    Http Status 500-
    type Exception report
    message
    description The server encountered an internal error () that prevented it from fulfilling this request.
    exception
    javax.servlet.ServletException: Cannot allocate servlet instance for path /rock/servlet/AddToList
         at org.apache.catalina.servlets.InvokerServlet.serveRequest(InvokerServlet.java:435)
         at org.apache.catalina.servlets.InvokerServlet.doGet(InvokerServlet.java:180)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
         at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter
    (ApplicationFilterChain.java:247)
    root cause
    java.lang.NoClassDefFoundError: org/jdom/JDOMException
         at java.lang.Class.newInstance0(Native Method)
         at java.lang.Class.newInstance(Class.java:237)
         at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:903)
         at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:668)
         at org.apache.catalina.servlets.InvokerServlet.serveRequest(InvokerServlet.java:416)
         at org.apache.catalina.servlets.InvokerServlet.doGet(InvokerServlet.java:180)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
         at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter
    (ApplicationFilterChain.java:247)
    The following is my configuration
    Classpath= .;c:\xalan\bin\xalan.jar;c:\xalan\bin\xml-apis.jar;c:\xerces\xmlParserAPIs.jar;c:\xerces\xercesImpl.jar;c:\tomcat\common\lib\servlet.jar;c:\jdom\build\jdom.jar;
    Java_Home=c:\jdk1.3
    Catalina_Home=c:\tomcat
    Server.xml
    <Engine name="Standalone" defaultHost="localhost" debug="0">
    <Host name="localhost" debug="0" appBase="webapps"
    unpackWARs="true" autoDeploy="true">
    <Context path="/rock" docBase="rock" debug="0"
    reloadable="true" crossContext="true">
    P.S When I try to build javadoc it give me following error:
    C:\jdom>build javadoc
    JDOM Build System
    Building with classpath c:\jdk1.3\lib\tools.jar;.\lib\ant.jar;.\lib\xml-apis.jar
    ;.\lib\xerces.jar;
    Starting Ant...
    Buildfile: build.xml
    [javadoc] Constructing Javadoc information...
    [javadoc] Building tree for all the packages and classes...
    [javadoc] Building index for all the packages and classes...
    [javadoc] javadoc: warning - Tag @link: Class or Package not found: javax.xml.
    transform.TransformerFactory#getFeature
    [javadoc] javadoc: warning - Tag @link: Class or Package not found: javax.xml.
    transform.TransformerFactory#getFeature
    [javadoc] Building index for all classes...
    [javadoc] javadoc: warning - Tag @link: Class or Package not found: javax.xml.
    transform.TransformerFactory#getFeature
    [javadoc] javadoc: warning - Tag @link: Class or Package not found: javax.xml.
    transform.TransformerFactory#getFeature
    [javadoc] javadoc: warning - Tag @link: Class or Package not found: javax.xml.
    transform.Transformer
    [javadoc] javadoc: warning - Tag @link: Class or Package not found: javax.xml.
    transform.Transformer
    [javadoc] javadoc: warning - Tag @link: Class or Package not found: javax.xml.
    transform.Transformer JAXP TrAX Transformer
    [javadoc] javadoc: warning - Tag @link: Class or Package not found: javax.xml.
    transform.TransformerFactory#getFeature
    [javadoc] javadoc: warning - Tag @link: Class or Package not found: javax.xml.
    transform.TransformerFactory#getFeature
    [javadoc] javadoc: warning - Tag @link: Class or Package not found: java.lang.
    Double#NaN
    [javadoc] Generating C:\jdom\build\apidocs\stylesheet.css...
    [javadoc] 10 warnings
    BUILD SUCCESSFUL
    Total time: 12 seconds

  • Unreported Exception java.lang.InstantiationException

    Dear Friends,
    I am developing javabean connectivty for inserting records to mysql database from jsp. when i try to compile java bean program. It gives an error like unreported Exception java.lang.InstantiationException: Must be caught or declared to be thrown*. This is my mode. Please anyone help to solve this error. if you find any error in my code, please suggest me. Thanks in advance.
    package com.webdeveloper.servlets;
    import java.sql.*;
    import java.io.*;
    public class InsertBean {
    private String dbURL = "jdbc:mysql://localhost:3306/test";
    private Connection dbCon;
    private Statement st;
    String dbuser = "root";
    String dbpass = "admin";
    String Name = null;
    String Address = null;
    String Zip = null;
    public InsertBean() {
    super();
    public String getName() {
    return this.Name;
    public String getAddress() {
    return this.Address;
    public String getZip() {
    return this.Zip;
    public void setName(String pname) {
    this.Name = pname;
    public void setAddress(String paddress) {
    this.Address = paddress;
    public void setZip(String pzip) {
    this.Zip = pzip;
    public void doInsert() throws ClassNotFoundException, SQLException {
    Class.forName("com.mysql.jdbc.Driver").newInstance();//it gives error in this line
    dbCon = DriverManager.getConnection(dbURL,dbuser,dbpass);
    Statement s = dbCon.createStatement();
    String sql = "Insert into Person values ('" + this.Name;
    sql = sql + "', '" + this.Address + "', " + this.Zip;
    sql = sql + ")";
    int insertResult = s.executeUpdate(sql);
    dbCon.close();
    }

    Dear BalusC,
    Thanks for your suggestion. I used try catch block also. But it still gives same error. I have modified my following code. Is there any thing wrong in my code? Please give me your suggestion. Thankyou.
    // Java Document
    package com.webdeveloper.servlets;
    import java.sql.*;
    import java.io.*;
    public class InsertBean {
    private String dbURL = "jdbc:mysql://localhost:3306/test";
    private Connection dbCon;
    private Statement st;
    String dbuser = "root";
    String dbpass = "admin";
    String Name = null;
    String Address = null;
    String Zip = null;
    public InsertBean() {
    super();
    public String getName() {
    return this.Name;
    public String getAddress() {
    return this.Address;
    public String getZip() {
    return this.Zip;
    public void setName(String pname) {
    this.Name = pname;
    public void setAddress(String paddress) {
    this.Address = paddress;
    public void setZip(String pzip) {
    this.Zip = pzip;
    public void doInsert() throws ClassNotFoundException, SQLException {
         try{
         Class.forName("com.mysql.jdbc.Driver").newInstance();
    dbCon = DriverManager.getConnection(dbURL,dbuser,dbpass);
    Statement s = dbCon.createStatement();
    String sql = "Insert into Person values ('" + this.Name;
    sql = sql + "', '" + this.Address + "', " + this.Zip;
    sql = sql + ")";
    int insertResult = s.executeUpdate(sql);
         catch(Exception e){
         System.out.println("error occured :" + e);
         dbCon.close();
    }

  • Must be caught or declared to be thrown...

    how would i go about something like that?
    import java.util.*;
    public class GameLauncher{
    public static void main( String [] args) {
         SellGame game = new SellGame();
              game.startGame();
    ____________________________________________________________________

    how would i go about something like that?I am guessing that your program will not compile... something like this:
    % cat HelloWorld.java
    public class HelloWorld {
        public static void main(String args[]) {
            System.out.println("Hello, world!");
            java.lang.Thread.sleep(500);
    % javac -g HelloWorld.java
    HelloWorld.java:5: unreported exception java.lang.InterruptedException; must be caught or declared to be thrown
            java.lang.Thread.sleep(500);
                                  ^
    1 errorRefer to this section of the Tutorial for an explanation:
    Exception Handling Statements
    http://java.sun.com/docs/books/tutorial/java/nutsandbolts/exception.html
    Hope this helps.
    "Troubleshooting Guide for J2SE 5.0",
    http://java.sun.com/j2se/1.5/pdf/jdk50_ts_guide.pdf

  • My function must be caught or declared to be thrown?

    hi again.
    so here's what's going on.
    i'm writing a class that contains a function that will be used as a part of a program. only one parameter will be passed, in this case, BAC.
    to test my program, i'm trying to write a simple main function to call the class. here's what it looks like:
    public static void main(String[] args) {
    String BAC = "teststring";
    findbac bac = new findbac();
    bac.findbac(BAC);
    the function i'm trying to call is findbac(String BAC) in class findbac.
    when i compile, i get the error message
    29: unreported exception java.io.IOException; must be caught or declared to be thrown
    bac.findbac(BAC);
    i just started java a few days ago so im not 100% familiar with the throw and catch terms.
    what should i do to make this work? thanks.

    thanks a bunch for the help. still a little confusing, but im gonna sit down and figure it all out tonight after i get home.
    and i tried putting in the code Valavet suggested, and it compiles now! but when i run it, i get a new error:
    java.lang.ArrayIndexOutOfBoundsException: 2
    at findit.findbac.findbac(findbac.java:108)
    at findit.findbackclass.main(findbackclass.java:37)
    Exception in thread "main"
    Java Result: 1
    the two lines of code are
    experiments[experimentnumber-1] = dataline.substring(beginningIndex, endIndex);
    and
    bac.findbac(BAC);
    respectively.
    what do they mean by array index out of bounds? i know my array index is correct.
    do {            //this do-while loop writes each experiment's result (as a string) to the experiments[] matrix.
                                    foundIndex = dataline.indexOf(comma, fromIndex);
                                    if (foundIndex >= 0) {
                                        experimentnumber++;
                                        fromIndex = foundIndex + 1;
                                    endIndex = fromIndex;
                                    if (experimentnumber >= 1){
                                        experiments[experimentnumber-1] = dataline.substring(beginningIndex, endIndex);
                                    beginningIndex = fromIndex;
                                } while (foundIndex >= 0);

  • Conn.rollback() must be caught or declared to be thrown

    Hi, I'm having problems compiling the following code
    private void toInsert(String insert_foo, int insert_bar) {
              InitialContext context = null;
              Connection conn = null;
              PreparedStatement pstmt= null;     
              try {
                   context = new InitialContext();
                   DataSource ds = (DataSource) context.lookup("java:comp/env/jdbc/TestDB");
                   conn = ds.getConnection();
                   conn.setAutoCommit(false);
                   pstmt = conn.prepareStatement("INSERT into testdata values(?, ?)");
                   pstmt.setString(1, insert_foo);
                   pstmt.setInt(2, insert_bar);
                   pstmt.executeUpdate();
                   conn.commit();
                   conn.setAutoCommit(true);
                   pstmt.close();
                   pstmt = null;
                   conn.close();
                   conn = null;
                   context.close();
                   context = null;
              catch (Exception e) {
                   conn.rollback();
              finally {
                   if (pstmt != null) {
                        try { pstmt.close(); }          
                        catch (SQLException e) {;}     
                        pstmt = null;               
                   if (conn != null) {
                        try { conn.close(); }          
                        catch (SQLException e) {;}     
                        conn = null;               
                   if (context != null) {
                        try { context.close(); }     
                        catch (NamingException e) {;}     
                        context = null;               
         }I got this error when I try to compile the above;
    unreported exception java.sql.SQLException; must be caught or declared to be thrown
    conn.rollback();
    I search and read through a lot of posts here that rollback() could be used in the catch block but why I can't I compile it?
    Please help me out, thank you.
    puzzled....

    Is it similiar to factory methods? No.
    I've read up on this:
    http://www.javaworld.com/javaworld/javaqa/2001-05/02-qa-0511-factory.html?
    "small boy with a pattern" syndrome strikes again.
    Could you assist to help me in giving me guidelines
    for writing the database utilites class?
    Appreciated...
    public final class DatabaseUtils
        public static void close(Connection c)
            if (c != null)
                try
                    c.close();
                catch (SQLException e)
                      // print stack trace or, better yet, log the exception with Log4J
        // same for other close operations on ResultSet and Statement
        public void rollback(Connection c)
            if (c != null)
                try
                    c.rollback();
                catch (SQLException e)
                      // print stack trace or, better yet, log the exception with Log4J
    }%

  • Java.rmi.RemoteException: Exception in ejbLoad

    I use findByPrimaryKey() to find the object first.And I also can get PrimaryKey by method getPrimaryKey().
    But when I invoke method getName()(the method I defined to get name) ,it throws out exception:
    java.rmi.RemoteException: Exception in ejbLoad:; nested exception is:
    java.lang.NullPointerException
    what's wrong?

    Hi Susan ,
    By looking at your question , the first thing that comes to my mind is the "Null pointer Exception" migt only come when you have the null reference to your primary key . I mean , your metod call findByPrimaryKey shoudl return you a NOT NULL reference . But I guess there is a probablility that it might be returning NULL. And after that when u try to use that reference to invoke getName() method , it must be throwing NULL pointer exception. Just try priting the reference returned by your findByPrimaryKey() method.
    If it does not work out , write me more about what exactly is happening at your end.
    -amit

  • Java.rmi.RemoteException: SOAP Fault:javax.xml.rpc.soap.SOAPFaultException

    Hi, I created a webservice using weblogic8.1 sp3 workshop. On my desktop, I tested the webservice with a java client and it worked fine. When I deployed webservice application on UNIX production server, it deployed successfully and it displayed WSDL file too. But, when I run java client from desktop to access this webservice on UNIX server, it is throwing the following exception.
    java.rmi.RemoteException: SOAP Fault:javax.xml.rpc.soap.SOAPFaultException: EXCEPTION: java.lang.NoClassDefFoundError [ServiceException]
    Detail:
    <detail>
    null </detail>; nested exception is:
    javax.xml.rpc.soap.SOAPFaultException: EXCEPTION: java.lang.NoClassDefFoundError [ServiceException]
    at weblogic.jws.proxies.MyServiceSoap_Stub.getInfo(MyServiceSoap_Stub.java:31)
    at SoapClient.main(SoapClient.java:17)
    Caused by: javax.xml.rpc.soap.SOAPFaultException: EXCEPTION: java.lang.NoClassDefFoundError [ServiceException]
    at weblogic.webservice.core.ClientDispather.receive(ClientDispatcher.java:313)
    at weblogic.webservice.core.ClientDispatcher.dispatch(ClientDispatcher.java:144)
    at weblogic.webservice.core.DefaultOperation.invoke(DefaultOperation.java:457)
    at weblogic.webservice.core.DefaultOperation.invoke(DefaultOperation.java:443)
    at weblogic.webservice.core.rpc.StubImpl._invoke(StubImpl.java:290)
    at weblogic.jws.proxies.MyServiceSoap_Stub.getInfo(MyServiceSoap_Stub.java:26)
    can somebody please help me. This is very critical for me.
    Thanks in advance.

    Hi, I created a webservice using weblogic8.1 sp3 workshop. On my desktop, I tested the webservice with a java client and it worked fine. When I deployed webservice application on UNIX production server, it deployed successfully and it displayed WSDL file too. But, when I run java client from desktop to access this webservice on UNIX server, it is throwing the following exception.
    java.rmi.RemoteException: SOAP Fault:javax.xml.rpc.soap.SOAPFaultException: EXCEPTION: java.lang.NoClassDefFoundError [ServiceException]
    Detail:
    <detail>
    null </detail>; nested exception is:
    javax.xml.rpc.soap.SOAPFaultException: EXCEPTION: java.lang.NoClassDefFoundError [ServiceException]
    at weblogic.jws.proxies.MyServiceSoap_Stub.getInfo(MyServiceSoap_Stub.java:31)
    at SoapClient.main(SoapClient.java:17)
    Caused by: javax.xml.rpc.soap.SOAPFaultException: EXCEPTION: java.lang.NoClassDefFoundError [ServiceException]
    at weblogic.webservice.core.ClientDispather.receive(ClientDispatcher.java:313)
    at weblogic.webservice.core.ClientDispatcher.dispatch(ClientDispatcher.java:144)
    at weblogic.webservice.core.DefaultOperation.invoke(DefaultOperation.java:457)
    at weblogic.webservice.core.DefaultOperation.invoke(DefaultOperation.java:443)
    at weblogic.webservice.core.rpc.StubImpl._invoke(StubImpl.java:290)
    at weblogic.jws.proxies.MyServiceSoap_Stub.getInfo(MyServiceSoap_Stub.java:26)
    can somebody please help me. This is very critical for me.
    Thanks in advance.

  • Java.rmi.RemoteException: Error initializing ejb-module java.lang.NoClassDe

    Hi,
    I have an ear file which has ejb jar and war file. Application is running fine through Jdeveloper but when am trying to deploy it in Oracle Application Server 10g getting following error. Any help in this would be appreciated.
    Deployment failed: Nested exception
    Resolution:
    Base Exception:
    java.rmi.RemoteException
    deploy failed!: ; nested exception is:
    oracle.oc4j.admin.internal.DeployerException: Error initializing ejb-module; Exception Error loading class 'ge.model.common.ejb.ReserveAccountBean': java.lang.NoClassDefFoundError: ge/common/exception/dao/GEDAOException. deploy failed!: ; nested exception is:
    oracle.oc4j.admin.internal.DeployerException: Error initializing ejb-module; Exception Error loading class 'ge.model.common.ejb.ReserveAccountBean': java.lang.NoClassDefFoundError: ge/common/exception/dao/GEDAOException
    Thanks and Regards,
    Ujwala

    Ujwala,
    I don't think classes in the "ejb.jar" file can access classes in the WAR file (and vice-versa). Perhaps you can put this class in a separate JAR file and put that JAR file in the "applib" subdirectory (of your OC4J installation). Then it will be accessible to all your J2EE applications deployed to OC4J.
    Good Luck,
    Avi.

  • JAX-RPC Client - java.rmi.RemoteException:/getPort best practices

    We are working on java webservices(JAX-RPC style) and while consuming Java WebService sometime getting ‘Remote Exception’ .I have generated client side code with weblogic ant task “clientgen”.
    1: Exception
    java.rmi.RemoteException: SOAPFaultException - FaultCode [{http://schemas.xmlsoap.org/soap/envelope/}Server] FaultString [Failed to invoke end component {service implementation class name} (POJO), operation= {webmethode name}
    -> Failed to invoke method
    ] FaultActor [null] Detail [<detail><java:string xmlns:java="java.io">java.lang.NullPointerException
    </java:string></detail>]; nested exception is:
    weblogic.wsee.jaxrpc.soapfault.WLSOAPFaultException: Failed to invoke end component {service implementation class name} (POJO), operation={webmethode name}
    -> Failed to invoke method
    {Package name}.ManagementPortType_Stub.createXXX(xxxPortType_Stub.java:37) // This line is clientgen generated code
    {From this line its clear that clientgen generated code failed to get webservice port}
    2: Following is our implementation to invoke webservice:
    ManagementService service =
    new ManagementService_Impl(“WSDL URL”)
    ManagementPortType port = service.getManagerHTTPPort();
    Port.getServiceName();
    Our code is executing first two lines for every webservice request, and as per our observation these two lines (mark in bold) is taking long time to execute and due to this sometime gives ‘remote exception’ (when there is more request for web service consumption).
    3: My questions:
    1> Why does it take so long on initialization of service and port object?
    2> Is there any problem if I share “port” object for multiple request?
    3> what are the best practices in this type of implementation?
    Help would be greatly appreciated !

    Hi,
    Thanks for your reply.
    My service is deployed and working fine.
    NPE is due to {Package name}.ManagementPortType_Stub is null and code is executing createXXX() methode on it.
    Anyway i cant do anaything here because this is a clientgen generated code.

Maybe you are looking for