android


Android ListView generated from SQLite database not displaying on phone screen (but displaying on emulator)


I'm new to Android and I'm currently designing an app in which I need to display a list of birds at some point. In order to do this, I have data that is stored in a SQLite database.
So, at some point, I click on a ListView item which starts a new activity, the one that is supposed to display the list of birds I need. The thing is when I run the app from the emulator in Android Studio, the bird ListView is displayed just fine but when I try to run it from my phone, the ListView is not displayed, only the title of the activity is displayed, the rest of the screen stays blank. I should mention that before running the app from the emulator, I use ADB and Android Device Monitor to put the database in the emulator's file system, only I don't know what I have to do to transmit the database to my phone when I want to run the app from my phone.
MenuOiseaux.java, the activity in which I want to display the list of birds:
package com.example.ant.kits;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import java.util.ArrayList;
import java.util.HashMap;
public class MenuOiseaux extends AppCompatActivity
{
ListView vue;
private SQLiteDatabase db;
DBOpenHelper dbOpenHelper;
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.list_view);
dbOpenHelper = new DBOpenHelper(this, DBOpenHelper.Constants.DATABASE_NAME, null,
DBOpenHelper.Constants.DATABASE_VERSION);
db = dbOpenHelper.getWritableDatabase();
Cursor cursor = db.rawQuery("SELECT " + DBOpenHelper.Constants.KEY_COL_ID
+ " , " + DBOpenHelper.Constants.KEY_COL_MINIATURE
+ " , " + DBOpenHelper.Constants.KEY_COL_NOM
+ " FROM " + DBOpenHelper.Constants.MY_TABLE ,null);
ArrayList<HashMap<String, Object>> liste = new ArrayList<>();
HashMap<String, Object> element;
while (cursor.moveToNext())
{
byte[] byteArray = cursor.getBlob(1);
Bitmap bmp = BitmapFactory.decodeByteArray(byteArray,0,byteArray.length);
if(bmp == null){db.close();}
element = new HashMap<>();
element.put("miniature", bmp);
element.put("nom",cursor.getString(2));
liste.add(element);
}
cursor.close();
vue = (ListView) findViewById(R.id.listView);
SimpleAdapter adapter = new SimpleAdapter(this,
liste,
R.layout.list_item,
new String[] {"miniature","nom"},
new int[] {R.id.img,R.id.txt});
adapter.setViewBinder(new MyViewBinder());
vue.setAdapter(adapter);
vue.setOnItemClickListener(new ListView.OnItemClickListener()
{
#Override
public void onItemClick(AdapterView<?> adapterView, View view, int position, long id)
{
Cursor cursor = db.rawQuery("SELECT " + DBOpenHelper.Constants.KEY_COL_ID
+ " , " + DBOpenHelper.Constants.KEY_COL_NOM
+ " , " + DBOpenHelper.Constants.KEY_COL_PHOTO
+ " , " + DBOpenHelper.Constants.KEY_COL_DESCRIPTION
+ " FROM " + DBOpenHelper.Constants.MY_TABLE
+ " WHERE " + DBOpenHelper.Constants.KEY_COL_ID + " = " + String.valueOf(position+1),null);
cursor.moveToFirst();
Intent intent = new Intent(MenuOiseaux.this, FicheBiodiv.class);
intent.putExtra("Nom", cursor.getString(1));
byte[] byteArray = cursor.getBlob(2);
Bitmap bmp = BitmapFactory.decodeByteArray(byteArray, 0 ,byteArray.length);
intent.putExtra("BitmapImage", bmp);
intent.putExtra("Description", cursor.getString(3));
startActivity(intent);
}
});
}
}
DBOpenHelper.java, which is used to create the database (?):
package com.example.ant.kits;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.provider.BaseColumns;
public class DBOpenHelper extends SQLiteOpenHelper
{
public static class Constants implements BaseColumns
{
public static final String DATABASE_NAME = "animaux.db";
public static final int DATABASE_VERSION = 1;
public static final String MY_TABLE = "Animaux";
public static final String KEY_COL_ID = "_id";
public static final String KEY_COL_MINIATURE = "miniature";
public static final String KEY_COL_NOM = "nom";
public static final String KEY_COL_DESCRIPTION = "description";
public static final String KEY_COL_PHOTO = "photo";
public static final int ID_COL = 1;
public static final int NOM_COL = 2;
public static final int DESCRIPTION_COL = 3;
public static final int PHOTO_COL = 4;
}
private static final String DATABASE_CREATE = "CREATE TABLE " + Constants.MY_TABLE + " ( "
+ Constants.KEY_COL_ID + " integer primary key autoincrement, "
+ Constants.KEY_COL_MINIATURE + " BLOB , "
+ Constants.KEY_COL_NOM + " TEXT , "
+ Constants.KEY_COL_DESCRIPTION + " TEXT ,"
+ Constants.KEY_COL_PHOTO + " BLOB )";
public static final String METIER_TABLE_DROP = " DROP TABLE IF EXISTS " + Constants.MY_TABLE + " ;";
public DBOpenHelper(Context context, String name, SQLiteDatabase.CursorFactory factory, int version)
{
super(context, name, factory, version);
}
#Override
public void onCreate(SQLiteDatabase db)
{
db.execSQL(DATABASE_CREATE);
}
#Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion)
{
db.execSQL(METIER_TABLE_DROP);
onCreate(db);
}
}
Sorry if I'm not being clear and thanks in advance for helping me out!
You aren't getting any list on device because your database is empty. Try adding a few entries to your table through code. It should work.
You should read this answer to copy your database:
http://stackoverflow.com/a/29733700/5671534

