Android Question Error loading bitmap

Mark Ryan Penafiel

Licensed User
Longtime User
I am trying to retrieve image from mysql but i got this error. I follow the instructions here Here is the code
#Region  Activity Attributes
    #FullScreen: False
    #IncludeTitle: True
#End Region


Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
    Private xui As XUI
    Private badge As Int
    Private cartBitmap As Bitmap
    Dim txt As String
    Dim SQL1 As SQL
    Dim dbCursor As Cursor
'    Dim Const POSITION_TOP_LEFT As Int  = 1
'    Dim Const POSITION_TOP_RIGHT As Int = 2
'    Dim Const POSITION_BOTTOM_LEFT As Int = 3
'    Dim Const POSITION_BOTTOM_RIGHT As Int = 4
'    Dim Const POSITION_CENTER As Int = 5
    Dim counter, marketscount As Int
End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
    Dim TextScale As Float
    Dim TextScale2 As Float
    Private Label1 As Label
    Private ImageView1 As ImageView
    Private Label2 As Label
    Private CLV1 As CustomListView
    Private Panel1 As Panel
    Private ACToolBarLight1 As ACToolBarLight
    Private ToolbarHelper As ACActionBar
'    Dim cartBadge As Badger
    Private Button1 As Button
    Private Label5 As Label
    Private Label4 As Label
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    If FirstTime Then
        cartBitmap = LoadBitmap(File.DirAssets, "cart.png")
        If File.Exists(File.DirInternal, "grocer.db") = False  Then
            File.Copy(File.DirAssets, "grocer.db", File.DirInternal, "grocer.db")
        End If
        SQL1.Initialize(File.DirInternal, "grocer.db", True)
    End If
'    TextScale = GetDeviceLayoutValues.Height/800
'    TextScale2 = TextScale / GetDeviceLayoutValues.Scale
'    Label1.TextSize = 16 * TextScale2
'    Label2.TextSize = 10 * TextScale2
'    Label4.TextSize = 14 * TextScale2
'    Label5.TextSize = 14 * TextScale2
    ToolbarHelper.ShowUpIndicator = True 'set to true to show the up arrow
    ToolbarHelper.UpIndicatorDrawable = BitmapToBitmapDrawable(LoadBitmap(File.DirAssets, "hamburger.png"))
'    Activity.AddMenuItem3("", "cart", xui.LoadBitmapResize(File.DirAssets, "cart.png", 32dip, 32dip, True), True)
    ProgressDialogShow2("Please Wait...",False)
    ExecuteRemoteQuery("SELECT * FROM `market` ORDER BY `id`" , "Markets")
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub Activity_CreateMenu(Menu As ACMenu)
    Log("Menu Added")
    Menu.Add(0, 0, "Overflow1", Null)
    Menu.Add(0, 0, "Overflow2", Null)
    Menu.Add(0, 0, "Overflow3", Null)
    Dim item As ACMenuItem = ACToolBarLight1.Menu.Add2(0, 0, "cart", Null)
    item.ShowAsAction = item.SHOW_AS_ACTION_ALWAYS
    UpdateIcon("cart", AddBadgeToIcon(cartBitmap, badge))
End Sub

Sub AddBadgeToIcon(bmp As Bitmap, Number As Int) As Bitmap
    Dim cvs As Canvas
    Dim mbmp As Bitmap
    mbmp.InitializeMutable(32dip, 32dip)
    Dim target As Rect
    target.Initialize(0, 0, mbmp.Width, mbmp.Height)
    cvs.DrawBitmap(bmp, Null, target)
    If Number > 0 Then
        cvs.DrawCircle(mbmp.Width - 8dip, 8dip, 8dip, Colors.Red, True, 0)
        cvs.DrawText(Min(Number, 9), mbmp.Width - 8dip, 12dip, Typeface.DEFAULT_BOLD, 12, Colors.White, "CENTER")
    End If
    Return mbmp
End Sub

Sub UpdateIcon(MenuTitle As String, Icon As Bitmap)
    Dim m As ACMenuItem = GetMenuItem(MenuTitle)
    m.ShowAsAction = m.SHOW_AS_ACTION_ALWAYS
    m.Icon = BitmapToBitmapDrawable(Icon)
End Sub

