I am reading all the Images in the Phone Gallery.
I then "filter" these images so that I only write the File Name and Image of files that are less than 8 days old to the SQLite table "gallery".
I write both the File Name and the image (BLOB) to the table "gallery".
I then populate the ListView "lvTip" from the SQLite table "gallery".
I receive the following error on line:
Error:
As can be seen from the Log, I do have data in the table "gallery".
Log:
My Code:
I can't seem to find what I am doing wrong.
I then "filter" these images so that I only write the File Name and Image of files that are less than 8 days old to the SQLite table "gallery".
I write both the File Name and the image (BLOB) to the table "gallery".
I then populate the ListView "lvTip" from the SQLite table "gallery".
I receive the following error on line:
B4X:
PicName = Curs.GetString("picName")
B4X:
android.database.CursorIndexOutOfBoundsException: Index 0 requested, with a size of 0
Log:
B4X:
Copying updated assets files (8)
** Service (starter) Create **
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
true
** Activity (main) Resume **
** Service (httputils2service) Create **
** Service (httputils2service) Start **
Error: java.net.ConnectException: failed to connect to /197.189.232.202 (port 18100) after 30000ms: isConnected failed: ECONNREFUSED (Connection refused)
** Activity (main) Pause, UserClosed = false **
** Activity (tip) Create, isFirst = true **
** Activity (tip) Resume **
DropTable: DROP TABLE IF EXISTS [gallery]
CreateTable: CREATE TABLE IF NOT EXISTS [gallery] ([picName] TEXT, [galleryPic] BLOB)
Gallery Table Created
File List = (ArrayList) [IMG_20161018_065705.jpg, IMG_20161102_084539.jpg, IMG_20161102_084553.jpg, IMG_20161102_084603.jpg, IMG_20161102_084623.jpg, IMG_20161102_084627.jpg, IMG_20161102_084630.jpg, SAVE_20161111_112027.png, IMG_20161116_081510.jpg, IMG_20161116_081513.jpg, IMG_20161116_081516.jpg, IMG_20161121_101052.jpg, IMG_20161121_101056.jpg, IMG_20161121_101104.jpg, IMG_20161121_101109.jpg, IMG_20161121_101115.jpg, IMG_20161121_101124.jpg, IMG_20161225_074426.jpg, IMG_20161225_074503.jpg, IMG_20161225_074518.jpg, IMG_20161101_183650.jpg, IMG_20161225_074631.jpg, IMG_20161225_074804.jpg, IMG_20161225_074913.jpg, IMG_20161225_074934.jpg, IMG_20161225_075153.jpg, IMG_20161225_075208.jpg, IMG_20161225_075417.jpg, IMG_20161225_075449.jpg, IMG_20170109_220002.jpg, IMG_20170109_220006.jpg, IMG_20170109_220011.jpg, IMG_20170109_220020.jpg, IMG_20170110_054009.jpg, IMG_20170110_054012.jpg, IMG_20170110_054012_1.jpg, IMG_20170110_054012_1_BURST2.jpg, IMG_20170110_054039.jpg, IMG_20161225_074103.jpg, IMG_20161225_074118.jpg, IMG_20161225_074120.jpg, IMG_20161225_074218.jpg, IMG_20161225_074222.jpg, IMG_20170110_120837.jpg, IMG_20170110_122431.jpg, IMG_20170113_091031.jpg, IMG_20170113_091038.jpg, IMG_20170113_091052.jpg, IMG_20170120_085349.jpg, IMG_20170120_085355.jpg, IMG_20170120_103407.jpg, IMG_20170120_103414.jpg, IMG_20170120_103426.jpg, IMG_20170120_103429.jpg, IMG_20170120_103433.jpg, IMG_20170120_103436.jpg, IMG_20170120_103442.jpg, IMG_20170120_103443.jpg, IMG_20170120_103502.jpg, IMG_20170121_105105.jpg, IMG_20170121_105117.jpg, IMG_20170121_111402.jpg, IMG_20170121_111406.jpg, IMG_20170121_111421.jpg, IMG_20170121_111423.jpg, IMG_20170121_111433.jpg, IMG_20170121_111438.jpg, IMG_20170121_111538.jpg, IMG_20170121_111551.jpg, IMG_20170121_111602.jpg, IMG_20170121_111613.jpg, IMG_20170121_111628.jpg, IMG_20170121_111632.jpg, IMG_20170121_111642.jpg, IMG_20170121_111713.jpg, IMG_20170121_111733.jpg, IMG_20170121_111740.jpg, IMG_20170121_111741.jpg, IMG_20170121_111748.jpg, IMG_20170121_111754.jpg, IMG_20170121_112057.jpg, IMG_20170122_133807.jpg, IMG_20170122_133818.jpg, IMG_20170122_133907.jpg, IMG_20170122_133913.jpg, IMG_20170122_133913_1.jpg, IMG_20170122_133926.jpg, IMG_20170122_133931.jpg, IMG_20170217_172841.jpg, IMG_20170217_172844.jpg, IMG_20170217_172845.jpg, IMG_20170217_173010.jpg, IMG_20170224_080939.jpg, IMG_20170224_080946.jpg, IMG_20170309_121014.jpg, IMG_20170309_121025.jpg, IMG_20170309_121028.jpg, IMG_20170314_080944.jpg]
File Count = 98
Picture Name: IMG_20161018_065705.jpg
Number of Days: 148
Picture Name: IMG_20161102_084539.jpg
Number of Days: 133
Picture Name: IMG_20161102_084553.jpg
Number of Days: 133
Picture Name: IMG_20161102_084603.jpg
Number of Days: 133
Picture Name: IMG_20161102_084623.jpg
Number of Days: 133
Picture Name: IMG_20161102_084627.jpg
Number of Days: 133
Picture Name: IMG_20161102_084630.jpg
Number of Days: 133
Picture Name: SAVE_20161111_112027.png
Picture Name: IMG_20161116_081510.jpg
Number of Days: 119
Picture Name: IMG_20161116_081513.jpg
Number of Days: 119
Picture Name: IMG_20161116_081516.jpg
Number of Days: 119
Picture Name: IMG_20161121_101052.jpg
Number of Days: 114
Picture Name: IMG_20161121_101056.jpg
Number of Days: 114
Number of Days: 64
Picture Name: IMG_20170110_054012_1.jpg
Number of Days: 64
Picture Name: IMG_20170110_054012_1_BURST2.jpg
Number of Days: 64
Picture Name: IMG_20170110_054039.jpg
Number of Days: 64
Picture Name: IMG_20161225_074103.jpg
Number of Days: 80
Picture Name: IMG_20161225_074118.jpg
Number of Days: 80
Picture Name: IMG_20161225_074120.jpg
Number of Days: 80
Picture Name: IMG_20161225_074218.jpg
Number of Days: 80
Picture Name: IMG_20161225_074222.jpg
Number of Days: 80
Picture Name: IMG_20170110_120837.jpg
Number of Days: 64
Picture Name: IMG_20170110_122431.jpg
Number of Days: 64
Picture Name: IMG_20170113_091031.jpg
Number of Days: 64
Picture Name: IMG_20170110_054012_1.jpg
Number of Days: 64
Picture Name: IMG_20170110_054012_1_BURST2.jpg
Number of Days: 64
Picture Name: IMG_20170110_054039.jpg
Number of Days: 64
Picture Name: IMG_20161225_074103.jpg
Number of Days: 80
Picture Name: IMG_20161225_074118.jpg
Number of Days: 80
Picture Name: IMG_20161225_074120.jpg
Number of Days: 80
Picture Name: IMG_20161225_074218.jpg
Number of Days: 80
Picture Name: IMG_20161225_074222.jpg
Number of Days: 80
Picture Name: IMG_20170110_120837.jpg
Number of Days: 64
Picture Name: IMG_20170110_122431.jpg
Number of Days: 64
Picture Name: IMG_20170113_091031.jpg
Number of Days: 64
Picture Name: IMG_20170110_054012_1.jpg
Number of Days: 64
Picture Name: IMG_20170110_054012_1_BURST2.jpg
Number of Days: 64
Picture Name: IMG_20170110_054039.jpg
Number of Days: 64
Picture Name: IMG_20161225_074103.jpg
Number of Days: 80
Picture Name: IMG_20161225_074118.jpg
Number of Days: 80
Picture Name: IMG_20161225_074120.jpg
Number of Days: 80
Picture Name: IMG_20161225_074218.jpg
Number of Days: 80
Picture Name: IMG_20161225_074222.jpg
Number of Days: 80
Picture Name: IMG_20170110_120837.jpg
Number of Days: 64
Picture Name: IMG_20170110_122431.jpg
Number of Days: 64
Picture Name: IMG_20170113_091031.jpg
Picture Name: IMG_20170121_111551.jpg
Number of Days: 53
Picture Name: IMG_20170121_111602.jpg
Number of Days: 53
Picture Name: IMG_20170121_111613.jpg
Number of Days: 53
Picture Name: IMG_20170121_111628.jpg
Number of Days: 53
Picture Name: IMG_20170121_111632.jpg
Number of Days: 53
Picture Name: IMG_20170121_111642.jpg
Number of Days: 53
Picture Name: IMG_20170121_111713.jpg
Number of Days: 53
Picture Name: IMG_20170121_111733.jpg
Number of Days: 53
Picture Name: IMG_20170121_111740.jpg
Number of Days: 53
Picture Name: IMG_20170121_111741.jpg
Number of Days: 53
Picture Name: IMG_20170121_111748.jpg
Number of Days: 53
Picture Name: IMG_20170121_111754.jpg
Number of Days: 53
Picture Name: IMG_20170121_112057.jpg
Number of Days: 53
Picture Name: IMG_20170122_133807.jpg
Number of Days: 52
Picture Name: IMG_20170122_133818.jpg
Number of Days: 52
Picture Name: IMG_20170122_133907.jpg
Number of Days: 52
Picture Name: IMG_20170122_133913.jpg
Number of Days: 52
Picture Name: IMG_20170122_133913_1.jpg
Number of Days: 52
Picture Name: IMG_20170122_133926.jpg
Number of Days: 52
Picture Name: IMG_20170122_133931.jpg
Number of Days: 52
Picture Name: IMG_20170217_172841.jpg
Number of Days: 26
Picture Name: IMG_20170217_172844.jpg
Number of Days: 53
Picture Name: IMG_20170121_111754.jpg
Number of Days: 53
Picture Name: IMG_20170121_112057.jpg
Number of Days: 53
Picture Name: IMG_20170122_133807.jpg
Number of Days: 52
Picture Name: IMG_20170122_133818.jpg
Number of Days: 52
Picture Name: IMG_20170122_133907.jpg
Number of Days: 52
Picture Name: IMG_20170122_133913.jpg
Number of Days: 52
Picture Name: IMG_20170122_133913_1.jpg
Number of Days: 52
Picture Name: IMG_20170122_133926.jpg
Number of Days: 52
Picture Name: IMG_20170122_133931.jpg
Number of Days: 52
Picture Name: IMG_20170217_172841.jpg
Number of Days: 26
Picture Name: IMG_20170217_172844.jpg
Number of Days: 53
Picture Name: IMG_20170121_111754.jpg
Number of Days: 53
Picture Name: IMG_20170121_112057.jpg
Number of Days: 53
Picture Name: IMG_20170122_133807.jpg
Number of Days: 52
Picture Name: IMG_20170122_133818.jpg
Number of Days: 52
Picture Name: IMG_20170122_133907.jpg
Number of Days: 52
Picture Name: IMG_20170122_133913.jpg
Number of Days: 52
Picture Name: IMG_20170122_133913_1.jpg
Number of Days: 52
Picture Name: IMG_20170122_133926.jpg
Number of Days: 52
Picture Name: IMG_20170122_133931.jpg
Number of Days: 52
Picture Name: IMG_20170217_172841.jpg
Number of Days: 26
Picture Name: IMG_20170217_172844.jpg
Number of Days: 26
Picture Name: IMG_20170217_172845.jpg
Number of Days: 26
Picture Name: IMG_20170217_173010.jpg
Number of Days: 26
Picture Name: IMG_20170224_080939.jpg
Number of Days: 19
Picture Name: IMG_20170224_080946.jpg
Number of Days: 19
Picture Name: IMG_20170309_121014.jpg
Number of Days: 6
InsertMaps (first query out of 1): INSERT INTO [gallery] ([picName], [galleryPic]) VALUES (?, ?)
List: (ArrayList) [{picName=IMG_20170309_121014.jpg, galleryPic=[B@1446a0c}]
Picture Name: IMG_20170309_121025.jpg
Number of Days: 6
InsertMaps (first query out of 1): INSERT INTO [gallery] ([picName], [galleryPic]) VALUES (?, ?)
List: (ArrayList) [{picName=IMG_20170309_121025.jpg, galleryPic=[B@3b8ff55}]
Picture Name: IMG_20170309_121028.jpg
Number of Days: 6
InsertMaps (first query out of 1): INSERT INTO [gallery] ([picName], [galleryPic]) VALUES (?, ?)
List: (ArrayList) [{picName=IMG_20170314_080944.jpg, galleryPic=[B@21ff25b}]
Gallery Rows Count: 4
List: (ArrayList) [{picName=IMG_20170314_080944.jpg, galleryPic=[B@21ff25b}]
Gallery Rows Count: 4
Error occurred on line: 141 (Tip)
android.database.CursorIndexOutOfBoundsException: Index 0 requested, with a size of 0
at android.database.AbstractCursor.checkPosition(AbstractCursor.java:466)
at android.database.AbstractWindowedCursor.checkPosition(AbstractWindowedCursor.java:136)
at android.database.AbstractWindowedCursor.getString(AbstractWindowedCursor.java:50)
at anywheresoftware.b4a.sql.SQL$CursorWrapper.GetString(SQL.java:355)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:708)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:337)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:247)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:134)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:157)
at anywheresoftware.b4a.debug.Debug.delegate(Debug.java:259)
at com.rob.crimechat.tip._loadpictures(tip.java:483)
at com.rob.crimechat.tip._btntipaddphoto_click(tip.java:475)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:708)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:340)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:247)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:134)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:157)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:153)
at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:78)
at android.view.View.performClick(View.java:5207)
at android.view.View$PerformClick.run(View.java:21177)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5438)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:739)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:629)
My Code:
B4X:
Dim MyPicsDate As String
Dim MyDateToday As Long
DBUtils.DropTable(Starter.SQL0, "gallery")
Dim m As Map
m.Initialize
m.Put("picName", DBUtils.DB_TEXT)
m.Put("galleryPic", DBUtils.DB_BLOB)
DBUtils.CreateTable(Starter.SQL0, "gallery", m, "")
Log("Gallery Table Created")
Dim ImageList As List
Dim ImageCount As Int
ImageList = File.ListFiles("/storage/emulated/0/DCIM/Camera/")
ImageCount = ImageList.Size
Log("File List = " & ImageList)
Log("File Count = " & ImageCount)
If ImageCount = 0 Then
ToastMessageShow("You have No Pictures in Your Gallery",False)
Activity.Finish
End If
For i = 0 To ImageCount - 1
MyPictureName = (ImageList.Get (i))
Log("Picture Name: " & MyPictureName)
Dim IsImage As String
IsImage = sf.Mid(MyPictureName,1,4)
If IsImage = "IMG_" Then
MyPicsDate = sf.Mid(MyPictureName,5,8)
DateTime.DateFormat = "yyyyMMdd"
DateTime.TimeFormat = "hh:mm:ss"
MyDateToday = DateTime.Date(DateTime.Now)
Dim p As Period = DateUtils.PeriodBetweenInDays(DateTime.DateParse(MyPicsDate), DateTime.DateParse(MyDateToday) )
Log("Number of Days: " & p.days)
If p.Days < 8 Then
'convert the image file to a bytes array
Dim InputStream1 As InputStream
InputStream1 = File.OpenInput(File.DirRootExternal & "/DCIM/Camera/",MyPictureName)'(File.DirRootExternal, "MyPortrait.jpg")
Dim OutputStream1 As OutputStream
OutputStream1.InitializeToBytesArray(1000)
File.Copy2(InputStream1, OutputStream1)
Dim Buffer() As Byte
Buffer = OutputStream1.ToBytesArray
'write the filename & image to the database
Dim ListOfMaps As List
ListOfMaps.Initialize
Dim m As Map
m.Initialize
m.Put("picName", MyPictureName)
m.Put("galleryPic", Buffer)
ListOfMaps.Add(m)
DBUtils.InsertMaps(Starter.SQL0, "gallery", ListOfMaps)
LogColor("List: " & ListOfMaps, Colors.Blue)
ListOfMaps.Clear
End If
End If
Next
' Load ListView (lvTip)
lvTip.clear
Dim Curs As Cursor
Curs = Starter.SQL0.ExecQuery("SELECT * FROM gallery")
If Curs.RowCount = 0 Then
ToastMessageShow("There are no pictures in Gallery",False)
Activity.Finish
Else
LogColor("Gallery Rows Count: " & Curs.RowCount, Colors.Blue)
lvTip.SingleLineLayout.ItemHeight = 1dip
lvTip.SingleLineLayout.Label.Color = Colors.LightGray
lvTip.TwoLinesAndBitmap.ItemHeight = 120dip
lvTip.TwoLinesAndBitmap.ImageView.Height = 80dip
lvTip.TwoLinesAndBitmap.ImageView.Width = 80dip
lvTip.TwoLinesAndBitmap.ImageView.top = 20dip
lvTip.TwoLinesAndBitmap.SecondLabel.Height = 80dip
lvTip.TwoLinesAndBitmap.SecondLabel.left = (((lvTip.TwoLinesAndBitmap.ImageView.Left) + (lvTip.TwoLinesAndBitmap.ImageView.Width)) + 5dip)
lvTip.TwoLinesAndBitmap.Label.TextColor=Colors.LightGray
lvTip.TwoLinesAndBitmap.Label.TextSize = 20
lvTip.TwoLinesAndBitmap.Label.Left = (((lvTip.TwoLinesAndBitmap.ImageView.Left) + (lvTip.TwoLinesAndBitmap.ImageView.Width)) + 5dip)
For i=0 To Curs.RowCount-1
Curs.Position=i
Dim Buffer() As Byte
Dim PicName As String
PicName = Curs.GetString("picName")
Buffer = Curs.GetBlob("galleryPic")
Dim Line1 As String
Dim Line2 As String
Line1 = "File Name:"
Line2 = PicName
Dim InputStream1 As InputStream
InputStream1.InitializeFromBytesArray(Buffer, 0, Buffer.Length)
Dim Bitmap1 As Bitmap
Bitmap1.Initialize2(InputStream1)
InputStream1.Close
lvTip.AddTwoLinesAndBitmap(Line1,Line2 , Bitmap1)
lvTip.AddSingleLine("")
Next
Curs.Close
End If