Android Question An error occurred while calling the database

ehsanez

Member
Hi. This is a problem that I did a lot of research on but failed to solve. Thank you for your help.
Error occurred on line: 449 (Main)
android.database.CursorWindowAllocationException: Cursor window allocation of 2048 kb failed. # Open Cursors=52 (# cursors opened by this proc=52)
at android.database.CursorWindow.<init>(CursorWindow.java:108)
at android.database.AbstractWindowedCursor.clearOrCreateWindow(AbstractWindowedCursor.java:198)
...
and this is a code
B4X:
Dim cure As Cursor = mysql.ExecQuery("SELECT * FROM English WHERE English_Word LIKE  '%"&userworden&"%' ")

    lblecount.Text = cure.RowCount
    lblecount.Visible = True
    Imgerecord.Visible = True
    
    If cure.RowCount > 0 Then
        
        For i=0 To cure.RowCount - 1
            cure.Position = i
            Dim enide As Int = cure.GetString("Word_ID")
            Dim cure2 As Cursor
            cure2 = mysql.ExecQuery2("SELECT * FROM Farsi WHERE English_ID =? " , Array As String(enide))
line 449 cure2.Position = 0
            
            Dim logate As String = cure2.GetString("Farsi_Word")
            Dim loagatee As String = cure.GetString("English_Word")
            Dim pe2 As Panel
            pe2.Initialize("")
            customenglist.Add(pe2 , 350dip , "" )
            pe2.Left = 0
            pe2.Width = 100%x
            pe2.LoadLayout("Ltempe")
            lblfaword.Height = 10%y
            lblemani.Height = 12%y
            lblemani.Top= 11%y
            btnsen.Height = 11%y
            btnsen.Top = 10%y
            
            btnsen.Tag = loagatee
        
            lblfaword.Text = logate
            lblemani.Text = cure.GetString("English_Word")
            
        Next
        
        Else
            ToastMessageShow("هیچ نتیجه ای یافت نشد" , False)   
    End If
    cure.Close
    cure2.Close
 

ehsanez

Member
You are fetching to much data from the database at once. You need to limit the data to not exceed 2mb of data.
Maybe add a LIMIT 0,100 to fetch only the first 100 results.
How much datasets does the query fetch???
It takes about 700 data to receive. The data is for a dictionary that should show the meaning of the word.
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
how can I do this?
Since both tables English and Farsi have a common field ( Word_ID/English_ID), you can create one resultset (sursor if you wish) by joining both table. It would be something like this and it will not take too much memory. If you continue to have problems, attach your project or a small project and the database or a small database.
B4X:
Dim rs As ResultSet
    Dim strQuery As String =$"SELECT E.Word_ID, E.English_Word, F.Farsi_Word FROM English E JOIN Farsi F 
    ON E.Word_Id = F.English_ID WHERE  E.English_Word LIKE ?"$
    rs= mysql.ExecQuery2(strQuery, Array As String( $"%${userworden}%"$))
    Do While rs.NextRow
        Log(rs.GetString("English_Word") & TAB & rs.GetString("Farsi_Word"))
    Loop
 
Upvote 1
Cookies are required to use this site. You must accept them to continue using the site. Learn more…