Unable to use WebView

TyneBridges

Member
Licensed User
Longtime User
I'm attempting to follow the DBUtils example in the User's Guide ("Show the table in a WebView"). I may have misunderstood the way the WebView is created, because there seems to be no reference to creating this as a layout, so I assumed it was predefined. If not (and if I have to create it myself), have I missed the link that shows how it should look...?

I have DBUtils in my modules list and SQL (Version: 1.02) ticked in Referenced Libraries.

Compiling code. Error
Error compiling program.
Error description: Cannot access activity object from sub Process_Globals.
Occurred on line: 5
Dim WebView1 As WebView
Word: webview

Thanks for any help.
 

klaus

Expert
Licensed User
Longtime User
You have declared:
Dim WebView1 As WebView
in the Process_Globals routine.
You must move it to the Globals routine, as in the guide.

When you downloaded the User's Guide you also got a folder called SourceCode where you find the source code of all examples in the guide.
The example program is SQLDBUtils.
In the example program a layout file is loaded.
You could also add WebView1 by code:
B4X:
WebView1.Initialize("WebView1")
Activity.AddView(WebView1,0, 0, 100%x, 100%y)
In the Activity_Create routine.

Best regards.
 
Upvote 0

TyneBridges

Member
Licensed User
Longtime User
Thanks. Moving the reference allowed the program to compile. I'm still getting run-time errors even after adding your lines of code. I guess this is because I didn't follow the example closely enough, so I need to work through those.
 
Upvote 0

TyneBridges

Member
Licensed User
Longtime User
Unfortunately I've come to a complete halt again. On the line "cur = SQL.ExecQuery(Query)" in ExecuteHTML I get the persistent error "Object should first be initialized". I can see that cur is declared just before this and I can display the query, ("Select ID, Task, Notes, Category, DateAdded, Priority, ExpiryDate from Tasks"). I know this is valid for my database and table because it's just been working in an initial trial program that I created. My ShowTableInWebView is as follows:

Sub ShowTableInWebView
Dim Query As String
Query = "Select ID, Task, Notes, Category, DateAdded, Priority, ExpiryDate from " & DBTableName
Msgbox (Query, "To Do List")
WebView1.LoadHtml(DBUtils.ExecuteHtml(SQL1, Query, Null, 0, False))
End Sub

I get the same error whether I set the final parameter of ExecuteHTML to True or False. "Dim SQL1 As SQL" is in my Process_Globals. Above the error in the debugger, Table (List) shows "Not initialized" and so does cur (Cursor). I haven't edited DBUtils at all.

Any thoughts? :confused:
 
Upvote 0

TyneBridges

Member
Licensed User
Longtime User
Project attached as requested. Thanks for your help.
 

Attachments

  • JHProject.zip
    10.7 KB · Views: 175
Upvote 0

TyneBridges

Member
Licensed User
Longtime User
Thanks again! I should have spotted that that was missing.
 
Upvote 0
Top