I what to use my online Excel database to populate my recycler view, but when I run my app the file it cannot be downloaded, it always returns the onFailure() method as in code. I test the app on an Android 4.4 kitkat phone with internet connection.
client = new AsyncHttpClient();
//Download link for my database
String db = "https://github.com/SentsAbix/Android/blob/main/computerscience.xls?raw=true";
//Download database and save it in file
client.get(db, new FileAsyncHttpResponseHandler(this) {
@Override
public void onFailure(int statusCode, Header[] headers, Throwable throwable, File file) {
fail();
}
//After Download completition
@Override
public void onSuccess(int statusCode, Header[] headers, File file) {
passed();
WorkbookSettings wbs = new WorkbookSettings();
wbs.setGCDisabled(true);
if(file != null){
try {
datab = Workbook.getWorkbook(file);
Sheet sheet = datab.getSheet(0);
//get rows available in our sheet
for(int i = 0; i < sheet.getRows() ; i++){
//store the rows in an array
Cell[] rows = sheet.getRow(i);
//then each row is stored accordingly
Regnoss.add(rows[0].getContents());
Names.add(rows[1].getContents());
}
getthedb();
} catch (IOException e) {
e.printStackTrace();
} catch (BiffException e) {
e.printStackTrace();
}
}
}
});
public void fail(){
Toast.makeText(this, "Failed to connect to the server", Toast.LENGTH_LONG).show();
}
public void passed(){
Toast.makeText(this, "Please wait while processing results", Toast.LENGTH_LONG).show();
}
The link you are using does not exist (publicly?). You always end up in onFailure() because there is no file associated with the link. The repository needs to be public.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.