Javaのimportエラー対処方法とは?

このQ&Aのポイント
  • Javaで「import chn.util.*;」がエラーになる場合の対処方法を教えてください。
  • エラーメッセージ「ConsoleIO を型に解決できません」「インポートされた chn は見つかりません」と表示されます。
  • 環境は日本語版のEclipse 3.5 Heliosです。
回答を見る
  • ベストアンサー

Javaでipmportエラーになります

以下の様なJavaのサンプルをコンパイルしたいのですが 「import chn.util.*;」がエラーになりConsoleIOクラスを利用できません。 エラーメッセージはつぎのとおりです。 ・ConsoleIO を型に解決できません ・インポートされた chn は見つかりません 環境は日本語版のEclipse 3.5 Heliosです。 このエラーの解決方法をご教示ください。 よろしくお願いいたします。 ************************************** import chn.util.*; public class samp03 { public static void main(String[] args) { ConsoleIO keyboard = new ConsoleIO( ); String word1, word2, anotherLine; char char1, char2; // ask for input from the keyboard System.out.print("Enter a line: "); // grab the first "word" word1 = keyboard.readToken(); // grab the second "word" word2 = keyboard.readToken(); // ask for input from the keyboard System.out.print("Enter another line: "); // discard any remaining input from previous line // and read the next line of input anotherLine = keyboard.readLine(); // output the strings System.out.println("word1 = " + word1); System.out.println("word2 = " + word2); System.out.println("anotherLine = " + anotherLine); char1 = anotherLine.charAt(0); char2 = anotherLine.charAt(1); System.out.println("char1 = " + char1); System.out.println("char2 = " + char2); } }

  • Java
  • 回答数2
  • ありがとう数2

質問者が選んだベストアンサー

  • ベストアンサー
  • kmee
  • ベストアンサー率55% (1857/3366)
回答No.2

> import chn.util.*; 標準のJavaには chn.utilは無いはずで、別途、インストールが必要です。 そのサンプルがあったところ/載ってた本に導入方法とか説明はありませんか?

moanakai777
質問者

お礼

特に書いてないので困っています。 回答ありがとうございます。

moanakai777
質問者

補足

Webで検索したらダウンロードサイトがありました。 解決いたしました。 ありがとうございました。

その他の回答 (1)

  • wormhole
  • ベストアンサー率28% (1621/5657)
回答No.1

本か何かのサンプルだと思いますが、そのサンプルを動かすための設定内容がどこかに書かれていると思いますので、それを探して読んでください。

moanakai777
質問者

お礼

回答ありがとうございます。 確認してみます。

関連するQ&A

  • javaについて

    以下のようにキーボードから入力していくプログラムを試行しているのですが、エラーが出てくるので行き詰まっています。 理想的にはキーボードに”あいう”エンター”えおか”エンターと打ち込んだら str[0]=あいう str[1]=えおか と表示させていきたいのですが、よろしくお願いします。 import java.io.*; import java.lang.*; import java.net.*; import java.awt.*; class gugu2 { public static void main(String[] args) throws IOException { int i=0; while(i<2){ System.out.println("キーワード入力"); BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String input = br.readLine(); char str[] = input.toCharArray(); System.out.println("キーワードは" + str[]); i=i+1; } for(i=0;i<2;i++){ System.out.println(str[]); } } } これがエラー表示です。 gugu2.java:17: '.class' がありません。 System.out.println("キーワードは" + str[]); ^ gugu2.java:21: '.class' がありません。 System.out.println(str[]); ^ エラー 2 個

    • ベストアンサー
    • Java
  • Javaでクイズ作成途中もエラー

    あの、以前こちらで質問した者です。→http://okwave.jp/qa/q6482901.html 今、英単語が表示され日本語でそれを答えるクイズを作ろうとしています。 まだまだ作りかけですが、どうしてもコンパイル時にエラーになってしまいます。 どこから直せば良さそうですか?自己研究ということで周りに質問する人がいません。 すみませんがヒントを頂けたらと質問しました。よろしくお願いします。 import java.io.*; public class EnglishToJapaneseQuiz { public int MAX_QUESTION = 5; public int GOODANSWER = 0; public static void main(String[] args) { BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); try { System.out.println("Welcome! This quiz helps you study Japanese in English"); System.out.println("'n' normal"); System.out.println("'h' hard"); System.out.println("'e' expert"); System.out.println("'z' exit"); System.out.println("Please select the level"); String line = reader.readLine(); char c = line.charAt(0); switch (c) { case 'n': System.out.println("You selected normal"); for (int i=0; i<MAX_QUESTION; i++) { int x = (int)(Math.random() * 10) + 1; switch (x) { case 1: System.out.println("School"); String Answer = "学校"; BufferedReader responce = new BufferedReader(new InputStreamReader(System.in)); String line = responce.readLine(); If (line.equals(Answer)) { System.out.println("correct"); GOODANSWER = GOODANSWER + 1; } else { System.out.println("incorrect"); } break; case 2: case 3: case 4: case 5: case 6: case 7: case 8: case 9: case 10: } } break; case 'h': System.out.println("You selected hard"); break; case 'e': System.out.println("You selected expert"); break; case 'z': break; default: System.out.println("you must indicate valid character"); break; } } catch (IOException e) { System.out.println(e); System.out.println("invalid value"); } System.out.println("the program was successfully ended"); } }

    • ベストアンサー
    • Java
  • javaのエラーについて質問

    毎度、お世話になります。 下記のコードに於いて、コメント箇所でエラー(UnsupportedOperationException())が発生します。 Q1)このエラーの原因と、改良をご教授ください。 ============================= import java.nio.ByteBuffer; import java.nio.ByteOrder; import java.nio.IntBuffer; import java.util.Date; import java.util.Random; public class Main { public static void main(String[] args) { Random random = new Random(); random.setSeed((int) new Date().getTime()); ByteBuffer byteBuffer = ByteBuffer.allocate(10000 * 4); long start = System.currentTimeMillis(); ByteOrder order; ByteBuffer tmpBuffer; int[] ints; IntBuffer intBuffer; long end; // ビックエンディアン order = ByteOrder.BIG_ENDIAN; tmpBuffer = byteBuffer.order(order); ints = tmpBuffer.asIntBuffer().array(); //エラー発生:UnsupportedOperationException() intBuffer = IntBuffer.wrap(ints); System.out.println("ビックエンディアンで実行"); printChunk(random, ints, intBuffer); end = System.currentTimeMillis(); System.out.print("経過時間:"); System.out.println((end - start) + "msec\t"); // リトルエンディアン start = System.currentTimeMillis(); order = ByteOrder.LITTLE_ENDIAN; tmpBuffer = byteBuffer.order(order); ints = tmpBuffer.asIntBuffer().array(); //エラー発生:UnsupportedOperationException() intBuffer = IntBuffer.wrap(ints); System.out.println("リトルエンディアンで実行"); printChunk(random, ints, intBuffer); end = System.currentTimeMillis(); System.out.print("経過時間:"); System.out.println((end - start) + "msec\t"); } ========================================= 以上

    • ベストアンサー
    • Java
  • java.util.Dateについて

    まずは下記ソースを参照してください。 import java.util.Date; import java.util.GregorianCalendar; import java.util.Calendar; public class Test{     public static void main( String args[] ){         GregorianCalendar cal = new GregorianCalendar(2004, 5, 31);         System.out.println("年:" + cal.get(Calendar.YEAR));         System.out.println("月:" + cal.get(Calendar.MONTH));         System.out.println("日:" + cal.get(Calendar.DAY_OF_MONTH));         System.out.println(); // ただの改行         System.out.println("比較:" + new Date().compareTo(cal.getTime()));     } } 上記ソースについて質問です。 1.「年」「月」「日」を表示しておりますが、本来ならば 「年:2004」 「月:5」 「日:31」 と表示されると思っておりましたが実際は、 「年:2004」 「月:6」 「日:1」 と表示されてしまいます。 なぜでしょうか? 2.12行目にてjava.util.DateクラスのcompareToメソッドを用いて、 現在日付(2004/5/28)と7行目で指定している日付の比較をしていますが、 7行目で設定している日付を現在日付よりも前後に設定して実行させても、 「-1」しか返りません。 なぜでしょうか? 環境は、 J2SDK:1.4.2 OS:Windows XP Pro です。

    • ベストアンサー
    • Java
  • java プログラミング

    以下のプログラムを改良したいのですがどの用に書き換えればいいかわからないので皆さんの力を貸してください。 1.最後に表示されるメールアドレスの後には;を表示しない。 2.コンマやセミコロンなどで区切られているメールアドレスも認識する(現段階では二つのアドレスの間にスペースがないと認識できません)aaa@bbb.ccc,AAA@BBB.CCC;AaA@BbB.CcCを認識する。 3. メルアドレスだけが一列ごとに並んでいるものを認識する。 aaa@bbb ccc@ddd eee@fffなどです。 メールアドレスの検出の仕方として@から前後にスペースがあるまでループするようにしてあるので上記の場合うまく働きません。以上の三点をみたすように改良するのに必要なコードブロックを教えてください。 プログラミング初心者なのでなるべく簡単に説明していただけると幸いです。 import java.io.BufferedReader; import java.io.FileReader; import java.io.FileWriter; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.ArrayList; import java.util.List; public class Email { @SuppressWarnings("unchecked") public static void main(String[] argv) throws Exception { String input = "fileContainingEmails.txt"; String output = "copyPasteMyEmails.txt"; BufferedReader cin; cin = new BufferedReader(new InputStreamReader(System.in)); String userInput; System.out.println("Enter input file name [default name: " + input + " ]"); userInput = cin.readLine(); if (userInput.equals("")) userInput = input; String name; if (userInput.equals(input)) name = output; else name = userInput; String userOutput; System.out.println("Enter output file name [default name: " + name + " ]"); userOutput = cin.readLine(); if (userOutput.equals("")) userOutput = name; System.out.println("Input FIle : " + userInput); System.out.println("Output FIle : " + userOutput); BufferedReader fin; fin = new BufferedReader(new FileReader(userInput)); PrintWriter fout; fout = new PrintWriter(new FileWriter(userOutput, true)); String lineFromFile = ""; List listOfMail = new ArrayList(); int indexOfAt = 0; int s = 0,e = 0; while (fin.ready()) { lineFromFile = fin.readLine(); indexOfAt = lineFromFile.indexOf('@',indexOfAt); while(indexOfAt > 0) { for(int i = 0;lineFromFile.charAt(indexOfAt - i) != ' ';i++) s = indexOfAt - i; for(int i = 0;lineFromFile.charAt(indexOfAt + i) != ' ';i++) e = indexOfAt + i; if(listOfMail.indexOf(lineFromFile.substring(s,e).toLowerCase()) < 0) { listOfMail.add(lineFromFile.substring(s,e).toLowerCase()); fout.println(lineFromFile.substring(s,e).toLowerCase()); System.out.print(lineFromFile.substring(s,e)); System.out.println(";"); } indexOfAt = lineFromFile.indexOf('@',indexOfAt + 1); } } fin.close(); fout.close(); System.out.println(); int count = 0; count = listOfMail.size(); if (count == 0) System.out.println("Sorry, no email addresses were found in the file " + userInput); else System.out.println(count + " email addresses were found, and copied to " + userOutput); System.out.println("Open " + userOutput + " and copy and paste those e-mail addresses into the to, cc, or bcc field."); System.out.println("Pasting into bcc field is the best way because everyone's email address does not appear in the message."); } }

  • JAVAの初心者です.

    import java.io.*; class Sample3 { public static void main(String args[])throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int meny; int max = 0; int kingaku[]; kingaku = new int[5]; char ss[][]; ss = new char[5][80]; do{ String hako = br.readLine(); meny = Integer.parseInt(hako); System.out.println("1:入力とその長さ"); System.out.println("2:データ入力"); System.out.println("3:データ表示"); System.out.println("4:おしまい"); switch(meny){ case 1: System.out.println("文字を入力してください。"); String input = br.readLine(); System.out.println(input + "は" + input.length + "文字です。"); break; case 2: if (max == 0){ System.out.printin("登録をしてからお選びください。"); }else{ System.out.println("名前を入力してください。"); String ss[max] = br.readLine(); System.out.println("金額を入力してください。"); String kingaku[max] = br.readLine(); System.out.println(ss[max] + "さんで" + kingaku[max] + "を登録します。"); max++; } break; case 3: System.out.println("現在登録人数は" + max + "人です。"); for(int aa = 0;aa<max;aa++){ System.out.println(name[max] + kingaku[max]); } break; } }while(meny != 4); } } 上記のソースなのですが、コンパイルで今のところ2つエラーが出てしまうのです。 String ss[max] = br.readLine(); String kingaku[max] = br.readLine(); の所がエラーと表示されます。 javaは入力した文字を表示するだけでしたら    = Integer.paruseint()する必要ないですよね?? 初心者ならではの質問でごめんなさい。 ご教授宜しくお願いいたします。

    • ベストアンサー
    • Java
  • charAt(0)について

    import java.io.*; class Sample3 { public static void main(String[] args) throws IOException { System.out.println("文字列を入力してください。"); BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String str1 = br.readLine(); System.out.println("検索文字を入力してください。"); String str2 = br.readLine(); char ch = str2.charAt(0); int num = str1.indexOf(ch); if(num != -1) System.out.println(str1 + "の" + (num+1) + "番目に「" + ch + "」が見つかりました。"); else System.out.println(str1 + "に「" + ch + "」はありません。"); } char ch = str2.charAt(0);の部分ですが、 charAt(0)というのは ( )に書かれている番号「のみ」を参照するんですよね? だからもし「こ」んちにはと入力しても0番目の「こ」しか出さないはずなのに、 「に」 を入れたらちゃんと「3番目に に が見つかりました」と出るのはなぜですか?

    • ベストアンサー
    • Java
  • javaの超初心者です。ご教授いただけたら幸いです。

    javaの超初心者です。ご教授いただけたら幸いです。 ある書籍を元にやっているのですが、演習に答えがなく、わからないためその問題をお願い致します。 2桁の整数値(10~99)を当てさせる数当てゲームを作成せよ。という問題です。 下記は少しやってみました。 import java.util.Random; import java.util.Scanner; class Kazuate99 { public static void main(String[] args) { Random rand = new Random(); Scanner stdIn = new Scanner(System.in);    int no = rand.nextInt(); ← ここがたぶん違う System.out.println("数当てゲーム開始!!"); System.out.println("10~99の数を当てて下さい。"); int x; // プレーヤが入力した数 do { System.out.print("いくつかな : "); x = stdIn.nextInt(); if (x > no) System.out.println("もっと小さな数だよ。"); else if (x < no) System.out.println("もっと大きな数だよ。"); } while (x != no ); System.out.println("正解です。"); } } 宜しくお願い致します。

    • ベストアンサー
    • Java
  • 至急!java オブジェクト指向

    昨日、質問させていただいた者です。おかげさまで、試合の状況を出力するプログラムが完成しました。あとはこれをオブジェクト指向のプログラムにしたいので、BSO()、Runner()、Score()のメソッド等を別々のクラスに記述して動作させるようにしたのですが、エラーばかりで起動できませんでした。インターフェースや継承などを使っていただいて構わないので、できれば改良のほうをお願いします。 import java.io.*; public class test1 { public static void main(String[] args) throws IOException{ BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); int sc=0,bc=0,oc=0,rc1=0,rc2=0,rc3=0,tenA=0,tenB=0,i=0; BSO(sc, bc, oc); Runner(rc1,rc2,rc3); Score(tenA,tenB,i); while(true){ i++; while(true){ System.out.println("ピッチャー、投げた!"); String str=br.readLine(); char hantei=str.charAt(0); if(hantei=='s'){ System.out.println("ストライク!"); sc++; }else if(hantei=='b'){ System.out.println("ボール!"); bc++; }else if(hantei=='o'){ System.out.println("アウト!"); oc++; bc=sc=0; }else if(hantei=='h'){ System.out.println("ヒット!"); bc=sc=0; }else if(hantei=='x'){ System.out.println("ホームラン!"); bc=sc=0; }else{ System.out.println("入力が違います。"); continue; } if(sc==3){ System.out.println("ストライク!バッターアウト!"); oc++; sc = bc =0; }else if(bc==4){ System.out.println("フォアボール!"); sc = bc =0; } if(oc >= 3){ System.out.println("スリーアウト!"); break; } System.out.println("走者は出たか、又は進塁したか?"); String str6=br.readLine(); char kakuninn=str6.charAt(0); if(kakuninn=='y'){ System.out.println("一塁は"); String str2=br.readLine(); char r1=str2.charAt(0); if(r1=='y'){ rc1=1; }else if(r1=='n'){ rc1=0; }else{ System.out.println("入力が違います。"); continue; } System.out.println("二塁は"); String str3=br.readLine(); char r2=str3.charAt(0); if(r2=='y'){ rc2=1; }else if(r2=='n'){ rc2=0; }else{ System.out.println("入力が違います。"); continue; } System.out.println("三塁は"); String str4=br.readLine(); char r3=str4.charAt(0); if(r3=='y'){ rc3=1; }else if(r3=='n'){ rc3=0; }else{ System.out.println("入力が違います。"); continue; } }else{ } System.out.print("得点は? :"); String str7=br.readLine(); int tokuten=Integer.parseInt(str7); if(i%2==1){ tenA=tenA+tokuten; }else{ tenB=tenB+tokuten; } BSO(sc, bc, oc); Runner(rc1,rc2,rc3); Score(tenA,tenB,i); } oc=0; rc1=rc2=rc3=0; BSO(sc, bc, oc); Runner(rc1,rc2,rc3); Score(tenA,tenB,i); if(i==6){ System.out.println("ゲームセット!"); break; }else{ } } Score(tenA,tenB,i); } public static void BSO(int sc, int bc, int oc){ System.out.println("---- BSOカウント ----"); System.out.print("B "); for(int i=1;i<=bc;i++){ System.out.print("〇"); } System.out.println(""); System.out.print("S "); for(int i=1;i<=sc;i++){ System.out.print("〇"); } System.out.println(""); System.out.print("O "); for(int i=1;i<=oc;i++){ System.out.print("〇"); } System.out.println("\n------------------"); } public static void Runner(int rc1,int rc2,int rc3){ System.out.println("***走者の有無***"); if(rc2==1){ System.out.println(" ▲ "); }else if(rc2==0){ System.out.println("  △ "); } if(rc3==1){ System.out.print("▲  "); }else if(rc3==0){ System.out.print("△  "); } if(rc1==1){ System.out.println("▲"); }else if(rc1==0){ System.out.println("△"); } System.out.println("***************"); } public static void Score(int tenA,int tenB,int i){ if(i==0||i==1||i==2){ System.out.print("1回"); }else if(i==3||i==4){ System.out.print("2回"); }else if(i==5||i==6){ System.out.print("3回"); } if(i==0||i%2==1){ System.out.println("表"); }else{ System.out.println("裏"); } System.out.println(tenA+" "+"-"+" "+tenB); } }

    • ベストアンサー
    • Java
  • javaの数字当てゲーム

    javaで数字当てゲーム作りたいです。 ここまで出来ています。 しかし、もう一度やりますか?というオプションで、yと入力すればもう一回、 nと入力すれば終わるようにしたいです。 それから、最後に何回ゲームを遊んだか、トータルで数字を何回予想したか、という情報も出力したいです。 できれば、正解するまでに平均で何回かかったかと、一番少なかった数も出力したいです。 よろしくお願いします import java.util.*; public class NumberGuess { public static void main(String args[]) { boolean b = true; int computer = (int) (Math.random() * 100) + 1; int player = 0; int count = 0; System.out.println("1~100の数当てゲーム"); if (computer < 0) { computer *= -1;} while (b) { count++; Scanner keyboard = new Scanner(System.in); System.out.print("1~100の数字を入力してください "); player = keyboard.nextInt(); if (computer > player) { System.out.println("CPUが作成した数字はもっと大きいです"); } else if (computer < player) { System.out.println("CPUが作成した数字はもっと小さいです"); } else if (computer == player) { System.out.println( count + "回目で当てました"); } } } } 直すべきところもあれば教えてください。

専門家に質問してみよう