Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/305.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/image/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 类型字符的错误方法未定义_Java_Character - Fatal编程技术网

Java 类型字符的错误方法未定义

Java 类型字符的错误方法未定义,java,character,Java,Character,我有一个程序,可以找到.txt文件中出现四个字母的次数,但我不明白为什么它会给我这个错误: Error: The method isWhiteSpace(char) is undefined for the type java.lang.Character 这个错误意味着什么,是什么导致了这个问题,我如何修复它 import java.util.Scanner; import java.io.File; import java.io.IOException; import java.io.Bu

我有一个程序,可以找到
.txt
文件中出现四个字母的次数,但我不明白为什么它会给我这个错误:

Error: The method isWhiteSpace(char) is undefined for the type java.lang.Character
这个错误意味着什么,是什么导致了这个问题,我如何修复它

import java.util.Scanner;
import java.io.File;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.FileNotFoundException;

public class Count
{
  public static void main (String[] args) throws  FileNotFoundException {

  String phrase;
  String everything = "";  // a string of characters
  int countBlank;   // the number of blanks (spaces) in the phrase 
  int length;       // the length of the phrase
  char ch;          // an individual character in the string
  int countA;
  int countE;
  int countS;
  int countT;

  java.io.File file = new java.io.File("counting.txt");
  Scanner inFile = new Scanner (file);

 Scanner scan = new Scanner(System.in);

 phrase = inFile.nextLine();
 length = phrase.length();

      // Initialize counts

  while (true)
  { 
  if (phrase.equalsIgnoreCase("quit"))

      break;

  else
  {

  countBlank = 0;
  countA = 0;
  countE = 0;
  countS = 0;
  countT = 0;

  for ( int i = 0; i < length; i++ )   
   { 
   if ( phrase.charAt( i ) == ' ' )

    countBlank++;
    ch = phrase.charAt(i);

       switch (ch)
        {
         case 'a':
         case 'A':  countA++;
                 break;
     case 'e':
     case 'E':  countE++;
         break;
     case 's':
     case 'S':  countS++;
            break;
     case 't':
     case 'T':  countT++;
        break;
      }

 }
        System.out.println ();
        System.out.println ("Number of blank spaces: " + countBlank);
        System.out.println ();

    System.out.println ("Number of A's: " + countA);
    System.out.println ();
    System.out.println ("Number of E's: " + countE);
    System.out.println ();
    System.out.println ("Number of S's: " + countS);
    System.out.println ();
    System.out.println ("Number of T's: " + countT);
    break;

  }     
 }


 } 
}
import java.util.Scanner;
导入java.io.File;
导入java.io.IOException;
导入java.io.BufferedReader;
导入java.io.FileNotFoundException;
公共类计数
{
公共静态void main(字符串[]args)引发FileNotFoundException{
字符串短语;
String everything=“”;//一个字符串
int countBlank;//短语中的空格数
int length;//短语的长度
char ch;//字符串中的单个字符
int countA;
整数计数;
整数计数;
int countT;
java.io.File File=新的java.io.File(“counting.txt”);
扫描仪内嵌=新扫描仪(文件);
扫描仪扫描=新扫描仪(System.in);
短语=infle.nextLine();
长度=短语。长度();
//初始化计数
while(true)
{ 
if(短语.equalsIgnoreCase(“退出”))
打破
其他的
{
countBlank=0;
countA=0;
计数=0;
计数=0;
countT=0;
for(int i=0;i
方法
是空格(char)
接受类型为
char
,而不是
Character
的参数

Character
是对象,
char
是本机类型

如果
char1
Character
类型的对象,则使用此代码:

//Assume char1 is an object of type Character
boolean flagWS;
flagWS = Character.isWhiteSpace(char1.charValue())

你有一个打字错误,它是
isWhitespace
,而不是
isWhitespace
。Java区分大小写。看看javadoc,它的意思就是它所说的。字母大小写在Java中非常重要;检查javadocs中正确的方法名。该代码是如何产生该错误的?该代码中甚至没有调用特定的方法。