Android Question I test 6 models of mobile phone, only one brand (one model) pass the test.

AndyChang

Member
Licensed User
I test 6 models of mobile phone, only one brand (one model) pass the test.

1). I download apk to 3 Brands of mobil phone. ASUS Zenfone / HTC / HUAWEI each Brands has two models Total: 6 phones.
2). Only one of the ASUS Zenfone can operate well. The other 5 phones are stopped and back to main activity when they run the code Listview1_itemClick (As Below). It means that once any one item line is being touched, the routine will stop and screen will back to activity main and the program still can be operated. Until we touch the item data line.
3). Is there any points or statements that I should carefully to use. How to finds out the way to let most of the phones can execute my APP.
4). Because the Zip file size is about 620KB, it is over 500KB limite. So I cannot upload the program.
5). I would like to provide any information or code. Please don’t be hesitate to ask me.

Sub ListView1_ItemClick (Position As Int, Value As Object)
Dim Sqlname, TableText As String
Dim Cursor1 As Cursor
Dim recordID As Int
Sqlname="myDesign4.sqlite3"
TableText = Tablename(Position)
TableNameNOW = TableText
OpenSQLitefile(Sqlname)
Cursor1 = SQL1.ExecQuery("SELECT itemno FROM " & TableText )

For recordID = 0 To 9
Cursor1.Position = recordID
Itemno(recordID) = Cursor1.GetString("itemno")
Next

Listview2.Clear
For i=0 To 9
Listview2.AddSingleLine(Itemno(i))
Next

Label1.Text = Itemno(0)
Label2.Text = Itemno(1)
Label3.Text = Itemno(2)
Label4.Text = Itemno(3)
Label5.Text = Itemno(4)
Label6.Text = Itemno(5)
Label7.Text = Itemno(6)
Label8.Text = Itemno(7)
Label9.Text = Itemno(8)
Label10.Text = Itemno(9)

ReadChosenTableBLOB

lblcommand.Text="請繼續點選檔案或點選命令欄"

End Sub
 

AndyChang

Member
Licensed User
Hi Erel
Thanks for caring about my problem.
When I run the program on Emulater, it works well. So no logs will appear error message.
When I install apk to my Asus phone, it works also nice.
But when I install apk to other phones which I can get arround me, they all fail at the same point.
I don't know how to get error message when it run in a real phone.

[ Please use
B4X:
code here...
tags when posting code. ]
I don't quite understand how to insert the
B4X:
  .....
to my code
Andy
 
Upvote 0

AndyChang

Member
Licensed User
B4X:
Sub ListView1_ItemClick (Position As Int, Value As Object)
    Dim Sqlname, TableText As String
    Dim Cursor1 As Cursor
    Dim recordID As Int
    Sqlname="myDesign4.sqlite3"
    TableText = Tablename(Position)
    TableNameNOW = TableText
    OpenSQLitefile(Sqlname)
    Cursor1 = SQL1.ExecQuery("SELECT itemno FROM " & TableText )
    For recordID = 0 To 9
        Cursor1.Position = recordID
        Itemno(recordID) = Cursor1.GetString("itemno")
        Log("Itemno= "&Itemno(recordID))
    Next
    Listview2.Clear
    For i=0 To 9
        Listview2.AddSingleLine(Itemno(i))
    Next
    Label1.Text = Itemno(0)
    Label2.Text = Itemno(1)
    Label3.Text = Itemno(2)
    Label4.Text = Itemno(3)
    Label5.Text = Itemno(4)
    Label6.Text = Itemno(5)
    Label7.Text = Itemno(6)
    Label8.Text = Itemno(7)
    Label9.Text = Itemno(8)
    Label10.Text = Itemno(9)
    ReadChosenTableBLOB
    lblcommand.Text="請繼續點選檔案 或 點選命令欄"
End Sub
 
Upvote 0

hongbii khaw

Member
Licensed User
Longtime User
Hi Andy,
You can add Try Catch Block to your code to trace the error.


