package com.example.examlast;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.loopj.android.http.AsyncHttpClient;
import com.loopj.android.http.FileAsyncHttpResponseHandler;
import jxl.Cell;
import jxl.WorkbookSettings;
import jxl.read.biff.BiffException;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Adapter;
import android.widget.ProgressBar;
import android.widget.Toast;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import cz.msebera.android.httpclient.Header;
public class MainActivity extends AppCompatActivity {
RecyclerView recyclerView;
Adapter adapter;
AsyncHttpClient client;
Workbook workbook;
List<String> titles,descriptions,imageUrl;
ProgressBar progressBar;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
String url = "https://github.com/bikashthapa01/excel-reafer-android-app/blob/master/story.xls?raw=true";
recyclerView = findViewById(R.id.listOfData);
progressBar = findViewById(R.id.progressBar);
titles = new ArrayList<>();
imageUrl = new ArrayList<>();
client = new AsyncHttpClient();
progressBar.setVisibility(View.VISIBLE);
client.get(url,new FileAsyncHttpResponseHandler(this){
@Override
public void onFailure(int statusCode, Header[] headers, Throwable throwable, File file){
progressBar.setVisibility(View.GONE);
Toast.makeText(MainActivity.this,"Download Failed.", Toast.LENGTH_SHORT).show();
}
@Override
public void onSuccess(int statuscode,Header[] headers, File file){
progressBar.setVisibility(View.GONE);
Toast.makeText(MainActivity.this,"FileDownloaded. ", Toast.LENGTH_SHORT).show();
WorkbookSettings ws = new WorkbookSettings();
ws.setGCDisabled(true);
if(file != null){
try {
workbook = workbook.getWorkbook(file);
Sheet sheet = workbook.getSheet(0);
for(int i = 0; i < sheet.getRows();i++){
Cell[] row = sheet.getRow(i);
titles.add(row[0].getContents());
descriptions.add(row[1].getContents());
imageUrl.add(row[2].getContents());
}
showDate();
Log.d("Tag","onSuccess: "+titles);
} catch (IOException e){
e.printStackTrace();
} catch (BiffException e){
e.printStackTrace();
}
}
}
});
}
private void showDate() {
adapter = (Adapter) new com.example.examlast.Adapter(this,titles,descriptions,imageUrl);
recyclerView.setLayoutManager(new LinearLayoutManager(this));
recyclerView.setAdapter((RecyclerView.Adapter) adapter);
}
}
현재
if(file != null){
구문 이후 try 구문 안에서 getWorkbook,getRows,그리고 Cell있는 줄이 오류가 발생합니다 ㅠㅠ 디버그만 5시간 넘어가서 너무 힘들어서 정말 죄송하지만 이렇게 질문드립니다..ㅠㅠ
혹시 도움이 될까봐 오류로그 사진이라도 올리겠습니다.
고수님들 한번만 부탁드려도 될까요...?ㅠㅠ