| Java Native Interface: "Translate" java call to JNI, how to pass parameters, how to show exception |
|
 |
Index ‹ java-programmer
|
- Previous
- 2
- Multiple web applications, single virtual hostHello everyone,
I am attempting to create access logs on a per web application basis,
using a single virtual host in my server.xml file. Here is what I
have so far:
<Host name="www.mysite.com" autoDeploy="false"
deployOnStartup="false"
deployXML="false">
<alias>www.mysite.com</alias>
<Valve
className="org.apache.catalina.valves.AccessLogValve"
prefix="mysite_access" suffix=".log"
pattern="common"
directory="${jboss.server.home.dir}/log"/>
<Context path="" docBase="html" debug="0" reloadable="true"/>
<DefaultContext cookies="true" crossContext="true"
override="true"/>
<Context path="/Web1" docBase="C:\jboss-4.0.1RC2\server\default
\deploy" debug="0" reloadable="true">
<Valve
className="org.apache.catalina.valves.AccessLogValve"
directory="${jboss.server.home.dir}/log"
prefix="my_web1" suffix=".log" resolveHosts="false" pattern="combined"/
>
</Context>
<Context path="/images" appBase="" docBase="C:
\jboss-4.0.1RC2\server\default\images" debug="99">
</Context>
<Context path="/Web2" docBase="C:\jboss-4.0.1RC2\server\default
\deploy" debug="0" reloadable="true">
<Valve className="org.apache.catalina.valves.AccessLogValve"
directory="${jboss.server.home.dir}/log"
prefix="my_web2" suffix=".log" resolveHosts="false" pattern="combined"/
>
</Context>
</Host>
Everything is working as it should, except that when I hit www.mysite.com/Web1
or www.mysite.com/Web2 the only log that gets updated is
mysite_access.
Can someone please explain to me how to go about writing to the
my_web1.log and my_web2.log files for those applications?
Thanks,
Monica
- 2
- Applet JBuilder(Borland) JDeveloper(Oracle) IE 6.0Hi All!
JBuilder v7 vm 1.3.1-b24
JSeveloper v 9.0.5 vm 1.4.2_03-b02
Applet(for JBulider(Borland) a2, for JDeveloper(Oracle) a1):
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
public class a2 extends Applet {
private boolean isStandalone = false;
//Get a parameter value
public String getParameter(String key, String def) {
return isStandalone ? System.getProperty(key, def) :
(getParameter(key) != null ? getParameter(key) : def);
}
//Construct the applet
public a2() {
}
//Initialize the applet
public void init() {
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
}
//Component initialization
private void jbInit() throws Exception {
}
//Get Applet information
public String getAppletInfo() {
return "Applet Information";
}
//Get parameter info
public String[][] getParameterInfo() {
return null;
}
}
Compile in JBuilder & Jdeveloper
Web server - Apache from Oracle Application server on OS Redhat RHES.
index.html:
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=windows-1251"/>
<TITLE>Test</TITLE>
</HEAD>
<BODY>
<H2>Test</H2>
<UL>
<LI><a href="joracle.html">Applet JDeveloper Oracle</a></LI>
<LI><a href="jborland.html">Apllet JBuilder Borland</a></LI>
</UL>
</BODY>
</HTML>
joracle.html:
<HTML>
<HEAD>
<TITLE>
Test
</TITLE>
</HEAD>
<BODY>
<H2>
This is sample HTML text.
</H2>
<BR>
<APPLET CODEBASE="." CODE="a1" HEIGHT="600" WIDTH="600" ALIGN="bottom">^M
<PARAM NAME="" VALUE="">This browser does not appear to support Applets.</APPLET>
</BODY>
</HTML>
jborland.html:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1251">
<title>
HTML Test Page
</title>
</head>
<body>
Applet2 will appear below in a Java enabled browser.<br>
<applet>
codebase = "."
code = "a2"
name = "TestApplet"
width = "400"
height = "300"
hspace = "0"
vspace = "0"
align = "middle"
>
</applet>
</body>
</html>
Launch IE6.0 with java console.
Borland - OK!
Oracle
Error loading class: a1
java.lang.NoClassDefFoundError
java.lang.ClassNotFoundException: a1
at com/ms/vm/loader/URLClassLoader.loadClass
at com/ms/vm/loader/URLClassLoader.loadClass
at com/ms/applet/AppletPanel.securedClassLoad
at com/ms/applet/AppletPanel.processSentEvent
at com/ms/applet/AppletPanel.processSentEvent
at com/ms/applet/AppletPanel.run
at java/lang/Thread.run
WHY???????
Help me please!!!!
Best regards.
- 3
- java front end that creates database appsDoes there exist a java front end like this database admin tool:
http://qform.sourceforge.net/
but that also allows you to create database applications (similar to
Rekall if you are familiar with that, uses python)
ie. allows you to create your own forms for data input input etc,
provides reporting, scripting etc
Thanks
Wayne
- 4
- Font dialog objectHello all..
Just wondering if there is a Font dialog object in Java. Looking at the
API's I did not see one.
Thanks in Advance...
IchBin
__________________________________________________________________________
'The meeting of two personalities is like the contact of two chemical
substances: if there is any reaction, both are transformed.'
- Carl Gustav Jung, (1875-1961), psychiatrist and psychologist
- 5
- Oracle consultants available immediately with KraftwareContact : Mandar
Direct : 402 408 6601/402 408 3687
Email : email***@***.com
Hi,
We have the following Oracle consultants available immediately with
us:
1) Oracle HRMS techno-functional consultant
2) Oracle Apps financials consultant
3) Oracle PL/SQL developer
4) Oracle HRMS functional consultant
Please feel free to contact us for additional information.
Thanks & Regards,
Mandar
Direct: 402 408 6601/402 408 3687
Email: email***@***.com
- 9
- servlet communicationi`m using servlet technology in a very unusual way and i`m now
searching for a better solution:
there is a server, a embedded device and a user, which logs onto the
server, for access to the embedded device. the server now calls the
embedded device via gsm, to tell the embedded device to connect to the
internet and callback. after that, the data from the embedded device is
transfered to the server and displayed as a html-file. this is now done
via polling the application context, where all online-devices are
stored.
problem now is: i want to figure out a better way, how to get the
server or rather the html file, which is refreshed every 15 seconds, to
see if the device is online now, to know.
is there some way to exchange the data between this servlets?
- 9
- NIO! Nein!I recently had the misfortune of trying out a InputStream.available()
command, only to find out it doesn't work on sockets.
I've found that the solution to my problem is the Nio SocketChannel
class, and now I have only one question:
What was Sun smoking when they came up with SocketChannel and where can
I get some?
SocketChannel* and the SSLEngine is probably the most complicated way of
doing socket work and I can only wonder whose crazy idea it was.
Why couldn't they just make .available() work as advertised?
*sigh*
Just wanted to publically complain about unncessary complication.
- 9
- static methods dont inherit (was: Constructor inheritance)"Andrew McDonagh" wrote...
: isamura wrote:
:
: snipped.
:
: > :
: > Can you clarify. Do you mean subclass can't inherit static methods either?
: >
: > ..K
: >
: Correct.
:
: Static methods don't belong to an object like normal (aka Instance)
: methods, they belong to the Class.
:
: When calling a static method you: 'Class.myStaticMethod()'
:
: there's no object, so no Vtable to use to look through.
:
This is going off-topic so I will change the thread topic.
That is puzzling since the following compiles and runs (JDK 1.42):
public static myStaticMethod(); // defined in ClassA
ClassB extends ClassA
ClassB.myStaticMethod(); // no problem
Please explain...
.K
- 10
- in need of swing performance adviceHi All,
I've hit a point in my app when I first call .validate() when loading a
new panel (it is fairly complex), it takes up to 5 seconds to load..
There must be something I can do to get over this and was wondering if
anyone had any ideas, if you are interested then my App flows like this..
A quite simple frame is initially created and displayed to user, this
contains a button with 4 buttons, a BIG panel and a menu bar and thats
it for now. the button bar is on left, menu at top and the Panel taking
everything else up..
When the user clicks a button, an appropriate panel is then called and
'loaded into' the big empty space where the panel is. All this is in a
function called Show() which is as follows...
private void show(Component component) {
java.awt.GridBagConstraints gridBagConstraints;
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
gridBagConstraints.weightx = 1.0;
gridBagConstraints.weighty = 1.0;
Main.removeAll();
Main.add(component,gridBagConstraints);
this.validate();
}
when a button is clicked, depending on the button I call the show
command like this...
show(new divelog.forms.ProfilePanel());
The panel that gets loaded that I have a problem with containt 3 panels
in a tabpanel. each one of those has a table, and maybe 10 textfields
per panel.
So not really all that much complexity I dont think, the instantiation
of the panel doesnt take long, so setting up the listeners I have seems
ok its just the moment the .validate() line is executed there is the 5/6
second delay.
Anyone any ideas ? I was thinking Ok I'll create the instances of the
panels in a seperate thread, but as I said the creation doesnt really
take anytime at all.
Thanks in advance.
--------------------
Rgds,
Dave.
- 10
- Jaxb and xsd Help requestedHi,
I'm having problems compiling the classes generated by Jaxb when using
the schema below. (Note the xsd below is part of a bigger xsd file i
just pulled out the section that was giving me issues ). If anyone can
see a problem with the xsd defined below I would appreicate the
information.
The inner interface defined within the generated java class is causing
me issues. The error I get is "Nested type GuestCountType hides an
enclosing type". i would appreciate any help with this.
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:complexType name="GuestCountType">
<xs:sequence>
<xs:element name="GuestCount" maxOccurs="99">
<xs:complexType>
<xs:attributeGroup ref="GuestCountGroup"/>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="IsPerRoom" type="xs:boolean" use="optional"/>
</xs:complexType>
<xs:complexType name="RoomStayCandidateType">
<xs:sequence>
<xs:element name="GuestCounts" type="GuestCountType" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
<xs:attributeGroup name="GuestCountGroup"/>
</xs:schema>
//
// This file was generated by the JavaTM Architecture for XML
Binding(JAXB) Reference Implementation, v1.0.4-b18-fcs
// See <a
href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a>
// Any modifications to this file will be lost upon recompilation of
the source schema.
// Generated on: 2006.05.06 at 09:47:52 EDT
//
package generated;
/**
* Java content class for GuestCountType complex type.
* <p>The following schema fragment specifies the expected content
contained within this java content object. (defined at
file:/C:/xsdfiles/test.xsd line 4)
* <p>
* <pre>
* <complexType name="GuestCountType">
* <complexContent>
* <restriction
base="{http://www.w3.org/2001/XMLSchema}anyType">
* <sequence>
* <element name="GuestCount" maxOccurs="99">
* <complexType>
* <complexContent>
* <restriction
base="{http://www.w3.org/2001/XMLSchema}anyType">
* <attGroup ref="{}GuestCountGroup"/>
* </restriction>
* </complexContent>
* </complexType>
* </element>
* </sequence>
* <attribute name="IsPerRoom"
type="{http://www.w3.org/2001/XMLSchema}boolean" />
* </restriction>
* </complexContent>
* </complexType>
* </pre>
*
*/
public interface GuestCountType {
/**
* Gets the value of the isPerRoom property.
*
*/
boolean isIsPerRoom();
/**
* Sets the value of the isPerRoom property.
*
*/
void setIsPerRoom(boolean value);
/**
* Gets the value of the GuestCount property.
*
* <p>
* This accessor method returns a reference to the live list,
* not a snapshot. Therefore any modification you make to the
* returned list will be present inside the JAXB object.
* This is why there is not a <CODE>set</CODE> method for the
GuestCount property.
*
* <p>
* For example, to add a new item, do as follows:
* <pre>
* getGuestCount().add(newItem);
* </pre>
*
*
* <p>
* Objects of the following type(s) are allowed in the list
* {@link generated.GuestCountType.GuestCountType}
*
*/
java.util.List getGuestCount();
/**
* Java content class for anonymous complex type.
* <p>The following schema fragment specifies the expected content
contained within this java content object. (defined at
file:/C:/xsdfiles/test.xsd line 7)
* <p>
* <pre>
* <complexType>
* <complexContent>
* <restriction
base="{http://www.w3.org/2001/XMLSchema}anyType">
* <attGroup ref="{}GuestCountGroup"/>
* </restriction>
* </complexContent>
* </complexType>
* </pre>
*
*/
public interface GuestCountType {
}
}
- 11
- Attempting to connect to Oracle error...I was attempting to connect to an Oracle instance using the
classes12.zip Oracle thin driver using SQuirrel 1.1final1
[http://squirrelsql.org]. I kept receiving the following Java
Exception:
java.sql.SQLException: Protocol violation
at oracle.jdbc.dbaccess.DBError.check_error(DBError.java:639)
at oracle.jdbc.ttc7.O3log.receive2nd(O3log.java:529)
at oracle.jdbc.ttc7.TTC7Protocol.logon(TTC7Protocol.java:217)
at oracle.jdbc.driver.OracleConnection.<init>(OracleConnection.java:156)
at oracle.jdbc.driver.OracleDriver.getConnectionInstance(OracleDriver.java:231)
at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:208)
at net.sourceforge.squirrel_sql.fw.sql.SQLDriverManager.getConnection(SQLDriverManager.java:99)
at net.sourceforge.squirrel_sql.client.mainframe.action.OpenConnectionCommand.execute(OpenConnectionCommand.java:112)
at net.sourceforge.squirrel_sql.client.mainframe.action.ConnectToAliasCommand$SheetHandler.run(ConnectToAliasCommand.java:345)
at net.sourceforge.squirrel_sql.fw.util.TaskExecuter.run(TaskExecuter.java:65)
at java.lang.Thread.run(Thread.java:536)
SQuirreL was successfully connecting to other Oracle instances, just
not this particular one. I work for a large organization with
multiple Oracle servers. Additionally, the company has just merged
with another company. And it is the other company's server that I am
unable to successfully connect to.
After going through a number of other tangents (network issues, jdbc
configuration details, etc.), I decided to download the classes12.zip
file from Oracle again just in case there was some difference from the
one I already had.
Once the download completed, I checked the file dates within
classes12.zip and their dates were all 2001/Mar/20. Then I went to
the "old" classes12.zip I was currently using in my project and the
file dates within were 1999/Jun/14. Surprise!!!
I did a quick reconfigure of SQuirreL to use the "new" classes12.zip
and was able to connect to the "problem" DB. Apparently there was
some sort of update since I had last dl'ed classes12.zip from Oracle.
Uh...same bloody file name, "classes12.zip", different versions. WTF?
I am confused why Oracle would choose to name the zip the same name
and not increment it when they change it. Grrr! It sure makes it
difficult to talk about "versions" with their naming convention.
And why doesn't Oracle use the industry standard .jar format and
naming convention? Their being "rogue" makes this even more confusing
and frustrating.
Hope you find my travails useful.
Jim
- 16
- JTables and dynamically adding dataHey,
I have a JTable that I want to add a new column to every time someone
clicks a button. I have been reading about extending the
AbstractTableModel, but I don't how this allows you to add a new
column. The examples online show what happens when a user edits a
table, but I don't want that. I want it add when the user presses a
button outside of the table. Some advice would be appreciated.
Thanks
- 16
- Applet is not able to call a URLHello!
I try to make a HTTP Connection through a Applet. The Url is inside
the same CodeBase.
Error message: java.net.UnknownHostException: https://www.unserserver.de
HttpMethod method = null;
try {
URL url = new URL(sUrl);
HostConfiguration hostConfig = new HostConfiguration();
hostConfig.setHost(url.getHost(), url.getPort(), url.getProtocol());
HttpClientParams httpClientParams = new HttpClientParams();
HttpClient httpClient = new HttpClient();
httpClient.setHostConfiguration(hostConfig);
httpClient.setParams(httpClientParams);
method = new GetMethod();
method.setQueryString(url.getQuery());
method.setPath(url.getPath());
int resultCode = httpClient.executeMethod(method);
} catch (Exception e) {
System.out.println(e);
}
I have configured the JVM to use the default settings of the browser,
to connect through the proxy.
Without proxy on my own workstation it works, but for the customer it
doesn't work, allthough he saids, that he has configured the same
settings for the JVM.
Any ideas?
best regards
Alexa
- 16
- UML to JavaHello all,
Does anybody knows a good tutorial for beginners to Make java code out of
UML?
Irlan
- 16
- Question about BigIntegers and byte[] inputI have a byte[] as an input
8B F2 99 7D 67 F1 7C 15 B2 99 2C 2E 33 DD C6 65
2D CD E7 2B
and I feed it into a BigInteger so that I can do simply compares and
easy formatting. However, when I call the toString(16) I get
74 0d 66 82 98 0e 83 ea 4d 66 d3 d1 cc 22 39 9a d2 32 18 d5
I am sure, in it's own way, it is "right" but I need to understand why
this is occurring. Since these values represent hashes I will be for
sure asked by they are the same as what was recorded for them.
Christian
http://christian.bongiorno.org
|
| Author |
Message |
ckirchho

