1 Soot版本及jdk版本
软件 | 版本 |
---|---|
Soot | 3.0.1 |
jdk | 1.8 |
2 相关问题
问题说明:Soot处理.class文件出现"Exception in thread “main” java.lang.Error: Error: Failed to load java.lang.CharSequence"错误
针对下面的冒泡排序的BubbleSort.java程序
public class BubbleSort{
public static void bubbleSort(int[] arr) {
if (arr == null || arr.length == 1) return;
for (int i = 0; i <arr.length - 1; i++) {
boolean isSorted = true;
for (int j = 0; j <arr.length - 1 - i; j++) {
if (arr[j] >arr[j + 1]) {
int temp = arr[j];
arr[j] = arr[j + 1];
arr[j + 1] = temp;
isSorted = false;
}
}
if (isSorted) return;
System.out.print("第"+ (i+1) + "趟:");
print(arr);
}
}
public static void main(String[] args) {
int[] arr = {6, 9, 1, 4, 5, 8, 7, 0, 2, 3};
System.out.print("排序前:");
print(arr);
bubbleSort(arr);
System.out.print("排序后:");
print(arr);
}
public static void print(int[] arr) {
if (arr == null) return;
for(int i : arr) {
System.out.print(i + " " );
}
System.out.println();
}
}
由于soot是支持输入.java文件的,在linux环境中使用soot处理BubbleSort.java时,却发现报告以下错误
此外,soot是支持输入.class文件。于是,想把BubbleSort.java编译为BubbleSort.class,却发现发生以下错误。
故猜测soot处理错误可以与system.out.prin()有关。
于是将BubbleSort.java程序中的system.out.prin()的输出均改为英文,如下所示。
public class BubbleSort_new{
public static void bubbleSort(int[] arr) {
if (arr == null || arr.length == 1) return;
for (int i = 0; i <arr.length - 1; i++) {
boolean isSorted = true;
for (int j = 0; j <arr.length - 1 - i; j++) {
if (arr[j] >arr[j + 1]) {
int temp = arr[j];
arr[j] = arr[j + 1];
arr[j + 1] = temp;
isSorted = false;
}
}
if (isSorted) return;
System.out.print("sorted time:"+(i+1) );##更改一
print(arr);
}
}
public static void main(String[] args) {
int[] arr = {6, 9, 1, 4, 5, 8, 7, 0, 2, 3};
System.out.print("random array:" ); ##更改二
print(arr);
bubbleSort(arr);
System.out.print("sorted array:" ); ##更改三
print(arr);
}
public static void print(int[] arr) {
if (arr == null) return;
for(int i : arr) {
System.out.print(i + " " );
}
System.out.println();
}
}
soot输入更改后的BubbleSort_new.java,发现仍然报下述错误
然而将BubbleSort_new.java编译为BubbleSort_new.class后,发现未报错。
现在整理相关问题
.java 文件 | .class文件 | |
---|---|---|
System.out.print输出包含中文 | 出错 | 出错 |
System.out.print输出不包含中文 | 出错 | 成功 |
目前只能解决.class文件出现"Exception in thread “main” java.lang.Error: Error: Failed to load java.lang.CharSequence"这种错误。
而.java文件为何出错则可能和jdk版本有关,但博主尚未验证。