2011-06-22 12 views
-2

このコードはコンパイルしたくないようです。私はJavaプログラミングにとってまったく新しいものです。どんな助けでも大歓迎です。エラーは、それがシンボルを見つけることができないと言います。クラスアドレス帳 場所:addressbookexample1.AddressBookExample1.mainこのコードをコンパイルすることはできません。

におけるクラスaddressbookexample1.AddressBookExample1 シンボルシンボルを見つけることができません - 互換性のないソースコード:スレッドでコンパイラエラー 例外 "メイン" java.lang.RuntimeExceptionは

package addressbookexample1; 

import java.io.*; 
import java.util.Scanner; 

public class AddressBookExample1 { 

    private Contact[] friends; 
    private int numfriends; 

    // Create an empty AddressBook 
    public AddressBookExample1() { 
     friends = new Contact[10]; 
     numfriends = 0; 
    } 

    // Add a contact that's passed in as a parameter. 
    public void addContact(Contact c) { 
     friends[numfriends] = c; 
     numfriends++; 
    } 

    // Print out info on all contacts using method Contact class. 
    public void printContacts() { 
     for (int i = 0; i < numfriends; i++) { 
      friends[i].printContact(); 
     } 
    } 

    // Returns the number of friends currently in AddressBook 
    public int numContacts() { 
     return numfriends; 
    } 


    private int haveContact(String s) { 

     for (int i = 0; i < numfriends; i++) { 
      if (friends[i].getName().equals(s)) { 
       return i; 
      } 
     } 
     return -1; 
    } 

    // Deletes a contact with name 
    public void deleteContact(String s) { 

     int place = haveContact(s); 
     if (place >= 0) { 
      friends[place] = friends[numfriends - 1]; 
      numfriends--; 
     } 
    } 


    public static void main(String[] args) throws IOException { 

     Scanner stdin = new Scanner(System.in); 

     // Instantiate AddressBook object 
     AddressBook blackbook = new AddressBook(); 

     // Menu driven loop. 
     menu(); 
     int choice = stdin.nextInt(); 

     while (choice != 5) { 


      if (choice == 1) { 

       if (blackbook.numContacts() < 10) { 

        //Reads in all appropriate information."); 
        System.out.println("Enter your friend\'s name:"); 
        String name = stdin.next(); 
        System.out.println("Enter their age."); 
        int age = stdin.nextInt(); 
        System.out.println("Enter their phone number."); 
        int number = stdin.nextInt(); 
        System.out.println("Enter the birthday, month on one line, then day on the next."); 
        int mon = stdin.nextInt(); 
        int day = stdin.nextInt(); 


        blackbook.addContact(new Contact(name, age, number, mon, day)); 
       } else { 
        System.out.println("Sorry, can not add anyone, your blackbook is full."); 
       } 
      } 
      else if (choice == 2) { 
       System.out.println("What is the name of the contact you want to delete?"); 
       String name = stdin.next(); 
       blackbook.deleteContact(name); 
      } else if (choice == 3) { 
       System.out.println("You have " + blackbook.numContacts() + " contacts."); 
      } else if (choice == 4) { 
       blackbook.printContacts(); 
      } else if (choice != 5) { 
       System.out.println("Sorry, that was an invalid menu choice, try again."); 
      } 

      menu(); 
      choice = stdin.nextInt(); 
     } 

    } 

    public static void menu() { 
     System.out.println("1.Add a new contact to your address book."); 
     System.out.println("2.Delete a contact from your address book."); 
     System.out.println("3.Print out the number of contacts you have."); 
     System.out.println("4.Print out information of all of your contacts."); 
     System.out.println("5.Quit."); 
     System.out.println("Enter your menu choice:"); 
    } 
} 

+0

正確なエラーメッセージをコピー/貼り付けてください。行番号とエラーコードは、問題の診断に非常に役立ちます。 – BraedenP

+0

そして、何がエラーですか? – Marcin

+0

コンパイルエラーをコピーできますか? –

答えて

0

Contactクラスが見つからないようです。私はこれも例の一部であると仮定し、ビルドにソースを含める必要があります。

+0

でaddressbookexample1.AddressBookExample1 \t見つけ出す。どのようにそれを定義するのですか?本当にありがとう! – PittsburghCoder

+0

サンプルコードのどこか他の場所でContact.javaを探します。または新しいものを書いてください。 :) –

0

連絡先クラスを定義していません

+0

これは私が把握しようとしている単なる例です。どのようにそれを定義するのですか?本当にありがとう! – PittsburghCoder

0

コードを見ると、連絡先が利用できない可能性があります。 Contact.javaとこのクラスを同時にコンパイルしてみてください。

2

これをAddressBookExample1として定義しましたが、AddressBookのインスタンス化を試みています。

// Instantiate AddressBook object 
AddressBook blackbook = new AddressBook(); 

AddressBookExample1 blackbook = new AddressBookExample1(); 
0

に変更しますが、クラスのアドレス帳を使用しようとしているが、あなたはAddressBookExample1を定義しています。

0

これが例の場合、「Contact」と「Addressbook」クラスを定義するサンプルがどこにあるかという別のコードがあるはずです。サンプルコードを正確に入力してください。 AddressBookExample1にAddressBookクラスの名前を変更したのでしょうか?