B4X:
Sub ListView1_ItemClick (Position As Int, Value As Object)
    Dim Sqlname, TableText As String
    Dim Cursor1 As Cursor
    Dim recordID As Int
    Sqlname="myDesign4.sqlite3"
    TableText = Tablename(Position)
    TableNameNOW = TableText
    OpenSQLitefile(Sqlname)
    Cursor1 = SQL1.ExecQuery("SELECT itemno FROM " & TableText )
    For recordID = 0 To 9
        Cursor1.Position = recordID
        Itemno(recordID) = Cursor1.GetString("itemno")
        Log("Itemno= "&Itemno(recordID))
    Next
    Listview2.Clear
    For i=0 To 9
        Listview2.AddSingleLine(Itemno(i))
    Next
    Label1.Text = Itemno(0)
    Label2.Text = Itemno(1)
    Label3.Text = Itemno(2)
    Label4.Text = Itemno(3)
    Label5.Text = Itemno(4)
    Label6.Text = Itemno(5)
    Label7.Text = Itemno(6)
    Label8.Text = Itemno(7)
    Label9.Text = Itemno(8)
    Label10.Text = Itemno(9)
    ReadChosenTableBLOB
    lblcommand.Text="請繼續點選檔案 或 點選命令欄"
End Sub
 
Upvote 0

AndyChang

Member
Licensed User
It's shame on me that until now I never successfully connect IDE to ASUS and HTC phone. I use Emulator only.
I will follow the B4ABeginners Guide and do it step by step. Hope this time I can connect successfully.
 
Upvote 0

AndyChang

Member
Licensed User
B4X:
  You can add Try Catch Block to your code to trace the error.

Hi honebii
I am very new programmer. I even don't know what is (Try Catch Block), but I will search the User Guide to try to understand. Thank you for your kindness suggestion. thank you.
Andy
 
Upvote 0

AndyChang

Member
Licensed User
B4X:
Sub ReadImageFromSQL
    Dim Sqlname As String="Nail.sqlite3"
    Dim Tablename As String="BasicData"
    Dim Cursor1 As Cursor
    Dim recordID As Int
    item(0)="FMAS-2101"
    OpenSQLitefile(Sqlname)
    Log("***  after OpenSQLitefile(Sqlname)  ")
    Cursor1 = SQL1.ExecQuery("SELECT image FROM " & Tablename &" WHERE itemno = "& item(0) )     <----   This statement cause error
    Log("***  after SELECT From ")
    recordID = 0
    Cursor1.Position = recordID
    Dim Buffer() As Byte                                                    'declare an empty byte array
    Buffer = Cursor1.GetBlob("image")                                        'get the byte data from cursor
    Dim InputStream1 As InputStream                                            '
    InputStream1.InitializeFromBytesArray(Buffer, 0, Buffer.Length)            'InputStream convert byte to a datastream
    Dim Bitmap1 As Bitmap
    Bitmap1.Initialize2(InputStream1)                                        'then convert Inputstream to image Bitmap file
    itemImage(recordID)=Bitmap1
    Label1.Text = item(0)
    Label2.SetBackgroundImage(itemImage(0))
End Sub

Hi, Erel
This time I have successfully connected (last time I use a Chinese version User Menu, It's not clear enough).
I can get the error message now.
It is an old problem for me. about two days ago, I have post the question on the forum. But later, I change the column name from itemno to onMarket and the error disappear. It is quite strange. But I supposed that I have solved problem. Now they appear again. The attach file is the results of my test running. Please give me a direction to solve this strange problem. I have to climb over this obstacle. Thank you everybody.
Andy
 

Attachments

  • test.zip
    371.9 KB · Views: 161
  • database.png
    database.png
    60.6 KB · Views: 163
  • Error Msg.png
    Error Msg.png
    124.2 KB · Views: 184
Upvote 0

klaus

Expert
Licensed User
Longtime User
Two main problems:
1) You must move OpenSQLitefile(Sqlname) from the ReadImageFromSQL routine to the Activiy_Create routine like this:
B4X:
Sub Activity_Create(FirstTime As Boolean)
    If FirstTime Then
        OpenSQLitefile(Sqlname)   
    End If
    Activity.LoadLayout("Main")
   
    ReadImageFromSQL
End Sub
The SQL object must be declared only once.
You could also move it to the Starter Service.
You should also move the variable declarations to Proces_Globals.

2) The query is wrong. The column is of TEXT type. So the variable must be between single quotes!
Cursor1 = SQL1.ExecQuery("SELECT image FROM " & Tablename &" WHERE itemno = '" & item(0) & "'")
Or, better, use:
Cursor1 = SQL1.ExecQuery2("SELECT image FROM " & Tablename &" WHERE itemno = ?", Array As String(item(0)))

You MUST read chapter 5 SQLite Database in the B4A User's Guide!

Attached a modifyed version.
 

Attachments

  • test1.zip
    371.9 KB · Views: 174
Upvote 0

AndyChang

Member
Licensed User
Dear Klaus
I follow your suggestions and rewrite the test program. Everything goes wonderful. I made many mistake. Thank you for your kindness and patient to teach me. Now I have to go back to correct my project's code. Thank you.
Andy
 
Upvote 0
Top