Sub BitmapToBitmapDrawable (bitmap As Bitmap) As BitmapDrawable
    Dim bd As BitmapDrawable
    Return bd
End Sub

Sub ACToolBarLight1_MenuItemClick (Item As ACMenuItem)
    Log("Clicked: " & Item.Title)
End Sub

Sub GetMenuItem(Title As String) As ACMenuItem
    For i = 0 To ACToolBarLight1.Menu.Size - 1
        Dim m As ACMenuItem = ACToolBarLight1.Menu.GetItem(i)
        If m.Title = Title Then
            Return m
        End If
    Return Null
End Sub

#If Java

public boolean _onCreateOptionsMenu(android.view.Menu menu) {
    if (processBA.subExists("activity_createmenu")) {
        processBA.raiseEvent2(null, true, "activity_createmenu", false, new de.amberhome.objects.appcompat.ACMenuWrapper(menu));
        return true;
        return false;
#End If

Private Sub CreateItem(Width As Int, Market As String, Image As Bitmap, Address As String) As Panel
    Dim p As Panel
    Dim Height As Int = 20%Y
'    If GetDeviceLayoutValues.ApproximateScreenSize < 4.5 Then Height = 210dip
    p.SetLayoutAnimated(0, 0, 0, Width, Height)
    Label1.Text = Market
    Label2.Text = Address
'    lblContent.Text = Content
'    SetColorStateList(Label2, xui.Color_LightGray, Label2.TextColor)
'    SetColorStateList(lblAction2, xui.Color_LightGray, lblAction2.TextColor)
    Return p
End Sub

Sub SetColorStateList(Btn As Label,Pressed As Int,Enabled As Int)
    Dim States(2,1) As Int
    States(0,0) = 16842919    'Pressed
    States(1,0) = 16842910    'Enabled
    Dim CSL As JavaObject
    CSL.InitializeNewInstance("android.content.res.ColorStateList",Array(States,Array As Int(Pressed, Enabled)))
    Dim B1 As JavaObject = Btn
    B1.RunMethod("setTextColor",Array As Object(CSL))
End Sub

Sub CLV1_ItemClick (Index As Int, Value As Object)
End Sub

Sub ACToolBarLight1_NavigationItemClick
End Sub

Sub JobDone(Job As HttpJob)
    If Job.Success Then
        Dim res As String
        res = Job.GetString
        Log("Response from server: " & res)
        Dim parser As JSONParser
        Select Job.JobName
            Case "Markets"
                txt = "DELETE FROM Shops"
                Dim l As List
                l = parser.NextArray 'returns a list with maps
                For i = 0 To l.Size - 1
                    Dim m As Map
                    m = l.Get(i)
                    Dim su As StringUtils
                    Dim ImageBytes() As Byte
                    ImageBytes = su.DecodeBase64(m.Get("image"))
                    Dim bmp As Bitmap
                    Dim InputStream As InputStream
                    InputStream.InitializeFromBytesArray(ImageBytes, 0, ImageBytes.Length)
                    CLV1.Add(CreateItem(CLV1.AsView.Width, m.Get("storename"), bmp, m.Get("description")), m.Get("storename"))
        End Select
        ToastMessageShow("Error: " &"No Internet", True)
    End If
End Sub

Sub ExecuteRemoteQuery(Query As String, JobName As String)
    Dim job As HttpJob
    job.Initialize(JobName, Me)
    job.PostString("", Query)
End Sub


$databasehost = "localhost";
$databasename = "grab_palengke";
$databaseusername ="root";
$databasepassword = "birdistheword978234";

$con = mysql_connect($databasehost,$databaseusername,$databasepassword) or die(mysql_error());
mysql_select_db($databasename) or die(mysql_error());
mysql_query("SET CHARACTER SET utf8");
$query = file_get_contents("php://input");
$sth = mysql_query($query);

if (mysql_errno()) {
    header("HTTP/1.1 500 Internal Server Error");
    echo $query.'\n';
    echo mysql_error();
    $rows = array();
    while($r = mysql_fetch_assoc($sth)) {
        if (array_key_exists('image', $r)) {
         $r['image'] = base64_encode($r['image']);
        $rows[] = $r;
    print json_encode($rows);
Last edited: