Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Java and AS/400

Status
Not open for further replies.

MJV

Programmer
Oct 2, 2002
10
CA
Hi,

Trying to run a java program using PCML to call a program on our AS/400 server. However when I run the java program, I get the following error. Anyone know what this means?

C:\JAVA>java Add2Numbers
Connecting to iSeries...
Exception in thread "main" java.lang.NullPointerException
at com.ibm.as400.data.PcmlSAXParser.introspectMethod(PcmlSAXParser.java:
479)
at com.ibm.as400.data.PcmlSAXParser.introspectMethod(PcmlSAXParser.java:
470)
at com.ibm.as400.data.PcmlSAXParser.<init>(PcmlSAXParser.java:126)
at com.ibm.as400.data.ProgramCallDocument.loadSourcePcmlDocument(Program
CallDocument.java:1076)
at com.ibm.as400.data.ProgramCallDocument.loadPcmlDocument(ProgramCallDo
cument.java:979)
at com.ibm.as400.data.ProgramCallDocument.<init>(ProgramCallDocument.jav
a:127)
at Add2Numbers.main(Add2Numbers.java:38)

MJV
 
NullPointerException means that you are trying to reference an object that is null. This is a bit like C, where you have a pointer, but the pointee is null.

for example, this would throw a NPE :

String s = null;
int sl = s.length();

because while the String s is declared, it has no value at the pointer's address.

Post your code if you need more help ...
 
Sedj,

Thanks for your comment. I think I understand what you are saying as I am new to Java. Here is the java code:

import com.ibm.as400.data.*;
import com.ibm.as400.access.*;
import java.math.BigDecimal;

// Example class to call an RPG program to add two numbers and return the sum

public class Add2Numbers {

public Add2Numbers() {
}

public static void main(String argv[])
{
// Uncomment the following to get debugging information
//com.ibm.as400.data.PcmlMessageLog.setTraceEnabled(true);

// Create and instantiate an AS/400 Object
// If you do not enter a user id or password, you will be prompted for each
// AS400 sys = new AS400("url of iSeries", "user id", "password");
System.out.println("Connecting to iSeries...");
AS400 sys = new AS400();

// Create Data Objects
ProgramCallDocument pcml; // com.ibm.as400.data.ProgramCallDocument
BigDecimal sum = new BigDecimal("0"); // RPG program variable
String comment; // RPG program variable
boolean rc = false; // Return code for program call
String msgId, msgText; // Messages returned from AS/400

try
{

// Instantiate the Objects (assign the variables)
pcml = new ProgramCallDocument(sys, "AddTwoNumbers");
pcml.setValue("program.parameter1", new Integer("5"));
pcml.setValue("program.parameter2", new BigDecimal("5.25"));

// Debug statement...Use to view outbound and inbound parms if you need it
//com.ibm.as400.data.PcmlMessageLog.setTraceEnabled(true);

// Call the Program
System.out.println("Calling the program...");
rc = pcml.callProgram("ADD2NUMBER");

// If return code is false, get messages from the iSeries
if(rc == false)
{
// Retrieve list of AS/400 messages
AS400Message[] msgs = pcml.getMessageList("program");

// Loop through all messages and write them to standard output
for (int m = 0; m < msgs.length; m++)
{
msgId = msgs[m].getID();
msgText = msgs[m].getText();
System.out.println(" " + msgId + " - " + msgText);
}
System.out.println("Call to PROGRAM failed. See messages listed above");
System.exit(0);
}

// Return code was true, call to PROGRAM succeeded - woo-hoo!

else
{
// Process the returned Data
sum = (BigDecimal) pcml.getValue("program.sum");
comment = (String) pcml.getValue("program.comment");

System.out.print("5" + " + " + "5.25" + " = " + sum);
System.out.print("\n");
System.out.print(comment);
System.exit(0);
}
}

catch (PcmlException e)
{
System.out.println(e.getLocalizedMessage());
e.printStackTrace();
System.out.println("Call to PROGRAM failed");
System.exit(0);
}

// Disconnect from AS/400
sys.disconnectAllServices();

}
}
 
I would say it was this line :

pcml = new ProgramCallDocument(sys, "AddTwoNumbers");

But how to fix it I'm really not sure, because the packages you are using are non-standard. I can only suggest looking at the API documentation.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top