昨天它工作正常,但是现在Eclipse中的“表达式”窗格在调试时不会显示任何有用的信息,但会给出照片中显示的错误。我四处寻找答案,但找不到任何有用的东西。有谁知道如何解决这一问题?我尝试调试一个不同的程序,然后它工作,所以它必须与我的代码(?)有关。
详细说明:
我的代码:
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
public class Driver {
private List<Integer>[] duplicateLists = new ArrayList[5];
private List<Integer>[] lists = new ArrayList[5];
private final int NUM_ALGORITHMS = 5;
private boolean flag = false; //testing only
private int calls = 0; // testing only
public static void main(String[] args) {
new Driver().run();
}
private void run() {
printHeaders();
createLists();
for (int i = 0; i < NUM_ALGORITHMS; ++i) {
resetDuplicates();
switch (i) {
case 0:
System.out.print("| | In order |");
System.out.println(selectionSort(duplicateLists[0]));
System.out.println("| |---------------+---------------+---------------+---------------+");
System.out.print("| | Reverse Order |");
System.out.println(selectionSort(duplicateLists[1]));
System.out.println("| |---------------+---------------+---------------+---------------+");
System.out.print("| SELECTION | Random 1 |");
System.out.println(selectionSort(duplicateLists[2]));
System.out.println("| |---------------+---------------+---------------+---------------+");
System.out.print("| | Random 2 |");
System.out.println(selectionSort(duplicateLists[3]));
System.out.println("| |---------------+---------------+---------------+---------------+");
System.out.print("| | Partial Order |");
System.out.println(selectionSort(duplicateLists[4]));
System.out.println("+===============+===============+===============+===============+===============+");
break;
case 1:
System.out.print("| | In order |");
System.out.println(insertionSort(duplicateLists[0]));
System.out.println("| |---------------+---------------+---------------+---------------+");
System.out.print("| | Reverse Order |");
System.out.println(insertionSort(duplicateLists[1]));
System.out.println("| |---------------+---------------+---------------+---------------+");
System.out.print("| INSERTION | Random 1 |");
System.out.println(insertionSort(duplicateLists[2]));
System.out.println("| |---------------+---------------+---------------+---------------+");
System.out.print("| | Random 2 |");
System.out.println(insertionSort(duplicateLists[3]));
System.out.println("| |---------------+---------------+---------------+---------------+");
System.out.print("| | Partial Order |");
System.out.println(insertionSort(duplicateLists[4]));
System.out.println("+===============+===============+===============+===============+===============+");
break;
case 2:
System.out.print("| | In order |");
System.out.println(bubbleSort(duplicateLists[0]));
System.out.println("| |---------------+---------------+---------------+---------------+");
System.out.print("| | Reverse Order |");
System.out.println(bubbleSort(duplicateLists[1]));
System.out.println("| |---------------+---------------+---------------+---------------+");
System.out.print("| BUBBLE | Random 1 |");
System.out.println(bubbleSort(duplicateLists[2]));
System.out.println("| |---------------+---------------+---------------+---------------+");
System.out.print("| | Random 2 |");
System.out.println(bubbleSort(duplicateLists[3]));
System.out.println("| |---------------+---------------+---------------+---------------+");
System.out.print("| | Partial Order |");
System.out.println(bubbleSort(duplicateLists[4]));
System.out.println("+===============+===============+===============+===============+===============+");
break;
case 3:
System.out.print("| | In order |");
System.out.println(mergeSort(duplicateLists[0]));
System.out.println("| |---------------+---------------+---------------+---------------+");
System.out.print("| | Reverse Order |");
System.out.println(mergeSort(duplicateLists[1]));
System.out.println("| |---------------+---------------+---------------+---------------+");
System.out.print("| MERGE | Random 1 |");
flag = true;
System.out.println(mergeSort(duplicateLists[2]));
flag = false;
System.out.println("| |---------------+---------------+---------------+---------------+");
System.out.print("| | Random 2 |");
System.out.println(mergeSort(duplicateLists[3]));
System.out.println("| |---------------+---------------+---------------+---------------+");
System.out.print("| | Partial Order |");
System.out.println(mergeSort(duplicateLists[4]));
System.out.println("+===============+===============+===============+===============+===============+");
break;
case 4:
System.out.print("| | In order |");
System.out.println(quicksort(duplicateLists[0]));
System.out.println("| |---------------+---------------+---------------+---------------+");
System.out.print("| | Reverse Order |");
System.out.println(quicksort(duplicateLists[1]));
System.out.println("| |---------------+---------------+---------------+---------------+");
System.out.print("| QUICKSORT | Random 1 |");
System.out.println(quicksort(duplicateLists[2]));
System.out.println("| |---------------+---------------+---------------+---------------+");
System.out.print("| | Random 2 |");
System.out.println(quicksort(duplicateLists[3]));
System.out.println("| |---------------+---------------+---------------+---------------+");
System.out.print("| | Partial Order |");
System.out.println(quicksort(duplicateLists[4]));
System.out.println("+===============+===============+===============+===============+===============+");
break;
}
}
System.out.println("CALLS: " + calls); //testing only
}
private ArrayList<Integer> createList(String path) {
ArrayList<Integer> list = new ArrayList<Integer>();
BufferedReader rd;
try {
rd = new BufferedReader(new FileReader(path));
String line;
while ((line = rd.readLine()) != null) {
list.add(new Integer(Integer.parseInt(line)));
}
rd.close();
} catch (IOException e) {
e.printStackTrace();
} catch (NumberFormatException e) {
}
return list;
}
private <T extends Comparable<? super T>> Data selectionSort(List<T> l) {
int compares = 0;
int swaps = 0;
double time = System.nanoTime();
for (int i = 0; i < l.size()-1; ++i) {
int minIndex = i;
for (int j = i+1; j < l.size(); ++j) {
if (l.get(j).compareTo(l.get(minIndex)) < 0) {
minIndex = j;
}
++compares;
}
if (minIndex != i) {
swap(l, minIndex, i);
++swaps;
}
}
time = (System.nanoTime() - time)/Math.pow(10, 9); // convert to seconds
return new Data(l, time, compares, swaps, "Selection");
} // method selectionSort
private <T extends Comparable<? super T>> Data insertionSort(List<T> l) {
int compares = 0;
int swaps = 0;
double time = System.nanoTime();
for (int i = 1; i < l.size(); ++i) {
for (int j = i; j > 0 && l.get(j-1).compareTo(l.get(j)) > 0; --j) {
++compares; // once during every loop
swap(l, j, j-1);
++swaps;
}
++compares; // one to correspond to final check
}
time = (System.nanoTime() - time)/Math.pow(10, 9); // convert to seconds
return new Data(l, time, compares, swaps, "Insertion");
} // method insertionSort
private <T extends Comparable<? super T>> Data bubbleSort(List<T> l) {
int compares = 0;
int swaps = 0;
double time = System.nanoTime();
int finalIndex = l.size()-1;
int swapIndex;
while (finalIndex > 0) {
swapIndex = 0;
for (int i = 0; i < finalIndex; ++i) {
if (((T)l.get(i)).compareTo(l.get(i+1)) > 0) { // if l[i] > l[i+1]
swap(l, i, i+1);
swapIndex = i;
++swaps;
}
++compares;
}
finalIndex = swapIndex;
}
time = (System.nanoTime() - time)/Math.pow(10, 9); // convert to seconds
return new Data(l, time, compares, swaps, "Bubble");
} // method bubbleSort
private <T extends Comparable<? super T>> Data mergeSort(List<T> l) {
double time = System.nanoTime();
List<T> aux = (List<T>) ((ArrayList) l).clone();
int compares = mergeSort(aux, l, 0, l.size());
time = (System.nanoTime() - time)/Math.pow(10, 9); // convert to seconds
return new Data(l, time, compares, 0, "Merge");
} // method mergeSort 1 param
private <T extends Comparable<? super T>> int mergeSort(List<T> src, List<T> dest, int low, int high) {
if (flag) {
calls++; // testing only
System.out.println("PRE SRC: " + src);
System.out.println("PRE DEST: " + dest);
}
int compares = 0;
int mid = (low + high) >> 1;
if (high - low == 1) {
} else {
mergeSort(dest, src, 0, mid);
mergeSort(dest, src, mid, high);
}
for (int i = low, p = low, q = mid; i < high; ++i) {
if (q >= high) {
dest.set(i, src.get(p++));
} else if (p >= mid){
dest.set(i, src.get(q++));
} else {
if (((T)src.get(p)).compareTo(src.get(q)) <= 0) {
dest.set(i, src.get(p++));
} else {
dest.set(i, src.get(q++));
}
++compares;
}
}
if (flag) {
System.out.println("POST SRC: " + src);
System.out.println("POST DEST: " + dest);
}
return compares;
} // method mergeSort 4 params
private <T extends Comparable<? super T>> Data quicksort(List<T> l) {
return null;
} // method quicksort
private <T> void swap(List<T> l, int index1, int index2) {
T temp = l.get(index1);
l.set(index1, l.get(index2));
l.set(index2, temp);
} // method swap
private void printHeaders() {
System.out.println("+===============+===============+===============+===============+===============+\n" +
"| | | TIME | NUMBER | NUMBER |\n" +
"| SORT METHOD | WHICH ARRAY | TO | OF | OF |\n" +
"| | | COMPLETE | COMPARES | SWAPS |\n" +
"+===============+===============+===============+===============+===============+" );
}
private void createLists() {
lists[0] = createList("C:\\Users\\Jason\\Documents\\School\\College\\Individual Studies\\202Projects\\07\\order.txt");
lists[1] = createList("C:\\Users\\Jason\\Documents\\School\\College\\Individual Studies\\202Projects\\07\\reverse.txt");
lists[2] = createList("C:\\Users\\Jason\\Documents\\School\\College\\Individual Studies\\202Projects\\07\\random1.txt");
lists[3] = createList("C:\\Users\\Jason\\Documents\\School\\College\\Individual Studies\\202Projects\\07\\random2.txt");
lists[4] = createList("C:\\Users\\Jason\\Documents\\School\\College\\Individual Studies\\202Projects\\07\\partial.txt");
}
private void resetDuplicates() {
for (int i = 0; i < duplicateLists.length; i++) {
if (duplicateLists[i] != null) {
duplicateLists[i].clear();
} else {
duplicateLists[i] = new ArrayList<Integer>();
}
for (int j = 0; j < lists[i].size(); j++) {
duplicateLists[i].add(new Integer(lists[i].get(j)));
}
}
}
}
数据类:
import java.util.List;
public class Data {
private List list;
private double time;
private int compares;
private int swaps;
private String name;
public Data(List list, double time, int compares, int swaps, String name) {
this.list = list;
this.time = time;
this.compares = compares;
this.swaps = swaps;
this.name = name;
}
public List getList() {
return list;
}
public double getTime() {
return time;
}
public int getCompares() {
return compares;
}
public int getSwaps() {
return swaps;
}
public String getName() {
return name;
}
public String toString() {
String timeString = String.format("%-14.4f", time);
String compareString = String.format("%-14d", compares);
String swapString = String.format("%-14d", swaps);
return " " + timeString + "| " + compareString + "| " + swapString + "| " + list;
}
}
答案 0 :(得分:0)
这不是因为你的java代码。 “表达式”选项卡将显示变量的值。
但是调试指针位于类的第一行,现在甚至不存在这样的变量。
继续调试,一旦你越过创建变量的代码行,你就可以在表达式viewm中看到那里的值