Problem getting imagepath's to future use
Here's the code block that should work in background to get the images URI for future use into a gallery. The asynctask select all the products in the database, and search for images into the pointed folder with the same name of the product description, if it find, it puts the product into a list of products that at the end of the asynctask declares a global var with these values.
public class getIMGS extends AsyncTask<Void, Integer, Void> {
public List<Produto> pc;
@Override
protected Void doInBackground(Void... params) {
try {
TimingLogger tm = new TimingLogger("IBS", "Inicio");
dbHelper DB = new dbHelper(start.this);
Dao<Produto, Integer> daO = DB.getProdutoDao();
//QueryBuilder<Produto, Integer> qB = daO.queryBuilder();
//qB.selectColumns("CD_REF");
List<Produto> lista = daO.queryForAll();
Produto p = null;
File f = null;
int i;
for (i = 0; i<lista.size();i++) {
开发者_高级运维 p = lista.get(i);
String path = Environment.getExternalStorageDirectory()+"/IBS/Imagens/"+p.getCD_REF()+".jpg";
f = new File(path);
Log.w("IBS", String.valueOf(i)+ " registros!");
if (f.exists()) {
pc.add(p); //This line generates the error
//NullPointerException, even all the values of p being filled. So, what the problem should be?
}
}
ImagesGlobal.setImages(pc);
Log.w("IMAGENS", String.valueOf(pc.size())+" de "+String.valueOf(i)+" produtos possuem imagens...");
Log.w("IMAGENS", "Processo de imagens finalizado!");
tm.addSplit("Fim Imagens");
tm.dumpToLog();
} catch (Exception e) {
Log.e("IMAGENS", e.getMessage());
}
return null;
}
}
Looks like this variable is null
public List<Produto> pc;
I didn't see you instantiate it
精彩评论