私は教科書からこのコードを実行します。どのように私はこの問題を解決するか、エラーが何を意味しこれは教科書のサンプルコードです。それはコンパイルされません
/**
A test of the methods add, toArray, and isFull, as defined
in the first draft of the class ArrayBag.
@author Frank M. Carrano
*/
public class ArrayBagDemo1
{
public static void main(String[] args)
{
// a bag that is not full
BagInterface<String> aBag = new ArrayBag<String>();
// tests on an empty bag
testIsFull(aBag, false);
// adding strings
String[] contentsOfBag1 = {"A", "A", "B", "A", "C", "A"};
testAdd(aBag, contentsOfBag1);
testIsFull(aBag, false);
// a bag that will be full
aBag = new ArrayBag<String>(7);
System.out.println("\nA new empty bag:");
// tests on an empty bag
testIsFull(aBag, false);
// adding strings
String[] contentsOfBag2 = {"A", "B", "A", "C", "B", "C", "D"};
testAdd(aBag, contentsOfBag2);
testIsFull(aBag, true);
} // end main
// Tests the method add.
private static void testAdd(BagInterface<String> aBag, String[] content)
{
System.out.print("Adding to the bag: ");
for (int index = 0; index < content.length; index++)
{
aBag.add(content[index]);
System.out.print(content[index] + " ");
} // end for
System.out.println();
displayBag(aBag);
} // end testAdd
// Tests the method isFull.
// correctResult indicates what isFull should return.
private static void testIsFull(BagInterface<String> aBag,boolean correctResult)
{
System.out.print("\nTesting the method isFull with ");
if (correctResult)
System.out.println("a full bag:");
else
System.out.println("a bag that is not full:");
System.out.print("isFull finds the bag ");
if (correctResult && aBag.isFull())
System.out.println("full: OK.");
else if (correctResult)
System.out.println("not full, but it is full: ERROR.");
else if (!correctResult && aBag.isFull())
System.out.println("full, but it is not full: ERROR.");
else
System.out.println("not full: OK.");
} // end testIsFull
// Tests the method toArray while displaying the bag.
private static void displayBag(BagInterface<String> aBag)
{
System.out.println("The bag contains the following string(s):");
Object[] bagArray = aBag.toArray();
for (int index = 0; index < bagArray.length; index++)
{
System.out.print(bagArray[index] + " ");
} // end for
System.out.println();
} // end displayBag
} // end ArrayBagDemo1
:ここ
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
BagInterface cannot be resolved to a type
ArrayBag cannot be resolved to a type
ArrayBag cannot be resolved to a type
at ArrayBagDemo1.main(ArrayBagDemo1.java:12)
コードにコンパイルされていないされています。私は次のエラーを取得しますか?
コードは、ArrayBagクラスの最初の草稿で と定義されているadd、toArray、およびisFullのメソッドのテストです。
「BagInterface」はどこから来たのですか? 'ArrayBag'を含んでいないようにも見えます –
あなたはクラスがない必要があります。それらを投稿に含めてください。 – Ajay
[本当に](https://xkcd.com/1742/)..冗談はさておき、クラスの部分だけでなくファイル全体の内容も含めてください。 'BagInterface'と' ArrayBag'について知る必要があります。可能であれば、コードも提供してください。また、['型に解決できない]に関するいくつかの答えがあります(http://stackoverflow.com/questions/5125107/java-class-cannot-be-resolved-to-a-type)。 –