Java错误与Eclipse阅读Excel文件

我是新来的Java,但一个快速的学习者。 我正在尝试让我的Android应用程序从EditText获取用户input,在Excel列中search匹配的string,并返回另一列(同一行)的值。

我在构buildpath中添加了一个jxl.jar,我的代码看起来应该可以工作。 教我自己,我正在慢慢地搞清楚debugging。 这个问题似乎是源android.jar没有find(如果我没记错的话)。 我find它,现在我得到“源附件不包含文件instrumentation.class源”

这是我第一个使用Excel的应用程序。 我需要以某种方式解决Android Manifest?

这是我的代码,以防万一,非常感谢任何帮助!

public class Frame_Bore extends Activity { private String inputFile; public void setInputFile(String inputFile) { this.inputFile = "c:/Desktop/AAS Work/PDA Programs/JBDB.xls"; } @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.framebore); Button Btn1 = (Button) findViewById(R.id.button1); final EditText T1 = (EditText) findViewById(R.id.et1); final EditText T2 = (EditText) findViewById(R.id.et2); Btn1.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { // TODO Auto-generated method stub String t1Value = T1.getText().toString(); File inputWorkbook = new File(inputFile); Workbook w; String bore = null; try { w = Workbook.getWorkbook(inputWorkbook); Sheet sheet = w.getSheet("Frame-Bore"); int y = 6; while (y < 200) { int x = 2; Cell columnB = sheet.getCell(x, y); String motorframe = columnB.getContents(); if (motorframe == t1Value) { Cell columnC = sheet.getCell(x + 1, y); bore = columnC.getContents(); } else { y = y + 1; } } } catch (BiffException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } finally { T2.setText("" + bore); } } }); } 

您正尝试从模拟器访问c:drive(“c:/ Desktop / AAS Work / PDA Programs / JBDB.xls”),这是不可能的。 如果你在设备上运行,你需要把你的excel文件放在资源文件夹或者SD卡中。

一个仿真器有一个虚拟的SD卡,它的限制是它不能直接从计算机访问任何其他驱动器。 但是,你可以做一个web服务,它将代表你的android应用程序执行操作。 你需要从你的android应用程序调用这个web服务。

把文件放在资产文件夹中,像这样访问它:

 InputStream is = null; try { is = context.getAssets().open("JBDB.xls"); workbook = Workbook.getWorkbook(is); } catch (IOException e) { e.printStackTrace(); } catch (BiffException e) { e.printStackTrace(); } if(workbook!=null) sheet = workbook.getSheet("Frame-bore"); 

context是您主要的活动上下文。