Android Question [SOLVED] Jrdc Error, object should be initialized first.

incendio

Well-Known Member
Licensed User
Longtime User
Hi guys,

I am confused, long time no use B4A.

I have a config file, something like this
B4X:
sql.test1 = select * from stored_proc1(?)

sql.test2 = select * from stored_proc2(?)

sql.test1 ran OK, sql.test2 raised an error.

But if I change sql.test2 into like this
B4X:
sql.test2 = select * from stored_proc1(?)

It was ran OK too.

So the problem is in stored_proc2, but I ran it from database manager, it ran OK.

Where is the problem here?
 

DonManfred

Expert
Licensed User
Longtime User
Where is the problem here?
You are the problem.

You found out that stored_proc2 raise an error, stored_proc1 not.

HIDING the code of these procedures is a GOOD WAY not to get help.

Remember noone of us know your databasestructure, nobody knows your stored procs.

We can not guess what the problem is.
 
Upvote 0

incendio

Well-Known Member
Licensed User
Longtime User
You are the problem.

You found out that stored_proc2 raise an error, stored_proc1 not.

HIDING the code of these procedures is a GOOD WAY not to get help.

Remember noone of us know your databasestructure, nobody knows your stored procs.

We can not guess what the problem is.
You don't read carefully!

I ran that procedure through database manager, and it was OK.

I am on a mobile phone right now, will check again later.
 
Upvote 0

incendio

Well-Known Member
Licensed User
Longtime User
Always remember to post your error message for others to help you.

My first suggestion is to change the SQL to following:
Sorry, I was on mobile phone before.

Here are the complete error message :
ResponseError. Reason: java.lang.RuntimeException: Object should first be initialized (JavaObject)., Response: <html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
<title>Error 500 java.lang.RuntimeException: Object should first be initialized (JavaObject).</title>
</head>
<body><h2>HTTP ERROR 500</h2>
<p>Problem accessing /rdc. Reason:
<pre> java.lang.RuntimeException: Object should first be initialized (JavaObject).</pre></p><hr><a href="http://eclipse.org/jetty">Powered by Jetty:// 9.4.z-SNAPSHOT</a><hr/>
</body>
</html>

I ran jar file via the command line, the output showed :
Command: , took 15ms, client .....

But if I changed the config file into
B4X:
sql.test2 = select * from stored_proc1(?)

the output showed :
Command: query : test2, took 15ms, client .....
 
Upvote 0

incendio

Well-Known Member
Licensed User
Longtime User
If you have tried to search for the error message, you may get the answer.
https://www.b4x.com/android/forum/p...object-should-first-be-initialized-javaobject

The possible cause is there is a null value in your results.
You were right, there is a null value in date field type.

I never though that this is the cause, because I think (not sure) never have a problem before with null value because it was not a date type.

More over, my stored procedure work fine in database manager, it can handle null value for type date, but apparently Java handle it differently.

Thanks again.
 
Upvote 0

aeric

Expert
Licensed User
Longtime User
I think Erel fixed that error after OliverA asked him
B4X:
Dim SQLTime As JavaObject = jrs.RunMethodJO(DateTimeMethods.Get(ct), Array(i + 1))
If SQLTime.IsInitialized Then
    row(i) = SQLTime.RunMethod("getTime", Null)
Else
    row(i) = Null
End If

One way is replace the Null with a default value. e.g:
B4X:
row(i) = "-"

But sometimes we still want to know that we have Null value in the resultset.

The best way is developer needs to handles the Null values from the SQL query by using IfNull() or similar syntax.
 
Upvote 0

OliverA

Expert
Licensed User
Longtime User
row(i) = Null
That's not what is causing the problem. The error is thrown by the jRDC server, not the client accessing the jRDC server. The problem (if you are using a version of jRDC2 that does not have the datetime fix as linked above) is that a Null object is returned to jRDC and then jRDC tries to call a method against that Null object, causing the error that you see. The datetime fix fixes this issue by making sure that the object returned is not Null before calling a method against it.

@aeric's point about handling Null values via the SQL query is a very valid point and has been suggested several times on this forum in order to prevent unexpected behavior on both the server side (when using jRDC) and the client side.
 
Upvote 0
Top