473,394 Members | 1,717 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Trouble with viewbinder simplecursortreeadapter -unable to convert string to blob

I have pictures in my sqlite prepopulated database, i'm using Simplecursortreeadapter to pass data to exepndablelistview , but the app crush when opening a childview with a picture and in logcat i got "UNABLE TO CONVERT STRING TO BLLOB'.
After making some research on internet i discovered(maybe) i have to implement viewbinder which i did ( copy past and addapt to my columns) ..what i have done is based on the answer of this question:https://stackoverflow.com/questions/30388843/unable-to-convert-blob-to-string-using-loadermanager-in-android ..

But The app can't build successfuly now...i think i'm missing something or there is something wrong with my code:

Please help! thanks


Expand|Select|Wrap|Line Numbers
  1.     public class MainActivity extends AppCompatActivity {
  2.         ExpandableListView expandableListView;
  3.         Database mDatabase;
  4.  
  5.         @Override
  6.         protected void onCreate(Bundle savedInstanceState) {
  7.             super.onCreate(savedInstanceState);
  8.             setContentView(R.layout.activity_main);
  9.  
  10.             mDatabase = new Database(this);
  11.             mDatabase.open();
  12.  
  13.             SimpleCursorTreeAdapter.setViewBinder( new MyViewBinder());
  14.  
  15.             Cursor cursor = mDatabase.getDatabase();
  16.             startManagingCursor(cursor);
  17.  
  18.             String[] childFrom = new String[]{Database.DATABASE_CHILD_1,Database.DATABASE_CHILD_2};
  19.             String[] groupFrom = new String[]{Database.DATABASE_GROUP_1};
  20.  
  21.             int[] groupTo = {R.id.group1};
  22.             int[] childTo = {R.id.child1,R.id.child2};
  23.  
  24.             SimpleCursorTreeAdapter simplecursortreeAdapter = new ExpandableListViewAdapter(
  25.                     this,
  26.                     cursor,
  27.                     R.layout.list_group,
  28.                     groupFrom,
  29.                     groupTo,
  30.                     R.layout.list_child,
  31.                     childFrom,
  32.                     childTo
  33.             );
  34.  
  35.             expandableListView = findViewById(R.id.expandableListview);
  36.             expandableListView.setAdapter(simplecursortreeAdapter);
  37.         }
  38.  
  39.         protected void onDestroy() {
  40.             super.onDestroy();
  41.             mDatabase.close();
  42.         }
  43.  
  44.         public class MyViewBinder implements ViewBinder {
  45.             @Override
  46.             public boolean setViewValue(View view, Cursor cursor, int columnIndex) {
  47.                 int viewID = view.getId();
  48.                 switch(viewID){
  49.                     case R.id.child1 :
  50.                         TextView friendName = (TextView) view;
  51.                         String friend_name;
  52.                         friend_name = cursor.getString(cursor.getColumnIndex(Database.DATABASE_CHILD_1));
  53.                         friendName.setText(friend_name);
  54.                         break;
  55.  
  56.                     case R.id.child2 :
  57.                         ImageView contactProfile = (ImageView) view;
  58.                         byte[] imageBytes = cursor.getBlob(cursor.getColumnIndex(Database.DATABASE_CHILD_2));
  59.                         if(imageBytes != null ){
  60.                             // Pic image from database
  61.                             contactProfile.setImageBitmap(BitmapFactory.decodeByteArray(imageBytes, 0, imageBytes.length));
  62.                         }else {
  63.                             // If image not found in database , assign a default image
  64.                             contactProfile.setBackgroundResource(R.drawable.disorders);
  65.                         }
  66.                         break;
  67.                 }
  68.                 return true;
  69.             }
  70.  
  71.         }
  72.  
  73.         private class ExpandableListViewAdapter extends SimpleCursorTreeAdapter {
  74.             private ExpandableListViewAdapter(
  75.                     Context context,
  76.                     Cursor cursor,
  77.                     int groupLayout,
  78.                     String[] groupFrom,
  79.                     int[] groupTo,
  80.                     int childLayout,
  81.                     String[] childFrom,
  82.                     int[] childTo) { super(context, cursor, groupLayout, groupFrom, groupTo, childLayout, childFrom, childTo); }
  83.  
  84.             protected Cursor getChildrenCursor(Cursor groupCursor) {
  85.                 return mDatabase.getID(groupCursor.getInt(groupCursor.getColumnIndex(Database.DATABASE_ID)));
  86.             }
  87.  
  88.         }
  89.  
  90.  
  91.     }
  92.  
Jul 31 '18 #1
0 2101

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Nathan | last post by:
Is there a way to convert a string to a CipherMessage? I am calling a function that decrypts a CipherMessage and returns the value. The only problem is when I want to use an encrypted value stored...
3
by: news.hku.hk | last post by:
could you tell me how can i convet a string to integer?? #include <iostream> #include <string> using namespace std; int main(){ int integer; string buffer("123456789");
5
by: sarab | last post by:
Hi, I have a managed C++ app in which i need to convert String * to char *. How can i achive this?. regards -sarab
3
by: Petr Jakes | last post by:
Hi, I am trying to convert string to the "escaped string". example: from "0xf" I need "\0xf" I am able to do it like: a="0xf" escaped_a=("\%s" % a ).decode("string_escape") But it looks a...
5
by: XML newbie: Urgent pls help! | last post by:
function to convert string to 1 dimensional array of long in VB.Net
3
by: Ursula | last post by:
Is it possible to convert a string in a file. The problem is this: I have an object string that is a file xml and I want to pass to Deserialize function, but Deserialize function expect an object...
3
by: Shawn Ferguson | last post by:
Hello All, I'm trying to do what I would think would be simple and straightforward, but it is not. I have a 2 textbox on a form, a label, and a button, when I click the botton I want to add the...
4
by: Man4ish | last post by:
HI , I am trying to convert string into char array of characters.but facing problem. #include <iostream> #include <string> using namespace std; int main() { string t="1,2,3,4,5,6";
12
by: Peter | last post by:
Trying to convert string to byte array. the following code returns byte array of {107, 62, 194, 139, 64} how can I convert this string to a byte array of {107, 62, 139, 65} ...
9
by: engteng | last post by:
How do I convert string to numeric in VB.NET 2003 ? Example convert P50001 to 50001 or 50001P to 50001 but if P is in middle then not convert. Regards, Tee
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.