【发布时间】:2017-06-26 12:58:56
【问题描述】:
我似乎无法深入了解这一点。使用 Apache POI 读取 excel 文件。似乎遇到了错误。使应用强制关闭。
java.lang.IllegalStateException: Could not execute method for android:onClick
我的 XML android:onClick id 与我的方法侦听器同名:
<Button
android:text="OK"
android:id="@+id/submitOK"
android:textAlignment="center"
android:textAppearance="@style/TextAppearance.AppCompat.Caption"
android:textSize="12sp"
android:background="@drawable/round_button"
android:gravity="center_vertical|center_horizontal"
android:textColor="#fff"
android:layout_alignTop="@+id/setName"
android:layout_toRightOf="@+id/setName"
android:layout_marginLeft="5dp"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_alignBottom="@+id/setName"
**android:onClick="inRoster"**
android:visibility="gone"
/>
public void inRoster(View v) throws IOException {
if (checkValidinFile()) {
// Send to a new page that lists your shifts, what time you want your alarms
// and what time you want messages to be sent
// What time do you want to send the messages?
// What time do you want your alarms to be?
// Do all alarm and message sending bs
} else {
// Display a toast message saying name not found
// Clear contents of the editbox for the name for user to re enter
CharSequence text = "Name not found in Roster!";
setName.setText("");
int duration = Toast.LENGTH_SHORT;
Toast.makeText(this, text, duration).show();
}
}
这似乎是此方法中出现错误的地方,但我不明白为什么。
public boolean checkValidinFile() throws IOException {
String nameToMatch = setName.getText().toString().toLowerCase();
try {
InputStream ExcelFileToRead = new FileInputStream(roster);
XSSFWorkbook wb = new XSSFWorkbook(ExcelFileToRead);
XSSFSheet sheet = wb.getSheetAt(0);
Iterator<Row> iterator = sheet.iterator();
while (iterator.hasNext()) {
Row currentRow = iterator.next();
Iterator<Cell> cellIterator = currentRow.iterator();
while (cellIterator.hasNext()) {
Cell currentCell = cellIterator.next();
System.out.println(currentCell.toString() + " ");
}
}
System.out.println();
wb.close();
ExcelFileToRead.close();
}
catch (IOException e) {
e.printStackTrace();
}
return true;
}
'SetName'在类的顶部全局定义,无需实例化,然后在onCreate中定义为:
setName = (EditText) findViewById(R.id.setName);
感谢您提供任何帮助,让我知道您还需要什么其他信息,我还遇到了一些其他问题,即 I/art 拒绝重新初始化以前失败的课程。如果您认为这两个问题可能相关,请参阅下面的链接。
【问题讨论】:
-
我认为它被否决的唯一原因是因为它是如此“容易解决”,如果是这样,为什么你不投反对票并离开页面,而不是投反对票,回答问题然后离开。我查看了其他类似的答案,检查了类似实例的代码并尝试了这些修复,但没有解决任何问题。
标签: java android apache-poi