|
Posted: 2006-9-15 19:09:00 |
Top |
java-programmer, Java Native Interface: "Translate" java call to JNI, how to pass parameters, how to show exception
Hallo,
I am at least one step further, now I need to pass the properties to
the call and are now sure how:
Remember: The call I want to implement in Delphi is
java -Xmx256m -cp
"lib\fop\fop.jar;lib\fop\avalon-framework-4.1.3.jar;lib\fop\JimiProClasses.zip"
org.apache.fop.apps.Fop -fo "Data.xml" -c "lib\fop\Config.xml" -pdf
"Data.pdf"
So the parameters that have to be passed are:
-fo "Data.xml"
-c "lib\fop\Config.xml"
-pdf "Data.pdf"
If I do
JNIEnv.CallStaticVoidMethod(Cls, Mid, ['-fo "Data.xml" -c
"Config.xml"-pdf "Cover.pdf"']);
(all parameters in one string) or
JNIEnv.CallStaticVoidMethod(Cls, Mid, ['-fo "Data.xml"', '-c
"Config.xml"', '-pdf "Cover.pdf"']);
(each parameter in a separate string)
...then JNIEnv.ExceptionOccurred is not NULL after the call, thus some
exception occured.
The parameter Args in the call CallStaticVoidMethod() is an array of
const. In CallStaticVoidMethod() the array elements are converted to
JValues with ArgsToJValues().
The exemplary C++ code in the doc PDF works with an ObjectArray created
with NewObjectArray(). I tried that, but CallStaticVoidMethod() won't
accept an ObjectArray, nor would the similar procedures
CallStaticVoidMethodA() or CallStaticVoidMethodV().
By the way: My Delphi app runs in a window, its not a console
application. Can I get the description of the exception with any other
function, or how would I have to use ExceptionDescribe() in this
context?
Regards,
Christian Kirchhoff
|
| |
|
| |
 |
Gordon Beaton

|
Posted: 2006-9-15 19:43:00 |
Top |
java-programmer >> Java Native Interface: "Translate" java call to JNI, how to pass parameters, how to show exception
On 15 Sep 2006 04:09:03 -0700, email***@***.com wrote:
> The parameter Args in the call CallStaticVoidMethod() is an array of
> const. In CallStaticVoidMethod() the array elements are converted to
> JValues with ArgsToJValues().
> The exemplary C++ code in the doc PDF works with an ObjectArray created
> with NewObjectArray(). I tried that, but CallStaticVoidMethod() won't
> accept an ObjectArray, nor would the similar procedures
> CallStaticVoidMethodA() or CallStaticVoidMethodV().
Keep in mind that even though you pass several "program arguments" to
the JVM, the method you are invoking takes only one argument, an array
of String. When you run this from a command shell, the launcher
collects the arguments into a single array of String.
So with CallStaticVoidMethod() you need to create an array of String
objects, i.e. one String per program argument, and pass that to the
method. Note that this is *not* the same as a Delphi array of pointers
to the Delphi string type, you need to create actual Java String
objects and a Java String array. I showed you how to do that in my
earlier code example.
I don't know what the conversion ArgsToJValues does, so I can't help
you there.
If you want to use CallStaticVoidMethodA() instead, then you would
still need to create the Strings and the String array, but you would
additionally need an array of jvalue, whose element 0 is a reference
to the String array. There is little point in using that function in
this case.
Finally I doubt that CallStaticVoidV() is what you want (and I doubt
that you can even create the necessary va_list in Delphi).
Since this is a common thing to do, I'm sure you should be able to
find Delphi examples somewhere that show you how to do this.
> By the way: My Delphi app runs in a window, its not a console
> application. Can I get the description of the exception with any
> other function, or how would I have to use ExceptionDescribe() in
> this context?
AFAIK there is only ExceptionDescribe().
/gordon
--
[ don't email me support questions or followups ]
g o r d o n + n e w s @ b a l d e r 1 3 . s e
|
| |
|
| |
 |
ckirchho

|
Posted: 2006-9-15 22:30:00 |
Top |
java-programmer >> Java Native Interface: "Translate" java call to JNI, how to pass parameters, how to show exception
Hallo,
> So with CallStaticVoidMethod() you need to create an array of String
> objects, i.e. one String per program argument, and pass that to the
> method. Note that this is *not* the same as a Delphi array of pointers
> to the Delphi string type, you need to create actual Java String
> objects and a Java String array. I showed you how to do that in my
> earlier code example.
Unfortunately not. Here is the definition of the procedure in Delphi:
procedure CallStaticVoidMethod(AClass: JClass; MethodID: JMethodID;
const Args: array of const);
Args is an "array of const". I tried creating the Object array with
NewObjectArray, adding additional ObjectArrayElements, and pass that as
Args to CallStaticVoidMethod, but the compiler errored "Incompatible
Types 'Array' and 'JObject'"
I have to use an array of const, but in the way I described earlier it
doesn't seem to work.
Regards,
Christian
|
| |
|
| |
 |
Gordon Beaton

|
Posted: 2006-9-15 22:51:00 |
Top |
java-programmer >> Java Native Interface: "Translate" java call to JNI, how to pass parameters, how to show exception
On 15 Sep 2006 07:29:58 -0700, email***@***.com wrote:
> Args is an "array of const".
I haven't got a clue what "array of const" is.
> I tried creating the Object array with NewObjectArray, adding
> additional ObjectArrayElements, and pass that as Args to
> CallStaticVoidMethod, but the compiler errored "Incompatible Types
> 'Array' and 'JObject'"
But Array should be assignable to JObject. The corresponding types in
Java and JNI are compatible (Arrays are Objects), so perhaps you need
to use an explicit cast, or you need to assign the result of the array
creation to a JObject instead of an Array and pass that. Other than
that, I'm out of ideas.
/gordon
--
[ don't email me support questions or followups ]
g o r d o n + n e w s @ b a l d e r 1 3 . s e
|
| |
|
| |
 |
ckirchho

|
Posted: 2006-9-15 22:55:00 |
Top |
java-programmer >> Java Native Interface: "Translate" java call to JNI, how to pass parameters, how to show exception
P.S.: Here is the code for the preocedure CallStaticVoidMethod in
Delphi:
procedure TJNIEnv.CallStaticVoidMethod(AClass: JClass; MethodID:
JMethodID; const Args: array of const);
begin
Env^.CallStaticVoidMethodA(Env, AClass, MethodID,
ArgsToJValues(Args));
end;
ArgsToJValues returns a PJValue, by the way.
My problem seems to be which syntax I have to use for the parameters.
JNIEnv.CallStaticVoidMethod(Cls, Mid, ['-fo "Data.xml"', '-c
"Config.xml"', '-pdf Cover.pdf"']);
seems to be wrong
JNIEnv.CallStaticVoidMethod(Cls, Mid, ['fo="Data.xml"',
'c="Config.xml"', 'pdf="Cover.pdf"']);
is wrong, too.
JNIEnv.CallStaticVoidMethod(Cls, Mid, ['fo=Data.xml', 'c=Config.xml',
'pdf=Cover.pdf']);
is wrong, too.
But then again, in my actual code I use full path names, and maybe here
I have to use another syntax. But I tried it with slashes instead of
backslashes, too, and it doesn't work...
Christian
|
| |
|
| |
 |
ckirchho

|
Posted: 2006-9-15 23:48:00 |
Top |
java-programmer >> Java Native Interface: "Translate" java call to JNI, how to pass parameters, how to show exception
I managed to change the code and use CallStaticVoidMethodA in a way
that the compiler doesn't throw an error.
Args := JNIEnv.NewObjectArray(3, StrClass, JStr1);
JNIEnv.SetObjectArrayElement(Args, 2, JStr2);
JNIEnv.SetObjectArrayElement(Args, 3, JStr3);
JNIEnv.CallStaticVoidMethodA(Cls, Mid, @Args);
@Args means that the pointer to Args is passed as the paranmeter. But
when I run this code, the programmcloses itself without an error or
exception, which is even worse than before.
So I went back to CallStaticVoidMethod(). I found a way to show the
error, at least as a number:
AException := JNIEnv.ExceptionOccurred;
if AException <> nil then
ShowMessage(Format('CheckJava: %d', [DWORD(AException)]));
I tried to make the call in two ways:
Pass all parameters in one string:
JNIEnv.CallStaticVoidMethod(Cls, Mid, ['-fo "Data.xml" -c "Config.xml"
-pdf Cover.pdf"']);
ErrorCode 180098752
Pass the parameters in separate strings:
JNIEnv.CallStaticVoidMethod(Cls, Mid, ['-fo "Data.xml"', '-c
"Config.xml"', '-pdf Cover.pdf"']);
ErrorCode 180098744
Just a test: Pass an empty string
JNIEnv.CallStaticVoidMethod(Cls, Mid, ['']);
ErrorCode 180098756
I believe that it's just the way the parameter string is set up that is
wrong. The syntax seems to be different than starting java from a batch
file.
Like with the problem I had before where just the quotes were wrong and
had to be deleted.
Does anybody by any chance now what those error codes mean?
By the way: Is there any way to get the messages that a java method
prints (e.g. in a DOS Box when the script is started from within a DOS
Box) when the method is called from within Delphi?
I will be on vacation til Oct 3rd, and hopefully I will find a solution
afterwards.
Best Regards,
Christian.
Gordon Beaton wrote:
> On 15 Sep 2006 07:29:58 -0700, email***@***.com wrote:
> > Args is an "array of const".
>
> I haven't got a clue what "array of const" is.
>
> > I tried creating the Object array with NewObjectArray, adding
> > additional ObjectArrayElements, and pass that as Args to
> > CallStaticVoidMethod, but the compiler errored "Incompatible Types
> > 'Array' and 'JObject'"
>
> But Array should be assignable to JObject. The corresponding types in
> Java and JNI are compatible (Arrays are Objects), so perhaps you need
> to use an explicit cast, or you need to assign the result of the array
> creation to a JObject instead of an Array and pass that. Other than
> that, I'm out of ideas.
>
> /gordon
>
> --
> [ don't email me support questions or followups ]
> g o r d o n + n e w s @ b a l d e r 1 3 . s e
|
| |
|
| |
 |
Chris Uppal

|
Posted: 2006-9-16 0:23:00 |
Top |
java-programmer >> Java Native Interface: "Translate" java call to JNI, how to pass parameters, how to show exception
email***@***.com wrote:
> Args is an "array of const". I tried creating the Object array with
> NewObjectArray, adding additional ObjectArrayElements, and pass that as
> Args to CallStaticVoidMethod, but the compiler errored "Incompatible
> Types 'Array' and 'JObject'"
Can you clarify exactly which of the three forms of CallStaticVoidMethod() you
are using ? There are three of them:
CallStaticVoidMethod()
CallStaticVoidMethodA()
CallStaticVoidMethodV()
Also, can we be clear that you are attempting to provide /one/ Java object as
the single parameter to the Java method you want to call ? That object is an
Java array (created with NewObjectArray()) but it is a single object.
If you were working in C, then once you have created and populated that single
Java object, there would then be three different ways you could invoke the
method.
Using CallStaticVoidMethod()
In this case you pass the jobject as one parameter to the call (in
addition to the class and method ID). You should be wary of using
this form from Delphi; unless Delphi understands 'C' variadic functions
(functions which take variable numbers of arguments like C's printf()).
I doubt whether it does, at least on the basis that 'C'-style variadic
functions are incompatible with both the semantics and typical
implementations of Pascal. It is possible that Borland have extended
that so that Delphi can work with 'C's variadic functions, but you should
check. Note that the ability to work with variadic functions at all
doesn't necessarily imply the ability to work with the specific
stack layout used by a MSVC variadic __stdcall function (I vaguely
seem to remember that Borland's C++Builder didn't use the same
layouts but that's a very long time ago...)
Using CallStaticVoidMethodA()
In this case you pass a /C/ array as the parameter to the call. That
array holds each of the parameters which should be passed to the
Java method. So in this case that array should contain one element
which itself is a Java array containing your parameter strings.
Using CallStaticVoidMethodV()
If you are working in C and know what you are doing then this can
be useful. In other circumstances -- such as seem to apply here -- you
should just ignore it.
BTW: going back to an earlier post of yours. You said that you were setting a
classpath like:
-Djava.class.path=C:\subfolder1\subfolder2\HWJava.class
If that's still true, and if 'HWJava.class' is not the (very strange) name of a
directory, then your application is only working by the most bizarre of
accidents -- there should never be any .class files explicitly mentioned on the
classpath. Just directories and JAR files (re-read Gordon's earlier post if
that's not clear).
-- chris
|
| |
|
| |
 |
ckirchho

|
Posted: 2006-10-10 0:52:00 |
Top |
java-programmer >> Java Native Interface: "Translate" java call to JNI, how to pass parameters, how to show exception
Hallo Chris,
sorry for the late answer, I was on vacation for a couple of weeks.
Here are some answers to your questions/comments:
Chris Uppal wrote:
> email***@***.com wrote:
>
> > Args is an "array of const". I tried creating the Object array with
> > NewObjectArray, adding additional ObjectArrayElements, and pass that as
> > Args to CallStaticVoidMethod, but the compiler errored "Incompatible
> > Types 'Array' and 'JObject'"
>
> Can you clarify exactly which of the three forms of CallStaticVoidMethod() you
> are using ? There are three of them:
>
> CallStaticVoidMethod()
> CallStaticVoidMethodA()
> CallStaticVoidMethodV()
Right now I concentrate on CallStaticVoidMethod()
>
> Also, can we be clear that you are attempting to provide /one/ Java object as
> the single parameter to the Java method you want to call ? That object is an
> Java array (created with NewObjectArray()) but it is a single object.
>
Well, as I wrote before CallStaticVoidMethod is defined with an array
of const as the parameter. It is a Delphi type. So I have to deal with
that
CallStaticVoidMethodA() works with a PJValue, which is defined in unit
JNI.
CallStaticVoidMethodV() works with a type called va_list, which is
Delphi again.
Yes, in any case it is one single object, that is passed
> If you were working in C, then once you have created and populated that single
> Java object, there would then be three different ways you could invoke the
> method.
>
> Using CallStaticVoidMethod()
> In this case you pass the jobject as one parameter to the call (in
> addition to the class and method ID). You should be wary of using
> this form from Delphi; unless Delphi understands 'C' variadic functions
> (functions which take variable numbers of arguments like C's printf()).
> I doubt whether it does, at least on the basis that 'C'-style variadic
> functions are incompatible with both the semantics and typical
> implementations of Pascal. It is possible that Borland have extended
> that so that Delphi can work with 'C's variadic functions, but you should
> check. Note that the ability to work with variadic functions at all
> doesn't necessarily imply the ability to work with the specific
> stack layout used by a MSVC variadic __stdcall function (I vaguely
> seem to remember that Borland's C++Builder didn't use the same
> layouts but that's a very long time ago...)
>
> Using CallStaticVoidMethodA()
> In this case you pass a /C/ array as the parameter to the call. That
> array holds each of the parameters which should be passed to the
> Java method. So in this case that array should contain one element
> which itself is a Java array containing your parameter strings.
>
> Using CallStaticVoidMethodV()
> If you are working in C and know what you are doing then this can
> be useful. In other circumstances -- such as seem to apply here -- you
> should just ignore it.
>
> BTW: going back to an earlier post of yours. You said that you were setting a
> classpath like:
> -Djava.class.path=C:\subfolder1\subfolder2\HWJava.class
> If that's still true, and if 'HWJava.class' is not the (very strange) name of a
> directory, then your application is only working by the most bizarre of
> accidents -- there should never be any .class files explicitly mentioned on the
> classpath. Just directories and JAR files (re-read Gordon's earlier post if
> that's not clear).
That was for testing reasons and I corrected that later. My actual
project sets the classpath to folder, JAR files and ZIP files.
I'll try to find out if I get CallStaticVoidMethod(),
CallStaticVoidMethodA() or CallStaticVoidMethodV() to work anyhow...
Rgeards,
Christian
|
| |
|
| |
 |
| |
 |
Index ‹ java-programmer |
- Next
- 1
- importing Java-code into Rational Rose RealTimeIs there anyone who has managed to get existing java-code imported into
Rational Rose in order to get UML-diagrams?
The documentation shipped with Rational Rose is very spartan on that topic
and I've been trying for days now.
Thank you so much
- 2
- Help needed with BlueJHi All,
Need help(procedures/steps) to execute
an application program using BlueJ.
I have downloaded the
BlueJTutorial.pdf, read
what is there, I can compile my program,
can make a jar,
but where is the "run" instruction
in the main menu?
Bob
- 3
- jvm class path unicode native methodsOkay.. I'm having the following problem.. I've tried pretty much every
solution I can think of but always hit some brick wall.
I need to:
load classes from a jar in a unicode directory and register native
methods for those classes.
Before (the unicode) I was simply doing a -Djava.class.path=myjar.jar
And then registering the native methods..
But.. I can't find a way to send a unicode code string to through the
-Djava.class.path..
So I've tried:
1. sending the string as utf8.. nope.
2. setting environment variable classpath with
SetEnvironmentVariableW.. nope.
3. creating my own url class loader with the jar..
Loads fine.. BUT NATIVE METHODS DO NOT REGISTER CORRECTLY (even
though the jnienv says they do.. they don't.. apparently I can only
register native methods from classes loaded from the jnienv_ sucky..)
4. creating my own url class loader that loads the byte code directly
from the jar, then calls defineClass from the root class loader.
NOPE.. because classes reference each other.. therefore the entire
jar must be available when ever I reference one class.
5. found out the class Launcher and its methods getClassLoader,
appendblahblahfor instrumentation..
NOPE.. although.. I've sort of giving up now.. this is going too far.
Any help?
Surely there are some japanese programmers that have dealt with this
before.
-tim
- 4
- J2ME: allowing for "Allow HTTP traffic?" confirmation when doing a connection timeout mechanismI'm using threading in a J2ME app to allow a timeout on an attempt to
connect to server. However, I'm having an issue with the usual
confirmation the user gets on first connection attempt: you know, the
message that say something like "This application would like to send
HTTP traffic. Allow this?" The problem is that I have no idea of how
long the user takes to read this message before hitting "ok", so my
connection timeout could timeout before the user has even hit ok and
before any connection attempt has been made!
Is there any callback available so that I know when the user has
actually hit 'ok'?
My current workaround is to make a dummy first connection to a bad
address, e.g. "http://x", just to get the user to hit 'ok' and get that
out of the way before making my proper connection attempt.
Is there a better way though? This technique makes an attempted DNS
lookup which wastes a little time.
Thanks.
N.B.
I'm aware that in some cases the user can have a preference set so that
the HTTP traffic alert happens before *every* server communication, but
I'm ignoring this case for the moment.
- 5
- EJB Remote Calls - Serialization Restriction(s)Hi,
I have a simple HelloWorldApplication which uses SSbs.
I pass a Customer Object which has two attribute String name and
Address address;
I made Address not-serializable
so when i make calls to the SessionBean i get a remote Exception which
contains the not-serializable exception in WebPShere (as expected)
To my surprise this application ran without any problem in JRun4.0
Why would that be the case and what would the result in other APp
Servers like WebLogic be?
AFAIK, objects (parameters and Return types) must be serializable for
all Remote EJB Calls.
Note this applicaiton does not use Local Interfaces..
TIA
Manglu
- 6
- Problem with TableDear all,
I have a TextField and a TextFieldHandler implement ActionListener and
a Table.
How can I do the following function?
When the user type 111 in the TextField and press enter, item 111
information is retrieved from database and will be displayed in the
table.
When the user type 222 in the TextField and press enter, item 222
information is retrieved from database and will be displayed in the
table.
( I know how to detect the value entered in the TextField, but I donno
how to display the corresponding information with a Table)
Thanks for reply.
Victoria
- 7
- Latest models of Gibson guitarsReviews of latest models of best guitars, fender, gibson, yamaha, and
many more, with pictures and prices.
http://pro-guitars.blogspot.com/
And if you want to win a free guitar go here
http://freeguitars.blogspot.com/
- 8
- New Forum For People Who Love To Discuss On Technical TopicsA new forum for everything in one place has launched at http://www.technicaltalk.net/
This is a cool forum where any one can discuss about many technical
things like Programming, Scripting, Design, Database, Operating
Systems, Testing and even a place where any one can read and post
articles. People will also find some helpfull site links, E-books.
Get registered at http://www.technicaltalk.net/ to explore more.....
http://www.technicaltalk.net/
- 9
- Hashtable: remove elements while Enumerating"Chris Berg" wrote:
> 1) Make a new Hashtable, copy all the 'good' entries into the new
> one, then replace the old one with the new one. This MAY be bad if
> another class still holds a reference to the old table.
>
> 2) make a new Vector in which you remember all keys of entries
> that shall be removed, and then remove them AFTER having finished
> the iteraton.
3) Copy (clone()) the Hashtable. Iterate over the copy. If you find an
entry in the copy that should be removed, remove it from the original.
Make sure that no other thread works the original Hashtable while you
enumerate over the copy and manipulate the original.
- 10
- W32.Swen.A@mm goes ballistic!"Tim Tyler" <email***@***.com> wrote
> It fills the mailboxes of users with huge numbers of 140K attachments -
> making email practically unusable.
Well, no, it just takes perseverance. Being careful not to junk the
five real messages in 1995 others is a bit tedious, I'll grant from
experience.
> Non-Windows users - and the rest of the internet - are targetted
> as a result of Microsoft's security problem - as mindless zombie
> Windows boxes swarm to spread the virus.
Indeed; in 30 hours so far, I've removed roughly 3500 emails either
containing the virus or saying they were forwarded with the virus
removed. This to my Unix ISP account, where mailx() is my friend and
companion for weeding through the end results of Microsoft's sloppy
coding practices.
Too bad California's refusal to allow the M$ denial of "fitness for
merchantability" cannot be reflected world-wide; a class action lawsuit
for damages would redistribute all of M$'s wealth and capital equipment
to the Internet as a whole.
Meanwhile, 200,000,000+ flawed email clients are trying to find my email
box with their virus copies.
Sigh; it is going to be a long next few days.
xanthian.
--
Posted via Mailgate.ORG Server - http://www.Mailgate.ORG
- 11
- [Swing] JScrollPane double MouseMotionListenerhi,
I am targetting JRE 1.5.
I have an image displayed within a jscrollPane (with scrollbars).
(in this way : new JScrollPane(new JLabel(new ImageIcon(image))))
I have a MouseMotionListener added to the JScrollPane, so when the
mouse goes over the visible part of the image, I can get the relative
coordinates of the mouse
My question is how to I get at the same time, the coordinate of the
mouse relative to the jscrollpane (the coordinates within the visible
part of the image) and the absolute coordinates (the coordinates of
the mouse relative to the whole image itself).
I tried adding also MouseMotionListener to the JLabel and that gives
me the the coordinates of the mouse relative to the whole image
itself, but then the event is lost for the jscrollpane's listener.
How can I achieve that simply ?
- 12
- OT. Being Ronald L. Grossi. (Brother Ronald has a website).D-word wrote:
> Smokie Darling (Annie) wrote:
> > Zippy wrote:
> > > alt.drugs.hard, alt.support.arthritis, comp.lang.java.programmer,
> > > alt.sports.football.pro.ne-patriots, alt.security.terrorism.
> > >
> > > Can someone please tell me what all these groups have in common
> that
> > > they are in such urgent need of salvation? these kind of posts
> always
> > > have the same selection of newsgroups. I can only assume that it
is
> > the
> > > same person or group of people doing the posting. But the
newsgroup
> > > list still intrigues me.
> > >
> > > Answers please - sensible or not, humorous or not, in fact
> whatever.
> > Go
> > > on humour me.
> > >
> > > Zippy
> >
> > Nothing other than the fact that posting through Google, one can
only
> > send to 5 groups at a time, and apparently Yahoo caught on to Ron
> > Gossi, so now he's being more creative with his name? Trust me,
> he'll
> > be posting to almost every other group available on Google through
> out
> > the day. That'd be his MO
>
>
>
> Usenet isn't the only forum he spams, according to google
> (http://www.groupsrv.com/science/post-784999.html).
>
>
> Ron can (apparently) be reached for comment at: 919-553-7901
>
Correction, that number could be wrong, it is registered to "Dufresne."
*HOWEVER* This just in. Brother Ronald has a website.
Let's hear it for "Triumphant Ministries" (http://tinyurl.com/c96dw),
"Internet Evangelist" Ronald L. Grossi, and the power of the one true
god, Google. Can I get an Amen?
http://www.arkwebshost.com/advice/host/
- 13
- Possible to split a PrinterJob ??Hi all,
I am using java Printerjob with Book to create some page to print.
The problem I have is that the generation of all the page a pretty
long.
I usually gets 100 pages and each page take up to 2 seconds.
I would like to know if there is a way to start the printing process
as soon as page are ready and not wait 5 minutes to create the batch
and after that another 3-5 minutes with the printer ?
Can we append page to the book once the print is started ?
thanks,
- 14
- collaborative QA testingDoes free or cheap code to do this already exist? What is this
generic sort of product called?
I want to set up a collaborative QA checklist, so that many people can
be testing at once and reporting what they have tested. Everyone sees
the incoming results like on election night, so they can see what
still needs to be done. It also allows for crucial stuff to be tested
by more than one person, and to record their conflicting results.
It might have columns for different platforms, and some sort of HTML
script to describe the sections and tests.
The problem is getting emergency coverage testing done at the last
possible minute to deal with any "insignificant" last minute changes.
--
Canadian Mind Products, Roedy Green.
Coaching, problem solving, economical contract programming.
See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
- 15
- Repost:STILL Need help w. HTMLUtils class.
Steve R. Burrus wrote:
> Hi all, this is steve Burrus, and I will admit that it's been a while
> since I last checked in with this group! I was wondering whatever
> happened to the "always-perennial" roedy Green, and after scrolling
> down the list of postings in this group, I found his last post was on
> 8.1.2004 and it's now 8/09/04.
> Well anyway, I needed some help with "getting it right" with the
> HTMLUtils class which is used in quite a few of the various examples
> in a particular servlet book of mine. I always seem to get a compiler
> error whenever I try to compile a servlet with this class in it! Can
> anyone help me please with this problem as I am in anguish over it, I
> must admit. Incidentally, I put the folder with this class in it into
> my classpath env. variable, but that didn't seem to help any.
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title></title>
</head>
<body>
<br>
<br>
Steve R. Burrus wrote:<br>
<blockquote type="cite" cite="email***@***.com">
<meta http-equiv="Content-Type" content="text/html;">
<title></title>
<big><b><font face="Times New Roman, Times, serif">Hi all, this is steve
Burrus, and I will admit that it's been a while since I last checked in with
this group! I was wondering whatever happened to the "always-perennial" roedy
Green, and after scrolling down the list of postings in this group, I found
his last post was on 8.1.2004 and it's now 8/09/04.<br>
Well anyway, I needed some help with "getting it right" with the HTMLUtils
class which is used in quite a few of the various examples in a particular
servlet book of mine. I always seem to get a compiler error whenever I try
to compile a servlet with this class in it! Can anyone help me please with
this problem as I am in anguish over it, I must admit. Incidentally, I put
the folder with this class in it into my classpath env. variable, but that
didn't seem to help any. <br>
</font></b></big> </blockquote>
<br>
</body>
</html>
|
|
|