我最近尝试使用重构在Eclipse中重命名我的项目,当我这样做时,我遇到了很多错误。我想我已经解决了所有这些问题,但是现在我的程序在读取.xlsx文件时卡住了。
package com.example.sumit.demoapplication4;
import android.app.Activity;
import android.app.ListActivity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.AsyncTask;
import android.os.Bundle;
import android.provider.MediaStore;
import android.util.Base64;
import android.util.Log;
import android.view.View;
import android.widget.ImageButton;
import android.widget.SimpleAdapter;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Objects;
import java.util.concurrent.ExecutionException;
public class SearchNovel extends ListActivity {
SimpleAdapter simpleAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_search_novel);
ArrayList<HashMap<String,Object>> feedList=new ArrayList<HashMap<String, Object>>();
HashMap<String,Object> map=new HashMap<String,Object>();
String result=getData();
if (!result.equals("")) {
String[] r1=result.split("<br>");
for(int i=0;i<r1.length;i++){
String[] r2=r1[i].split(",", 2);
String title=r2[0].toString().trim();
String author=r2[1].toString().trim();
Bitmap bitmap=null;
try {
bitmap= new GetImage().execute(title).get();
} catch (InterruptedException e) {
e.printStackTrace();
} catch (ExecutionException e) {
e.printStackTrace();
}
map=new HashMap<String,Object>();
String stringImage=getStringImage(bitmap);
map.put("image",stringImage);
map.put("title",title);
map.put("author", author);
feedList.add(map);
}
}
simpleAdapter=new SimpleAdapter(this,feedList,R.layout.novellist,new String[]{"image","title","author"},new int[]{R.id.icon,R.id.tv1,R.id.tv2});
setListAdapter(simpleAdapter);
}
private String getStringImage(Bitmap bitmap) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
//resizedBitmap.compress(Bitmap.CompressFormat.JPEG, 100, baos);
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, baos);
byte[] imageBytes = baos.toByteArray();
String encodedImage = Base64.encodeToString(imageBytes, Base64.DEFAULT);
return encodedImage;
}
private String getData() {
String data=null;
class RetrieveData extends AsyncTask<String,String,String>{
ProgressDialog progressDialog;
@Override
protected void onPreExecute() {
super.onPreExecute();
progressDialog=ProgressDialog.show(SearchNovel.this,"Connecting Server...","Please Wait...",true,true);
}
@Override
protected String doInBackground(String... params) {
String url="http://192.168.43.89/phpmyadmin/shareNovel/NovelList.php";
try{
URL u=new URL(url);
HttpURLConnection httpURLConnection=(HttpURLConnection)u.openConnection();
httpURLConnection.setRequestMethod("POST");
httpURLConnection.setDoInput(true);
httpURLConnection.setDoOutput(true);
InputStream inputStream=httpURLConnection.getInputStream();
BufferedReader bufferedReader=new BufferedReader(new InputStreamReader(inputStream,"UTF-8"));
String response="";
String temp="";
while((temp=bufferedReader.readLine())!=null){
response+=temp;
}
bufferedReader.close();
inputStream.close();
httpURLConnection.disconnect();
return response;
}catch (Exception e){
e.printStackTrace();
}
return null;
}
@Override
protected void onPostExecute(String s) {
super.onPostExecute(s);
progressDialog.dismiss();
}
}
RetrieveData retrieveData=new RetrieveData();
try{
data= retrieveData.execute().get();
}catch (Exception e){
e.printStackTrace();
}
return data;
}
private class GetImage extends AsyncTask<String,String,Bitmap> {
@Override
protected Bitmap doInBackground(String... params) {
String title=params[0];
String url="http://192.168.43.89/phpmyadmin/shareNovel/getImageNovel.php";
Bitmap image=null;
try{
URL url1=new URL(url);
HttpURLConnection httpURLConnection=(HttpURLConnection)url1.openConnection();
httpURLConnection.setRequestMethod("POST");
httpURLConnection.setDoInput(true);
httpURLConnection.setDoOutput(true);
OutputStream outputStream = httpURLConnection.getOutputStream();
BufferedWriter bufferedWriter = new BufferedWriter(new OutputStreamWriter(outputStream, "UTF-8"));
String data = URLEncoder.encode("title", "UTF-8") + "=" + URLEncoder.encode(title, "UTF-8");
bufferedWriter.write(data);
bufferedWriter.close();
image=BitmapFactory.decodeStream(httpURLConnection.getInputStream());
}catch (Exception e){
e.printStackTrace();
}
return image;
}
}
问题区域似乎在“工作簿=新的XSSFWorkbook(文件);” line因为在调试器中,工作簿中填充了空值。在我的构建路径中,我包含了以下.jar文件:
有什么想法吗?