What's wrong with my DII client code?
I have the following WSDL for my ASP/IIS web service...
<?xml version='1.0' encoding='UTF-8' ?>
<!-- Generated 10/31/03 by Microsoft SOAP Toolkit WSDL File Generator, Version 3.00.1325.0 -->
<definitions
name='DCIS'
targetNamespace='http://ds_00119/DCIS/wsdl/'
xmlns:wsdlns='http://ds_00119/DCIS/wsdl/'
xmlns:typens='http://ds_00119/DCIS/type/'
xmlns:soap='http://schemas.xmlsoap.org/wsdl/soap/'
xmlns:xsd='http://www.w3.org/2001/XMLSchema'
xmlns:stk='http://schemas.microsoft.com/soap-toolkit/wsdl-extension'
xmlns:dime='http://schemas.xmlsoap.org/ws/2002/04/dime/wsdl/'
xmlns:ref='http://schemas.xmlsoap.org/ws/2002/04/reference/'
xmlns:content='http://schemas.xmlsoap.org/ws/2002/04/content-type/'
xmlns:wsdl='http://schemas.xmlsoap.org/wsdl/'
xmlns='http://schemas.xmlsoap.org/wsdl/'>
<types>
<schema
targetNamespace='http://ds_00119/DCIS/type/'
xmlns='http://www.w3.org/2001/XMLSchema'
xmlns:SOAP-ENC='http://schemas.xmlsoap.org/soap/encoding/'
xmlns:wsdl='http://schemas.xmlsoap.org/wsdl/'
elementFormDefault='qualified'>
<import namespace='http://schemas.xmlsoap.org/soap/encoding/'/>
<import namespace='http://schemas.xmlsoap.org/wsdl/'/>
<import namespace='http://schemas.xmlsoap.org/ws/2002/04/reference/'/>
<import namespace='http://schemas.xmlsoap.org/ws/2002/04/content-type/'/>
</schema>
</types>
<message name='DCIS.CTXD'>
<part name='bstrUser' type='xsd:string'/>
<part name='bstrPassword' type='xsd:string'/>
<part name='bstrName' type='xsd:string'/>
<part name='bstrAddress' type='xsd:string'/>
<part name='bstrPhone' type='xsd:string'/>
</message>
<message name='DCIS.CTXDResponse'>
<part name='Result' type='xsd:string'/>
</message>
<portType name='DCISSoapPort'>
<operation name='CTXD' parameterOrder='bstrUser bstrPassword bstrName bstrAddress bstrPhone'>
<input message='wsdlns:DCIS.CTXD'/>
<output message='wsdlns:DCIS.CTXDResponse'/>
</operation>
</portType>
<binding name='DCISSoapBinding' type='wsdlns:DCISSoapPort' >
<stk:binding preferredEncoding='UTF-8'/>
<soap:binding style='rpc' transport='http://schemas.xmlsoap.org/soap/http'/>
<operation name='CTXD'>
<soap:operation soapAction='http://ds_00119/DCIS/action/DCIS.CTXD'/>
<input>
<soap:body
use='encoded'
namespace='http://ds_00119/DCIS/message/'
encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'
parts='bstrUser bstrPassword bstrName bstrAddress bstrPhone'/>
</input>
<output>
<soap:body
use='encoded'
namespace='http://ds_00119/DCIS/message/'
encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'
parts='Result'/>
</output>
</operation>
</binding>
<service name='DCIS' >
<port name='DCISSoapPort' binding='wsdlns:DCISSoapBinding' >
<soap:address location='http://ds_00119/DCIS/DCIS.ASP'/>
</port>
</service>
</definitions>
and the following client code...
import javax.xml.namespace.*;
import javax.xml.rpc.*;
import javax.activation.*;
import javax.mail.*;
import com.sun.xml.messaging.saaj.*;
import java.net.*;
import java.util.*;
import java.rmi.*;
public class DIIClient
public static void main(String[] args)
try
String namespace = "http://ds_00119/DCIS/wsdl/";
String endpointURL = "http://ds_00119/DCIS/dcis.asp";
String portName = "DCISSoapPort";
String functionName = "CTXD";
String[] paramNames = {"bstrUser","bstrPassword","bstrName","bstrAddress","bstrPhone"};
String[] paramValues = new String[] {"x","y","a","b","c"};
String xsdStringType = "<xsd:string>";
ServiceFactory factory = ServiceFactory.newInstance();
Call call = factory.createService(new QName("DCIS")).createCall();
call.setTargetEndpointAddress(endpointURL);
call.setPortTypeName(new QName(namespace, portName));
call.setOperationName(new QName(namespace, functionName));
call.setProperty(Call.SOAPACTION_USE_PROPERTY, new Boolean(true));
call.setProperty(Call.SOAPACTION_URI_PROPERTY, "http://ds_00119/DCIS/");
call.setProperty(Call.ENCODINGSTYLE_URI_PROPERTY, "");
call.setProperty(Call.OPERATION_STYLE_PROPERTY, "rpc");
for(int i=0; i<5; i++)
call.addParameter(paramNames, new QName(xsdStringType),ParameterMode.IN);
call.setReturnType(new QName(xsdStringType));
String returnValue = (String) call.invoke(paramValues);
System.out.println(returnValue);
catch(Exception ex)
ex.printStackTrace();
when I run this I get:
java.rmi.RemoteException: WSDLReader:The operation requested in the Soap message with soapAction http://ds_00119/DCIS/action/DCIS isn't defined in the WSDL file. This may be because it is in the wrong namespace or has incorrect case
at com.sun.xml.rpc.client.dii.BasicCall.invoke(BasicCall.java:369)
at DIIClient.main(DIIClient.java:45)
I've tried everything I can think of for the soapAction string and just can't get it to work. What am I doing wrong here?
I know the service works because I've been using C++ and VB clients for months, but I need to get a Java client up and running soon.
I've only been looking at Java WS clients for a day, so if anyone knows of a better way to do this then please tell me! I've tried 4 completely different implementations so far and none of them worked.
Chris
Dear Chris,
The problem is in your code itself or the way u've created this web service.
I'm sending you some sample code. Just change the values of variables and delete unwanted lines according to you. Just go step by step.
Here is the code
import javax.xml.rpc.Call;
import javax.xml.rpc.Service;
import javax.xml.rpc.JAXRPCException;
import javax.xml.namespace.QName;
import javax.xml.rpc.ServiceFactory;
import javax.xml.rpc.ParameterMode;
public class DllClient {
private static String qnameService = "IPSProv_pipeService";
private static String qnamePort = "IPSProv_pipeIFPort";
private static String BODY_NAMESPACE_VALUE =
"urn:Foo";
private static String ENCODING_STYLE_PROPERTY =
"javax.xml.rpc.encodingstyle.namespace.uri";
private static String NS_XSD =
"http://www.w3.org/2001/XMLSchema";
private static String URI_ENCODING =
"http://schemas.xmlsoap.org/soap/encoding/";
public static void main(String[] args) {
System.out.println("Endpoint address = http://218.248.33.59:8080/ipsprovPipeService/provision?WSDL");
try {
ServiceFactory factory =
ServiceFactory.newInstance();
Service service =
factory.createService(
new QName(qnameService));
QName port = new QName(qnamePort);
Call call = service.createCall(port);
call.setTargetEndpointAddress("http://215.246.33.59:8080/ipsprovPipeService/provision?WSDL");
call.setProperty(Call.SOAPACTION_USE_PROPERTY,
new Boolean(true));
call.setProperty(Call.SOAPACTION_URI_PROPERTY,
call.setProperty(ENCODING_STYLE_PROPERTY,
URI_ENCODING);
QName QNAME_TYPE_STRING =
new QName(NS_XSD, "string");
call.setReturnType(QNAME_TYPE_STRING);
call.setOperationName(
new QName(BODY_NAMESPACE_VALUE,"sp_mgmnt"));
call.addParameter("String_1", QNAME_TYPE_STRING,
ParameterMode.IN);
call.addParameter("String_2", QNAME_TYPE_STRING,
ParameterMode.IN);
call.addParameter("String_3", QNAME_TYPE_STRING,
ParameterMode.IN);
call.addParameter("String_4", QNAME_TYPE_STRING,
ParameterMode.IN);
String[] params = { "A","B"};
String result = (String)call.invoke(params);
System.out.println(result);
} catch (Exception ex) {
ex.printStackTrace();
Plz show me the code after u make changes in it and do reply whether it works or not.
Regards,
Piyush
Similar Messages
-
Please tell me what's wrong with this paypal buy code?
<form id="form1" name="form1" method="post" action="">
<p><form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="hosted_button_id" value="PBG8WAM6N6G2S">
<table>
<tr><td><input type="hidden" name="on0" value=""Showtime"-paper print">"Showtime"-paper print</td></tr><tr><td><select name="os0">
<option value="1-11x14">1-11x14 $50.00</option>
<option value="1-12x18">1-12x18 $65.00</option>
<option value="1-16x20">1-16x20 $90.00</option>
<option value="1-24x36">1-24x36 $170.00</option>
</select> </td></tr>
</table>
<input type="hidden" name="currency_code" value="USD">
<input type="image" src="https://www.paypal.com/en_US/i/btn/btn_buynowCC_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
<img alt="" border="0" src="https://www.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1">
</form>
When I insert this code and try the "buy buttton" nothing happens. My website is www.ritacortesi.com. Paypal does not really have a good support website.HTML and/or DW Tutorials, and other information links that I have saved
http://validator.w3.org/
http://www.w3schools.com/
http://www.hotscripts.com/
http://webdesignledger.com/
http://www.adobe.com/devnet/
http://www.scriptarchive.com/
http://www.htmldog.com/guides/
http://www.htmlcodetutorial.com/
http://alistapart.com/topics/code
http://www.how-to-build-websites.com/
http://css.maxdesign.com.au/floatutorial/
Download User Guide as PDF for easy search
http://www.adobe.com/support/documentation
http://www.ianr.unl.edu/internet/mailto.html
http://lynda.com/ Hours of videos. (must pay)
http://apptools.com/examples/pagelayout101.php
http://www.thesitewizard.com/archive/css.shtml
http://www.projectseven.com/tutorials/index.htm
If not PDF (link above) an online guide to read
http://livedocs.adobe.com/en_US/Dreamweaver/9.0/
Nate's Forms http://www.mindpalette.com/scripts/
Customizing the layouts that come with CS3 (VIDEO)
http://www.adobe.com/designcenter/video_workshop/?id=vid0155
FormMail http://www.bebosoft.com/products/formstogo/index.php
For those using MySQL - Installing PHP and MySQL on Windows XP
http://www.webassist.com/professional/products/solutionrecipes.asp
Community MX lessons http://www.communitymx.com/abstract.cfm?cid=3D074
http://www.adobe.com/cfusion/designcenter/search.cfm?product=Dreamweaver&go=Go
The Contact Form Solution Pack is only $29.99. To learn more, visit
http://www.webassist.com/go/cfsp
Web advisor extension to DW
Date and Time through Javascript http://www.mediacollege.com/internet/javascript/date-time/
Tutorial for building your first website:
http://www.adobe.com/devnet/dreamweaver/articles/first_website_pt1.html
Tutorial on building a dynamic website (one with a database):
http://www.adobe.com/devnet/dreamweaver/articles/first_dynamic_site_pt1.html
HTM Color Codes
http://www.visibone.com/
or http://html-color-codes.com/
or http://www.pagetutor.com/common/bgcolors1536.html
or http://www.geocities.com/SiliconValley/Network/2397/ -
What is wrong with this simple JSP code?
Whenever I run it on a browser it goes the SQL exception, but when I run it in a Java compiler it works fine.
Any help very much appreciated
<head>
<%@ page
import = "java.io.*"
import = "java.lang.*"
import = "java.sql.*"
%>
<title>
JSP Example 2
</title>
</head>
<body>
<h1>JSP Example 2</h1>
<%
try
// Load the driver class
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
try
// Define the data source for the driver
String sourceURL = "jdbc:odbc:my_library";
// Create a connection through the DriverManager
Connection databaseConnection = DriverManager.getConnection(sourceURL,"","");
out.println("Here");
Statement statement = databaseConnection.createStatement();
ResultSet authorNames = statement.executeQuery("Select * from tblAvailable_Items");
catch (SQLException s)
out.println("SQL Error<br>");
catch (ClassNotFoundException err)
out.println("Class loading error");
%>
</body>
</html>Hi...
I have made some modifications to your code.. Try this. I assume, you would configured the system dsn as my_library, a table name "Table1" with one of the fields name as "name"
<head>
<%@ page import = "java.io.*,java.lang.*,java.sql.*" %>
<title>
JSP Example 2
</title>
</head>
<body>
<h1>JSP Example 2</h1>
<%
try
// Load the driver class
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
try
// Define the data source for the driver
String sourceURL = "jdbc:odbc:my_library";
// Create a connection through the DriverManager
Connection databaseConnection = DriverManager.getConnection(sourceURL,"","");
out.println("Here");
Statement statement = databaseConnection.createStatement();
String sql = "select * from Table1";
ResultSet authorNames = statement.executeQuery(sql);
while (authorNames.next()){
String Name = authorNames.getString("name");
out.println(Name);
catch (SQLException s)
out.println("SQL Error<br>");
catch (ClassNotFoundException err)
out.println("Class loading error");
%>
</body>
</html>
Regds
Vasi -
What's wrong with my simple IO code?
import java.io.*;
public class test4
public static void main(String arg[])throws IOException
File f=new File("u:/temp.txt");
f.createNewFile();
FileWriter fwriter=new FileWriter(f,true);
fwriter.write("can you see me?");
}You have to close your, and you really should flush,
your fwriter before sending any data to file:You mean after sending any data, right? ;)
fwriter.flush();
fwriter.close();I suppose it doesn't hurt to be explicit, but the flush() isn't strictly necessary as close() flushes the stream before closing it (as per the API docs). I'll leave it to you as to what level of verbosity you want. -
What's wrong with this server-client example?
I have this simple server and client pair that I can't get speaking to each other and I wonder why.
The commandAction method:
} else if (cmd == simpleSrvrCommand) {
tbox.insert("Starting simple server...", tbox.size());
t = new MyThread();
t.start();
} else if (cmd == simpleClntCommand) {
tbox.insert("Trying to connect to simple server...("+PROTOCOL +
serverDeviceToBeFoundNokia6600 + ":" + serviceNumberServer+")",
tbox.size());
try {
L2CAPConnection cConn = (L2CAPConnection) Connector.open(PROTOCOL +
serverDeviceToBeFoundNokia6600 + ":" + serviceNumberServer);
String str1 = "Hej!";
String str2 = "Stop Server";
int maxOs = cConn.getTransmitMTU();
int maxIs = cConn.getReceiveMTU();
tbox.insert("Sending 'Hej!'", tbox.size());
cConn.send(str1.getBytes());
byte[] inbuf = new byte[maxIs];
cConn.receive(inbuf);
tbox.insert("Rec '" + inbuf + "'", tbox.size());
tbox.insert("Send 'Stop Server'", tbox.size());
cConn.send(str2.getBytes());
byte[] inbuf2 = new byte[maxIs];
cConn.receive(inbuf2);
tbox.insert("Rec '" + inbuf2 + "'", tbox.size());
} catch (IOException e) {
tbox.insert("IOExc:" + e.getMessage() + "'", tbox.size());
}The server thread:
class MyThread extends Thread {
L2CAPConnectionNotifier server;
LocalDevice local;
L2CAPConnection conn;
public void kill() {
try { conn.close(); } catch (IOException e) { e.printStackTrace(); }
try { server.close(); } catch (IOException e) { e.printStackTrace(); }
public void run() {
server = null;
String message = "";
byte[] data = null;
int length;
try {
local = LocalDevice.getLocalDevice();
local.setDiscoverable(DiscoveryAgent.GIAC);
} catch (BluetoothStateException e) {
tbox.insert("Failed to start service", tbox.size());
tbox.insert("BluetoothStateException: " + e.getMessage(), tbox.size());
return;
try {
server = (L2CAPConnectionNotifier) Connector.open(
PROTOCOL + "localhost:" + serviceNumberServer);
tbox.insert(local.getBluetoothAddress()+":"+serviceNumberServer, tbox.size());
} catch (IOException e) {
tbox.insert("Failed to start service", tbox.size());
tbox.insert("IOException: " + e.getMessage(), tbox.size());
return;
tbox.insert("Starting " + PROTOCOL + " Print Server", tbox.size());
while (!(message.equals("Stop Server"))) {
message = "";
conn = null;
try {
conn = server.acceptAndOpen();
tbox.insert("Receiving...", tbox.size());
length = conn.getReceiveMTU();
data = new byte[length];
length = conn.receive(data);
while (length != -1) {
message += new String(data, 0, length);
tbox.insert("Rec (part) '" + new String(data, 0, length), tbox.size());
try {
length = conn.receive(data);
tbox.insert("RECEIVED!", tbox.size());
} catch (IOException e) {
tbox.insert("EXCEPTION!"+e.getMessage(), tbox.size());
break;
tbox.insert("Received '" + message + "'. Sending it back...", tbox.size());
int maxOs = conn.getTransmitMTU();
conn.send(message.getBytes());
} catch (IOException e) {
tbox.insert("IOException: " + e.getMessage(), tbox.size());
} finally {
if (conn != null)
try { conn.close(); } catch (IOException e) {}
try { server.close(); } catch (IOException e) {}
tbox.insert("Server stopped", tbox.size());
};Some clarifications needed to the above:
String PROTOCOL = "btl2cap://";
String serverDeviceToBeFoundNokia6600 = "006057F3E9E0";
String serviceNumberServer = "432";
TextBox tbox; -
What is wrong with these PL/SQL codes?
DECLARE
CURSOR C_All_Tables IS select table_name from user_tables where substr(table_name,1,1)='B';
BEGIN
For cnt1 in C_All_Tables Loop
Declare
CURSOR C_EachTable IS select NAME from cnt1.table_name;
V_Result varchar2(20);
Begin
for cnt2 in C_EachTable Loop
V_Result := substr(cnt2.name,1,3);
EXIT when substr(cnt2.name,1,3) = 'K01' ;
if V_Result != 'K01' then
delete from cnt1.table_name where substr(NAME,1,3)=V_result;
end if;
end loop;
End;
End Loop;
Commit;
END;
Here is the errors
Error report:
ORA-06550: line 8, column 56:
PL/SQL: ORA-00942: table or view does not exist
ORA-06550: line 8, column 34:
PL/SQL: SQL Statement ignored
ORA-06550: line 12, column 43:
PLS-00364: loop index variable 'CNT2' use is invalid
ORA-06550: line 12, column 24:
PL/SQL: Statement ignored
ORA-06550: line 13, column 40:
PLS-00364: loop index variable 'CNT2' use is invalid
ORA-06550: line 13, column 23:
PL/SQL: Statement ignored
ORA-06550: line 15, column 37:
PL/SQL: ORA-00942: table or view does not exist
ORA-06550: line 15, column 19:
PL/SQL: SQL Statement ignored
06550. 00000 - "line %s, column %s:\n%s"
*Cause: Usually a PL/SQL compilation error.
*Action:
Could someone help me fix it. Thanks so much.something like this maybe?
begin
for c in (select table_name from user_tables where substr(table_name,1,1)='B' order by substr(table_name,1,3) ) loop
EXIT when substr(c.table_name,1,3) = 'K01';
execute immediate ('delete from '||c.table_name||' where substr('||c.table_name||',1,3)= substr('||c.table_name||',1,3)');
end loop;
end; -
What's wrong with this?HELP
What's wrong with this piece of code:
clickhereButton.addActionListener(this);
^
That's my button's name.
Everytime I try to complie the .java file with this code in it it says:
Identifier expected: clickhereButton.addActionListener(this);
^
Please help.You must have that code in a method or an initilizer block... try moving it to eg. the constructor.
-
What is wrong with this code? on(release) gotoAndPlay("2")'{'
Please could someone tell me what is wrong with this code - on(release)
gotoAndPlay("2")'{'
this is the error that comes up and i have tried changing it but it is not working
**Error** Scene=Scene 1, layer=Layer 2, frame=1:Line 2: '{' expected
gotoAndPlay("2")'{'
Total ActionScript Errors: 1 Reported Errors: 1
ThanksIf you have a frame labelled "2" then it should be:
on (release) {
this._parent.gotoAndPlay("2");
or other wise just the following to go to frame 2:
on (release) {
this._parent.gotoAndPlay(2);
You just had a missing curly bracket... -
I can't figure out what's wrong with this code
First i want this program to allow me to enter a number with the EasyReader class and depending on the number entered it will show that specific line of this peom:
One two buckle your shoe
Three four shut the door
Five six pick up sticks
Seven eight lay them straight
Nine ten this is the end.
The error message i got was an illegal start of expression. I can't figure out why it is giving me this error because i have if (n = 1) || (n = 2) statements. My code is:
public class PoemSeventeen
public static void main(String[] args)
EasyReader console = new EasyReader();
System.out.println("Enter a number for the poem (0 to quit): ");
int n = console.readInt();
if (n = 1) || (n = 2)
System.out.println("One, two, buckle your shoe");
else if (n = 3) || (n = 4)
System.out.println("Three, four, shut the door");
else if (n = 5) || (n = 6)
System.out.println("Five, six, pick up sticks");
else if (n = 7) || (n = 8)
System.out.println("Seven, eight, lay them straight");
else if (n = 9) || (n = 10)
System.out.println("Nine, ten, this is the end");
else if (n = 0)
System.out.println("You may exit now");
else
System.out.println("Put in a number between 0 and 10");
I messed around with a few other thing because i had some weird errors before but now i have narrowed it down to just this 1 error.
The EasyReader class code:
// package com.skylit.io;
import java.io.*;
* @author Gary Litvin
* @version 1.2, 5/30/02
* Written as part of
* <i>Java Methods: An Introduction to Object-Oriented Programming</i>
* (Skylight Publishing 2001, ISBN 0-9654853-7-4)
* and
* <i>Java Methods AB: Data Structures</i>
* (Skylight Publishing 2003, ISBN 0-9654853-1-5)
* EasyReader provides simple methods for reading the console and
* for opening and reading text files. All exceptions are handled
* inside the class and are hidden from the user.
* <xmp>
* Example:
* =======
* EasyReader console = new EasyReader();
* System.out.print("Enter input file name: ");
* String fileName = console.readLine();
* EasyReader inFile = new EasyReader(fileName);
* if (inFile.bad())
* System.err.println("Can't open " + fileName);
* System.exit(1);
* String firstLine = inFile.readLine();
* if (!inFile.eof()) // or: if (firstLine != null)
* System.out.println("The first line is : " + firstLine);
* System.out.print("Enter the maximum number of integers to read: ");
* int maxCount = console.readInt();
* int k, count = 0;
* while (count < maxCount && !inFile.eof())
* k = inFile.readInt();
* if (!inFile.eof())
* // process or store this number
* count++;
* inFile.close(); // optional
* System.out.println(count + " numbers read");
* </xmp>
public class EasyReader
protected String myFileName;
protected BufferedReader myInFile;
protected int myErrorFlags = 0;
protected static final int OPENERROR = 0x0001;
protected static final int CLOSEERROR = 0x0002;
protected static final int READERROR = 0x0004;
protected static final int EOF = 0x0100;
* Constructor. Prepares console (System.in) for reading
public EasyReader()
myFileName = null;
myErrorFlags = 0;
myInFile = new BufferedReader(
new InputStreamReader(System.in), 128);
* Constructor. opens a file for reading
* @param fileName the name or pathname of the file
public EasyReader(String fileName)
myFileName = fileName;
myErrorFlags = 0;
try
myInFile = new BufferedReader(new FileReader(fileName), 1024);
catch (FileNotFoundException e)
myErrorFlags |= OPENERROR;
myFileName = null;
* Closes the file
public void close()
if (myFileName == null)
return;
try
myInFile.close();
catch (IOException e)
System.err.println("Error closing " + myFileName + "\n");
myErrorFlags |= CLOSEERROR;
* Checks the status of the file
* @return true if en error occurred opening or reading the file,
* false otherwise
public boolean bad()
return myErrorFlags != 0;
* Checks the EOF status of the file
* @return true if EOF was encountered in the previous read
* operation, false otherwise
public boolean eof()
return (myErrorFlags & EOF) != 0;
private boolean ready() throws IOException
return myFileName == null || myInFile.ready();
* Reads the next character from a file (any character including
* a space or a newline character).
* @return character read or <code>null</code> character
* (Unicode 0) if trying to read beyond the EOF
public char readChar()
char ch = '\u0000';
try
if (ready())
ch = (char)myInFile.read();
catch (IOException e)
if (myFileName != null)
System.err.println("Error reading " + myFileName + "\n");
myErrorFlags |= READERROR;
if (ch == '\u0000')
myErrorFlags |= EOF;
return ch;
* Reads from the current position in the file up to and including
* the next newline character. The newline character is thrown away
* @return the read string (excluding the newline character) or
* null if trying to read beyond the EOF
public String readLine()
String s = null;
try
s = myInFile.readLine();
catch (IOException e)
if (myFileName != null)
System.err.println("Error reading " + myFileName + "\n");
myErrorFlags |= READERROR;
if (s == null)
myErrorFlags |= EOF;
return s;
* Skips whitespace and reads the next word (a string of consecutive
* non-whitespace characters (up to but excluding the next space,
* newline, etc.)
* @return the read string or null if trying to read beyond the EOF
public String readWord()
StringBuffer buffer = new StringBuffer(128);
char ch = ' ';
int count = 0;
String s = null;
try
while (ready() && Character.isWhitespace(ch))
ch = (char)myInFile.read();
while (ready() && !Character.isWhitespace(ch))
count++;
buffer.append(ch);
myInFile.mark(1);
ch = (char)myInFile.read();
if (count > 0)
myInFile.reset();
s = buffer.toString();
else
myErrorFlags |= EOF;
catch (IOException e)
if (myFileName != null)
System.err.println("Error reading " + myFileName + "\n");
myErrorFlags |= READERROR;
return s;
* Reads the next integer (without validating its format)
* @return the integer read or 0 if trying to read beyond the EOF
public int readInt()
String s = readWord();
if (s != null)
return Integer.parseInt(s);
else
return 0;
* Reads the next double (without validating its format)
* @return the number read or 0 if trying to read beyond the EOF
public double readDouble()
String s = readWord();
if (s != null)
return Double.parseDouble(s);
// in Java 1, use: return Double.valueOf(s).doubleValue();
else
return 0.0;
Can anybody please tell me what's wrong with this code? ThanksString[] message = {
"One, two, buckle your shoe",
"One, two, buckle your shoe",
"Three, four, shut the door",
"Three, four, shut the door",
"Five, six, pick up sticks",
"Five, six, pick up sticks",
"Seven, eight, lay them straight",
"Seven, eight, lay them straight",
"Nine, ten, this is the end",
"Nine, ten, this is the end"
if(n>0)
System.out.println(message[n]);
else
System.exit(0); -
[b]Does anybody know what is wrong with my code[/b]
I cannot see what is wrong with this code but i can't get it to compile. when i try to compile it i get the
"Exception in thread "main" java.lang.NoClassDefFoundError:
Is this a problem with compiling or is it a code error?
Here is my code
public class IntCalc{
int value;
public IntCalc(){
value = 0;
public void add(int number) {
value = value + number;
public void subtract(int number){
value = value - number;
public int getValue() {
return value;
Message was edited by:
SHIFTERYoud don't have a class file. Compile it first then run it. If your compiler isnt making the .class file tell me and ill give you a link to a realy good java compiler.
-
JScrollPane, what is wrong with my code?
Hi, I appreciated if you helped me(perhaps by trying it out yourself?)
I wanted my JScrollPane to display what is drawn on my canvas (which may be large)by scrolling, but it says it doesn't need any vertical and horizontal scroll bars. Here is the code that has this effect
import javax.swing.*;
import java.awt.*;
public class WhatsWrong extends JApplet{
public void init(){
Container appletCont = getContentPane();
appletCont.setLayout(new BorderLayout());
JPanel p = new JPanel();
p.setLayout(new BorderLayout());
p.add(new LargeCanvas(),BorderLayout.CENTER);
int ver = ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED;
int hor = ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED;
JScrollPane jsp = new JScrollPane(p,ver,hor);
appletCont.add(jsp,BorderLayout.CENTER);
class LargeCanvas extends Canvas{
public LargeCanvas(){
super();
setBackground(Color.white);
public void paint(Graphics g){
g.drawRect(50,50,700,700);
and the html code:
<html>
<body>
<applet code="WhatsWrong" width = 300 height = 250>
</applet>
</body>
</html>
What shall I do?
Thanks in advance.What is wrong with your code is that your class, LargeCanvas must implement the Scrollable interface in order to be scrolled by a JScrollPane.
A comment regarding your use of Canvas and Swing components: The Java Tutorial recommends that you extend JPanel to do custom painting. Canvas is what they call a "heavyweight" component and they recommend not to mix lightweight (Swing) components and heavyweight components.
There is a lot more information on custom painting on the Java Tutorial in the Lesson "Creating a GUI with Swing. -
What's wrong with my code? compliation error
There is a compilation error in my program
but i follow others sample prog. to do, but i can't do it
Please help me, thanks!!!
private int selectedRow, selectedCol;
final JTable table = new JTable(new MyTableModel());
public temp() {
super(new GridLayout(1, 0));
table.setPreferredScrollableViewportSize(new Dimension(600, 200));
table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
ListSelectionModel rowSM = table.getSelectionModel();
rowSM.addListSelectionListener(new ListSelectionListener() {
public void valueChanged(ListSelectionEvent e) {
//Ignore extra messages.
if (e.getValueIsAdjusting()) return;
ListSelectionModel lsm = (ListSelectionModel)e.getSource();
if (lsm.isSelectionEmpty()) {
System.out.println("No rows are selected.");
else {
selectedRow = lsm.getMinSelectionIndex();
System.out.println("Row " + selectedRow+ " is now selected.");
JScrollPane scrollPane = new JScrollPane(table);
add(scrollPane);
createPopupMenu();
public void createPopupMenu() {
//Create the popup menu.
JPopupMenu popup = new JPopupMenu();
// display item
JMenuItem menuItem = new JMenuItem("Delete selected");
popup.add(menuItem);
menuItem.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
System.out.println("Display selected.");
System.out.println("ClientID: "+table.getValueAt(selectedRow,0));
int index = table.getSelectedColumn();
table.removeRow(index); <-------------------------------compliation error
}}); //what's wrong with my code? can anyone tell
//me what careless mistake i made?
MouseListener popupListener = new PopupListener(popup);
table.addMouseListener(popupListener);
public class MyTableModel extends AbstractTableModel {
private String[] columnNames = { "ClientID", "Name", "Administrator" };
private Vector data = new Vector();
class Row{
public Row(String c, String n, String a){
clientid = c;
name = n;
admin = a;
private String clientid;
private String name;
private String admin;
public MyTableModel(){}
public void removeRow(int r) {
data.removeElementAt(r);
fireTableChanged(null);
public int getColumnCount() {
return columnNames.length;
public int getRowCount() {
return data.size();
public String getColumnName(int col) {
return columnNames[col];
public Object getValueAt(int row, int col) {
return "";
public boolean isCellEditable(int row, int col) {
return false;
public void setValueAt(Object value, int row, int col) {}
}Inside your table model you use a Vector to hold your data. Create a method on your table model
public void removeRow(int rowIndex)
data.remove(rowIndex); // Remove the row from the vector
fireTableRowDeleted(rowIndex, rowIndex); // Inform the table that the rwo has gone
[/data]
In the class that from which you wish to call the above you will need to add a reference to your table model. -
What's wrong with my code for comparing date retreived from db and sysdate?
Hi all,
I need to retrive date from the DB and compare it to system date.i have posted the code below.i get java.sql.SQL Exception:Io exception:Socket closed.
What's wrong with the code?please help me.Thanks in advance.
public boolean date() throws IOException, SQLException {
Connection con1;
long millis = System.currentTimeMillis();
Timestamp timestamp = new java.sql.Timestamp(millis);
ResultSet rs4 = null;
try
Class.forName("oracle.jdbc.driver.OracleDriver");
con = DriverManager.getConnection(
"jdbc:oracle:thin:@abc:1605:xyz",
"cdf", "cdf");
Statement stmt_exp = con.createStatement();
rs4 = stmt_exp.executeQuery("SELECT DATE FROM TABLE_NAME")
while (rs4.next()) {
Timestamp timestamp2 = rs4.getTimestamp("expire_date");
con1.close();
catch (Exception e)
e.printStackTrace();
finally
//ResultSet rs4 = null;
//Timestamp timestamp2;
Timestamp timestamp2 = rs4.getTimestamp("expire_date");
if (timestamp2.compareTo(timestamp) < 0) //sysdate < exp date
return true;
} else {
return false;
}Didn't you understand what BalusC said? You're closing the connection and then trying to use the ResultSet. The ResultSet will be closed when you close the connection so you can't use it anymore.
You should close the connection last thing in your code, probably in a finally. And after you close your ResultSet and Statement.
People on the forum help others voluntarily, it's not their job.
Help them help you.
Learn how to ask questions first: http://faq.javaranch.com/java/HowToAskQuestionsOnJavaRanch
---------------------------------------------------------------- -
What's wrong with the code?
public void run()
try
{ for(;;)
mgr = (RTPManager)RTPManager.newInstance();
mgr.addSessionListener(this);
mgr.addReceiveStreamListener(this);
try{ /*****port1 = port2 = 29261, which port is only used in here
localAddr = new SessionAddress(InetAddress.getLocalHost(), port1);
destAddr = new SessionAddress(ipAddr, port2);
}catch(Exception e)
System.out.println(e + " 4");
try{
mgr.initialize(localAddr);
}catch(Exception e)
System.out.println(e + " 5");
//set buffer
bc = (BufferControl)mgr.getControl("javax.media.control.BufferControl");
if (bc != null)
bc.setBufferLength(20);
try{
mgr.addTarget(destAddr);
}catch(Exception e)
System.out.println(e + " 2");
catch(Exception e)
System.out.println(e+ " 3");
the error when i run the code is like that:
javax.media.rtp.InvalidSessionAddressException: Can't open local data port: 29261
5
java.io.IOException: Address already in use: Cannot bind 2
which means there is error in :
mgr.initialize(localAddr);
mgr.addTarget(destAddr);
But i don't know what's wrong with the code,
can any one help me?I do not find any problem using the same ports for local and destination address with several unicasts. My problems are others.
But note that the error is even at constructing the localAddress, I mean before trying the destinationAddress. Thus the reason cannot be the former is already in use. In fact I think the later belongs to a remote hosts. Likely, it is trying to access the destinationAddress through the localAddress, but this has not been constructed properly. -
What's wrong with the following code?
What's wrong with the following code?
Circle cir1;
double rad = cir1.radiusThe circle Object was never instantiated.
In other words, you have set a declaring of a Circle, but it has not been created in memory yet.
You will create it using the " = new Circle( PARAMETERS_HERE ); "
Or some other method that returns a circle.
Maybe you are looking for
-
Pc no longer works on airport extreme
Airport extreme was working for mac and older PC. Now it isn't. Can anyone help?
-
hi i am a noob in this area..can someone plz help me.. well i have to do a link where it will open the latest file.. how do i do tat...................... String file = "C:/"; File f = new File(file); String [] fileNames = f.list(); File [] fileObjec
-
Sun One Studio 5 Update 1 + Sun One Application Server 8
I haven't been able to setup Sun One Studio 5 to work with Sun One Application Server 8. I already tried with the plugin for netbeans 3.6, but it fails on dependencies. The plugin and dependencies can not be found on the update center. I'd appreciate
-
RTC-5301 the runtime service is not available
we are running client on XP and run time repository on sun 5.8 we were able to connect to the repository, until we rebooted the Database. Then we getting 5301 meesage when logging in to the run time. 1. running start_service script as owb run time re
-
hello experts what is this error ??would you please tell me how to rectify below issue, ALERT for DX1EUR \ DX1_100_Business Process Engine \ Definition \ Event linkage propertie YELLOW CCMS alert for monitored object Event linkage properties Alert Te