-1
私のデータ構造体クラスは、独自のデータ構造体をSkipListの形で実装しようとしています。私が取り組んでいるメソッドはsubListです。私はほとんどのエラーを処理しましたが、私のエラーtestSubList()
メソッドに例外がスローされていると言ってきました。私は入力変数ですべてのエラーをカバーしていると信じているので、これが何であるか分かりません。他のすべてのメソッドが動作していると仮定すると、このエラーの原因は何ですか?メソッドで例外を見つける方法はありますか?
public List<E> subList(int fromIndex, int toIndex)
{
//subList method written by Ryan Schubert
//if a trivial case where the index is out of bounds occurs throw exception
if (fromIndex < 0 || toIndex > this.size() || toIndex < fromIndex){
throw new IndexOutOfBoundsException();
}
//make new skiplist to add values to
List<E> sub = new SkipList<E>();
//run through the skiplist between the indices and add the values to sub
for(int i = fromIndex; i<toIndex; i++)
{
sub.add(this.get(i));
}
return sub;
}
public static boolean testSubList()
{
//testSubList method written by Ryan Schubert
//make a new list and add a bunch of values to it
List<String> testList = new SkipList<String>();
testList.add("test1");
testList.add("test2");
testList.add("test3");
testList.add("test4");
testList.add("test5");
testList.add("test6");
//make a new list and fill it with sub list values
List<String> testSubList = new SkipList<String>();
testSubList = testList.subList(1, 4);
//compare the test list to the sublist
if (testList.containsAll(testSubList))
{
System.out.println("true");
return true;
}
else
{
System.out.println("false");
return false;
}
}
通常、スタックトレースはかなり冗長です。これには、例外が発生する正確な行と、例外のタイプと、メッセージ(使用可能な場合)が含まれます。必要な情報がスタックトレースに存在する必要があるため、質問を明確にしてください。 – Turing85
例外のスタックトレースを単にポストするのはなぜですか? –