B4J Question Solved: Resultset should first be initialized

clinst

Member
Licensed User
Longtime User
Hi

I'm getting the following error when trying to get some data from a SQLite DB:
Error occurred on line: 191 (DBUtils) - (Error points to the line with Dim rs as Resultset if I use that version)
java.lang.RuntimeException: Object should first be initialized
----------
I've tried it using the DBUtils functions and by calling the ExecQuery function of the SQL object directly:

lst = DBUtils.ExecuteList(Main.SQL1,"SELECT catname FROM Categories",Null,0)
&
DBUtils.ExecuteList2(Main.SQL1,"SELECT catname FROM Categories",Null,0,lst)
&
dim rs as ResultSet = Main.SQL1.ExecQuery("SELECT catname FROM Categories")
----------
The problem seems to be that it is expecting the Resultset to be initialized but it doesn't have a Initialized method.

The code to create the tables works fine as does the code to IINSERT INTO the Categories table (verified with SQLite Admin)
I'm using #AdditionalJar: sqlite-jdbc-3.7.2.

I've read through the the B4XSQLiteDatabase Guide and searched the forum but I can't see anything that talks about this error.
 
Last edited:
Solution
The problem is that you added code in the Main module, you should not.
You should move the code from the Main module in AppStart to the B4XPage_Created routine in the B4XMainPage module.
And also move Public SQL1 As SQL to the B4XMainPage module.
And remove Main from DBUtils.ExecuteList2(SQL1,"SELECT catname FROM Categories",Null,0,lst).

In the Main module in AppStart module leave only the four first lines.

Daestrum

Expert
Licensed User
Longtime User
try
B4X:
Dim rs As ResultSet
rs = Main.SQL1.ExecQuery("SELECT catname FROM Categories")
 
Upvote 0

clinst

Member
Licensed User
Longtime User
I've attached the project.

I'm modifying the B4X-Lists project/tutorial from PaulMeuris's site (cursustekst.be/index.php) to use a DB instead of writing everything to text files. I did get the project working using his tutorial.

I did have to leave out a number of folders to get it small enough to post, hopefully it's got everything needed. (And please excuse my amateur code :) )
 

Attachments

  • B4J.zip
    5.9 KB · Views: 142
Upvote 0

Chris2

Active Member
Licensed User
Longtime User
The example you attached appears to be missing the modules that contain the relevant code:
B4X:
[IDE message - 3:19:19]
The following modules are missing:
C:\###\B4XMainPage.bas
C:\###\CategoryPage.bas
C:\###\SubcategoryPage.bas

Error occurred on line: 191 (DBUtils) - (Error points to the line with Dim rs as Resultset if I use that version)
Are you sure that's where the error is?
To me the error message suggests that the error is on line 191 of the DBUtils module in the library, not 191 of your code.

Are you initialising lst (I'm assuming it's a list)?
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
Your project is supposed to a B4XPages project.
Many things are missing.
To export a B4XPages project you should zip it with this line in the B4XMainPage.
'Ctrl + click to export as zip: ide://run?File=%B4X%\Zipper.jar&Args=\%PROJECT_NAME%.zip
 
Upvote 0

clinst

Member
Licensed User
Longtime User
Sorry, I was trying to get the zip small enough to attach. Even the in IDE option still produces a zip that's too large.

I'll try and create an example version that will hopefully be smaller.
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
The problem is that you added code in the Main module, you should not.
You should move the code from the Main module in AppStart to the B4XPage_Created routine in the B4XMainPage module.
And also move Public SQL1 As SQL to the B4XMainPage module.
And remove Main from DBUtils.ExecuteList2(SQL1,"SELECT catname FROM Categories",Null,0,lst).

In the Main module in AppStart module leave only the four first lines.
 

Attachments

  • Project1.zip
    22.8 KB · Views: 146
Upvote 0
Solution

clinst

Member
Licensed User
Longtime User
Excuse the pun but.....Result :)
Compiles without any complaint about the Resultset now. Thank you.

If it's ok I have one final question:
Variable 'SelectedItem1' is marked as unused but it is assigned an item from cbx1 in line 89. This warning doesn't affect anything, app runs fine, but I'm curious as to why the IDE/Compiler thinks it is unused.
 
Upvote 0
Top