Error (Android.NetworkOnMain LastExcepti) with access MYSQL to Android 3.x and higher

rclatorre

Member
Licensed User
Longtime User
Hello,

I'm developing an application that is used to display magazines.

I have two activities that both access to MySQL (as explained in the tutorial), the first shows the list of publications and the second shows the selected articles in the publication in the first activity.

Apparently, the problem I have is the Android version, everything works fine on Android 2.3.5 (Apps_2.6.32.9) on a Motorola XT531 (also on other computers with Android 2.x versions), but when running on a Thinkpad Tablet with Android 4 and also on Android emulators with 3 or higher fails to execute the query for the second activity

Message data that goes:

Message: Program paused on line 108 (see code below)
res = Response.GetString ("UTF8")

In the debug window, Locals zone comes in red:
Android.NetworkOnMain LastException ThreadException

These are an extract of the activities

ACTIVITY 1: Displays the publications

B4X:
Sub Process_Globals

'HttpClient
Dim hc As HttpClient

'Query type indicator
As Int Dim PUBLICATIONS_LIST
PUBLICATIONS_LIST = 1

....

Sub FetchPublicationsList
ExecuteRemoteQuery ("SELECT name, publication_id, image_url, publication_date, introduction ORDER BY FROM publication_id publication" PUBLICATIONS_LIST)
End Sub

Sub ExecuteRemoteQuery (Query As String, TaskId As Int)
Dim req As HttpRequest
req.InitializePost2 ("http://www.domainxx.pe/testing/cns.php" Query.GetBytes ("UTF8"))
hc.Execute (req, TaskId)
End Sub

Sub hc_ResponseSuccess (Response As HttpResponse, TaskId As Int)
Dim res As String
'Here the error occurred when the connection is poor
res = Response.GetString ("UTF8") << ---- This line runs correctly 
.....


ACTIVITY 2: It is called from activity 1 shows the selected articles in the publication

B4X:
Sub Process_Globals
'HttpClient
As hc1 Dim HttpClient

As Int Dim ARTICLE_LIST
ARTICLE_LIST = 1

As Float Dim Factor_Tamano_Letra

....

Sub FetchArticleList
ExecuteRemoteQuery ("Select article_id, title, introduction, image_top_url, image_bottom_url, author, description from article where publication_id =" &publication_id & "AND active = 'Y' order by article_id" ARTICLE_LIST)
End Sub

Sub ExecuteRemoteQuery (Query As String, TaskId As Int)
Dim req As HttpRequest
req.InitializePost2 ("http://www.domainxx.pe/testing/cns.php" Query.GetBytes ("UTF8"))
hc1.Execute (req, TaskId)
End Sub

Sub hc_ResponseSuccess (Response As HttpResponse, TaskId As Int)
Dim res As String
res = Response.GetString ("UTF8") << ------ Line 108, here stops and throws the error described above.
....

Please, help me.

Roberto
 

rclatorre

Member
Licensed User
Longtime User
Thanks Erel, I remove the value android: targetSdkVersion = "14" and it works well.

I have only one question, I copy the files and HttpUtils2Service HttpJob. In libraries I have selected HTTP (Version 1.21), with this setup I'm using HttpUtils2?

Thanks

Roberto
 
Upvote 0
Top