Related Links

Visual Studio not recognizing emulator (AVD)
Detect When android device is turn on after switch off position
SOLVED IAP Android problems trying to upgrade subscription with getBuyIntentExtraParams not returning BUY_INTENT key
User profile info null in Firebase Auth with Google Sign-In
Cordova Android Expansion Pack for 2017
How to set in Autocomplete text view in my Project below
Unity Android Game with database not working on Android, but in my PC, it is working
Android RadioGroup/RadioButton Selection - Different in Android API 16/17 - Cannot Select Radiobutton
android web font different
Cannot load library: find_library[1201]: 1192 'libzbarjni.so' failed to load previously
How to show xAxis labels in MP android Bubble chart 3.0
Typing in edittext increase its space and decreases the other edittext space
Android Studio Structural Search Class Constructors No of parameters
Rebrending for Android app
Android add aar file as module library
how to insert imageview to custom xml shape android

Categories

HOME
shell
phpword
rdbms
ns-3
saml-2.0
jsf-2.2
alarm
google-cloud-functions
web-hosting
visual-studio-emulator
bookmarks
android-json
pkcs#11
syntaxnet
why3
redis-sentinel
xcodebuild
intercom
gkturnbasedmatch
frequency-distribution
event-sourcing
microsoft-dynamics-nav
standards
intershop
feathersjs
google-data-studio
wolframalpha
smartclient
digital-signature
mapstruct
jmp
sse
exploit
displaytag
comparator
delimiter
fractions
bringtofront
winpe
twiml
sqsh
send
volatile
powershell-ise
testbed
glib
card.io
android-gridview
hard-drive
installshield-le
getlasterror
navigator
xcode7.3
z-notation
verifiable-c
unordered-map
signals-slots
laravel-elixir
jide
lampp
linter
mschart
java-bytecode-asm
er-diagram
check-mk
branch-prediction
polyline
rocks
webjars
microstation
resourcemanager
mongodb-php
mediametadataretriever
nss
spreadjs
turbo-prolog
beanstalk
contentcontrol
asyncdisplaykit
terracotta
computer-architecture
video-player
visual-sourcesafe-2005
skspritenode
cwrsync
zend-currency
j-security-check
bcache
code-documentation
openbabel
adehabitathr
cryptographichashfunction
rapidsvn
administration
sql-scripts
easyrtc
ss7
matrix-inverse
alternate
amslidemenu
accesscontrolexception
ecslidingviewcontroller
visual-studio-express
asdf
scmmanager
android-icons
video-codecs
cardreader
apache-abdera
qi4j
monotouch.dialog
uimanageddocument
wcf-configuration
faye
thttpd
virtualpathprovider
pinch
google-ajax-api
unattended-processing
instantiationexception
cruisecontrol.rb
web-garden
pos-for-.net
build-environment
data-mapping
product-management
online-storage

Resources

Encrypt Message



code
soft
python
ios
c
html
jquery
cloud
mobile