首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >错误:无法找到或加载主类迪斯尼乐园

错误:无法找到或加载主类迪斯尼乐园
EN

Stack Overflow用户
提问于 2017-11-16 01:02:07
回答 1查看 25关注 0票数 0

我的代码进行了编译,我有两个文本文件需要从程序中读取,但当我运行程序时,我得到了以下错误: menuItems.txt包含:油炸冰淇淋汉堡奶酪汉堡火鸡腿玉米狗披萨漏斗蛋糕苏打水

priceItems包含:5 4 9 10 13 7 9 6 5所有文件都位于我的桌面上

错误:无法找到或加载主类迪士尼乐园包com.Kassie$;

代码语言:javascript
复制
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Scanner;

public class Disneyland {
//Initialize the items 1D array
public static String[] getItems() {
   try {
       //Read from file
       String[] aItems = new String(Files.readAllBytes
           (Paths.get("src/com/Kassie$/desktop/menuItems.txt")))
           .split("\n");
       return aItems;
    } catch (IOException e) {
       e.printStackTrace();
   }
   return null;
}
//Initialize the items 1D array
public static String[] getPrices() {
   try {
       //Read from file
           String[] aPrices = new String(Files.readAllBytes
           (Paths.get("src/com/Kassie$/desktop/menuPrices.txt")))
           .split("\n");
           return aPrices;
       } catch (IOException e) {
           e.printStackTrace();
       }
       return null;  
}
// Find the character's location
public static String findLocation(String[][] storedValue, String name) {
   for(int i = 0; i < storedValue.length; i++) {
       if(storedValue[i][0].equals(name)) {
           return (storedValue[i][1]);
       }
   }
   return null;
}
public static void main(String[] args) {
   char choice = ' ';
   int totPrice = 0;
   Scanner s = new Scanner(System.in);
   String[][] characterLocation = {{"Mickey Mouse","Main Street USA"},
       {"Minnie Mouse", "Toon Town"},
       {"Goofy","Frontier Land"},
       {"Pluto","Tomorrowland"},
       {"Belle","Fantasyland"},
       {"Jasmine", "Adventureland"}};
   System.out.println("Do you like to know the "
       + "Disney Character's location(Y/N)?");
   choice = s.next().charAt(0);
   if(choice == 'Y' || choice == 'y') {
       System.out.println("Enter the name of the character");
       String aName = s.next();
       String location = findLocation(characterLocation,aName);
       if( location != null) {
           System.out.println("The character is located in " + location);
       }
       else {
           System.out.println("Sorry! The character you are looking for "
               + "is not in park today");
       }
   }
   String[] items = getItems();
   String[] prices = getPrices();
   choice = ' ';
   System.out.println("Would you like to view the menu?(Y/N)");
   choice = s.next().charAt(0);
   if(choice == 'N' || choice == 'n') {
       System.exit(0);
   }
   while(choice == 'Y' || choice == 'y') {
       for(int i = 0; i < items.length; i++) {
           System.out.println("Enter " + (i+1) + " for " + items[i]);
       }
       int option = s.nextInt();
       System.out.println("Item : " + items[option-1]);
       System.out.println("Price : " + prices[option-1]);
       totPrice = totPrice + Integer.parseInt(prices[option-1]);
       System.out.println("Do you want to order more(Y/N)?");
       choice = s.next().charAt(0);
   }
   System.out.println("Are you an Annual Pass Holder?(Y/N)?");
   choice = s.next().charAt(0);
   if(choice == 'Y' || choice == 'y') {
       System.out.println("Your bill amount due : $" +        ((double)totPrice -
   ((double)(totPrice*15))/100));
       System.exit(1);
   }
   System.out.println("Your bill amount due : $" + totPrice);
}
}
EN

回答 1

Stack Overflow用户

发布于 2017-11-16 01:07:42

你需要避开路上的美元符号。

要匹配美元符号,请使用"\$"

代码语言:javascript
复制
public static String[] getPrices() {
   try {
       //Read from file
           String[] aPrices = new String(Files.readAllBytes
           (Paths.get("src/com/Kassie\\$/desktop/menuPrices.txt")))
           .split("\n");
           return aPrices;
       } catch (IOException e) {
           e.printStackTrace();
       }
       return null;  
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/47313237

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档