input = new File(filePath); try { //parse the html file Document doc; Course course = new Course(); doc = Jsoup.parse(input, "UTF-8"); //经测试后,我认为是这句引起的程序崩溃 Elements links = doc.getElementsByAttributeValue("ALIGN","left"); int i = 0; boolean needrecord = false;//in order to find the information needed
for (Element link : links) {//setText on the screen and save the information as a file String linkText = link.text(); if(linkText.equals("EE")){//after String EE found, the course name, date, and instructor needrecord = true; //can be found in the fixed position } if(needrecord){ i++; if(i == 4){//course name coursesList.setText(linkText+" "); } if(i == 5){//date coursesList.setText(linkText+" "); } if(i == 8){//instructor coursesList.setText(linkText+" \n"); needrecord = false; i = 0; } } } flage = true; } catch (IOException e) { // TODO Auto-generated catch block coursesList.setText("ERROR!"+e.toString()); e.printStackTrace();
} }//if
else{ coursesList.setText("File path is not right. Check the path and retype the path."); }
您是说onClick这个按钮的代码吗?
<Button
android:id="@+id/set"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:onClick="getFile"
android:text="@string/set" />就是我贴出来的那段
我一开始引用了
jsoup-1.7.3-javadoc.jar
jsoup-1.7.3-sources.jar
jsoup-1.7.3.jar然后我删掉 jsoup-1.7.3-sources.jar
并在 java build path --> order and export 里面勾选了相应jar文件之后就好了(如图)! 谢谢~!
//onClick getFile
public void getFile(View view) {
File input;
TextView coursesList = (TextView) findViewById(R.id.theList);
TextView location = (TextView) findViewById(R.id.location);
filePath = location.getText().toString();
if(fileIsExists(filePath)){
input = new File(filePath);
try {
//parse the html file
Document doc;
Course course = new Course();
doc = Jsoup.parse(input, "UTF-8"); //经测试后,我认为是这句引起的程序崩溃
Elements links = doc.getElementsByAttributeValue("ALIGN","left");
int i = 0;
boolean needrecord = false;//in order to find the information needed
for (Element link : links) {//setText on the screen and save the information as a file
String linkText = link.text();
if(linkText.equals("EE")){//after String EE found, the course name, date, and instructor
needrecord = true; //can be found in the fixed position
}
if(needrecord){
i++;
if(i == 4){//course name
coursesList.setText(linkText+" ");
}
if(i == 5){//date
coursesList.setText(linkText+" ");
}
if(i == 8){//instructor
coursesList.setText(linkText+" \n");
needrecord = false;
i = 0;
}
}
}
flage = true;
} catch (IOException e) {
// TODO Auto-generated catch block
coursesList.setText("ERROR!"+e.toString());
e.printStackTrace();
}
}//if
else{
coursesList.setText("File path is not right. Check the path and retype the path.");
}
}
问题已经解决了 谢谢~