Skip to Content
avatar image
Former Member

Help, Is the sneek preview 6.40 compatible to j2sdk1.4.2_04

I am an experienced ABAPer but absolutely new in JAVA. So after some investigations (and the not successfully try to install it under Linux - no help from SAP), I have successfully installed WAS 6.40 under W2000. Now I'm trying to run 'Creating Your First J2EE Application' from the help. I have done everything with extreme care (and cut and paste) but after editing 'CalcProxy.java' I get always the same Error Message: 'The method narrow(Object, Class) from the type PortableRemoteObject is not static'. PortableRemoteObject is an import, so this should be ok, but it is not.

In the prerequisites is written that j2sdk1.4.2_03 should be installed first. On my sytem j2sdk1.4.2_04 was already installed, so I thought this should be ok and I got no error message during installation.

But now I have the frustrating fact that the simpliest beginners application does not work. I have included the code, and my question is: Is it a typing mistake or is it the wrong sdk??

I have done this three times, but always the same result.

Thanks for every help

Rudolf

>>>>>>>>>>>>>>>>>>>>>>>>

/*

  • Created on 31.05.2004

*

  • To change the template for this generated file go to

  • Window>Preferences>Java>Code Generation>Code and Comments

*/

package com.sap.examples.calculator.beans;

import javax.naming.InitialContext;

import com.sap.examples.calculator.Calculator;

import com.sap.examples.calculator.CalculatorHome;

import com.sun.corba.se.internal.javax.rmi.PortableRemoteObject;

/**

  • @author sapwas

*

  • To change the template for this generated type comment go to

  • Window>Preferences>Java>Code Generation>Code and Comments

*/

public class CalcProxy {

private Calculator calc;

public void init() throws Exception {

//Lookup the enterprise bean

try {

InitialContext ctx = new InitialContext();

Object ob = ctx.lookup("java:comp/env/ejb/CalculatorBean");

CalculatorHome home =

(CalculatorHome) PortableRemoteObject.narrow(

ob,

CalculatorHome.class);

//Initialize the enterprise bean

calc = home.create();

} catch (Exception e) {

throw new Exception(

"Error instantiating Calculator EJB" + e.toString());

}

}

public CalcProxy() throws Exception {

init();

}

public float getResult(

String firstNumber,

String secondNumber,

String expression)

throws Exception {

float result = 0;

try {

if (firstNumber != null && secondNumber != null) {

//Parse the input parameters

float first = Float.parseFloat(firstNumber);

float second = Float.parseFloat(secondNumber);

int expr = Integer.parseInt(expression);

//Invoke the relevant method of the enterprise bean

switch (expr) {

case 1 :

result = calc.multiply(first, second);

break;

case 2 :

result = calc.divide(first, second);

break;

case 3 :

result = calc.add(first, second);

break;

case 4 :

result = calc.subtract(first, second);

break;

}

}

} catch (Exception re) {

throw new Exception("Fill in all required fields with appropriate values!");

}

//Return the result of the calculation

return result;

}

}

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

1 Answer

  • avatar image
    Former Member
    Jun 01, 2004 at 02:46 AM

    Hi Rudolf,

    it's absolute ok to use j2sdk1.4.2_04. The only mistake is, that you choosed the wrong import in case of PortableRemoteObject. Repeating the corresponding lines from the help:

    2. If necessary, correct the formatting of the code lines by choosing Source -> Format from the context menu.

    3. To add the required import statements, position the cursor anywhere in the Java editor and choose Source -> Organize Imports.

    4. Choose <b>javax.rmi.PortableRemoteObject</b> and confirm by choosing Finish.

    You have selected com.sun.corba.se.internal.javax.rmi.PortableRemoteObject in step 4 instead.

    Hope that helps.

    Regards

    Stefan

    Add comment
    10|10000 characters needed characters exceeded