大家帮我看下我自己练习的代码错在哪了 exception类 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 package testString;import java.util.ArrayList;import java.util.HashMap;import java.util.Map;import java.util.Random;import java.util.Stack;public class Menu { private static final Menu Do = null; static Map<Integer, Food> is = new HashMap<Integer, Food>(); static int[] array = new int[10]; static int m = 0; static int sum = 0; Food p1 = new Food("大白菜", 10); Food p2 = new Food("大龙虾", 50); Food p3 = new Food("回锅肉", 30); Food p4 = new Food("麻婆豆腐", 22); Food p5 = new Food("番茄鸡蛋", 12); Food p6 = new Food("炒猪耳朵", 26); Food p7 = new Food("宫爆鸡丁", 35); Food p8 = new Food("干锅豆腐", 18); Food p9 = new Food("烤羊串", 3); Food p0 = new Food("萝卜汤", 15); public void show() { is.put(1, p1); is.put(2, p2); is.put(3, p3); is.put(4, p4); is.put(5, p5); is.put(6, p6); is.put(7, p7); is.put(8, p8); is.put(9, p9); is.put(0, p0); } public ArrayList<Food> shoo() { ArrayList<Food> food = new ArrayList<Food>(); new Menu().show(); Random ra = new Random(); for (int i = 0; i < array.length; i++) { int aa = ra.nextInt(10); array[i] = aa; food.add(is.get(aa)); sum += food.get(i).getPrice(); System.out.println(food.get(i)); } System.out.println("一共需要" + sum + "元"); return food; } public void Do() { ArrayList<Food> foodShelf = new ArrayList<Food>();//?????????? ArrayList<Food> food = new Menu().shoo(); while (true) { if (food.size() != 0) { if (foodShelf.size() >= 5) {//这里为0 while (true) { if (foodShelf.size() != 0) { System.out.println(foodShelf.get(0).toString( foodShelf.size() - 1, food.size())); foodShelf.remove(0); try { Thread.sleep(500); } catch (InterruptedException e) { e.printStackTrace(); } } else { break; } } } System.out.println("出错了");//=======================看这里============================ foodShelf.add(food.get(0));//你在这里不停的取.取完数参数,却没做任何处理!取不到参数所以报空针异常. System.out.println(foodShelf.get(m).toString(foodShelf.size())); food.remove(0); m++; try { Thread.sleep(500); } catch (InterruptedException e) { e.printStackTrace(); } } else { System.exit(0); } } }}看上面的注释! 静态成员变量初始化的疑惑 java swing如何布局? 关于 线程 Java的反射机制!!Java高手请进! 菜鸟问题.确实不懂啊!! 请教一下,JAVA开发的代码有没有继承窗体的哪个概念? Jtable Jcheckbox 想做成前面一个checkbox,后面跟着一条记录,选中checkbox,也就选中该条,象sina邮箱,用Applet! 急用!修改程序使结果排序后输出。经调试成功 后,给分,不成功 ,不给分. 一个很简单却令我很郁闷的问题,请教! 请问线程池在开发中常用吗 用正则表达式 替换字符前后字符,中间的保持不变. Spring HIbernate 整合问题
import java.util.HashMap;
import java.util.Map;
import java.util.Random;
import java.util.Stack;public class Menu {
private static final Menu Do = null;
static Map<Integer, Food> is = new HashMap<Integer, Food>();
static int[] array = new int[10];
static int m = 0;
static int sum = 0;
Food p1 = new Food("大白菜", 10);
Food p2 = new Food("大龙虾", 50);
Food p3 = new Food("回锅肉", 30);
Food p4 = new Food("麻婆豆腐", 22);
Food p5 = new Food("番茄鸡蛋", 12);
Food p6 = new Food("炒猪耳朵", 26);
Food p7 = new Food("宫爆鸡丁", 35);
Food p8 = new Food("干锅豆腐", 18);
Food p9 = new Food("烤羊串", 3);
Food p0 = new Food("萝卜汤", 15); public void show() {
is.put(1, p1);
is.put(2, p2);
is.put(3, p3);
is.put(4, p4);
is.put(5, p5);
is.put(6, p6);
is.put(7, p7);
is.put(8, p8);
is.put(9, p9);
is.put(0, p0);
} public ArrayList<Food> shoo() {
ArrayList<Food> food = new ArrayList<Food>();
new Menu().show();
Random ra = new Random();
for (int i = 0; i < array.length; i++) {
int aa = ra.nextInt(10);
array[i] = aa;
food.add(is.get(aa));
sum += food.get(i).getPrice();
System.out.println(food.get(i));
}
System.out.println("一共需要" + sum + "元");
return food;
} public void Do() {
ArrayList<Food> foodShelf = new ArrayList<Food>();//??????????
ArrayList<Food> food = new Menu().shoo();
while (true) {
if (food.size() != 0) {
if (foodShelf.size() >= 5) {//这里为0
while (true) {
if (foodShelf.size() != 0) {
System.out.println(foodShelf.get(0).toString(
foodShelf.size() - 1, food.size()));
foodShelf.remove(0);
try {
Thread.sleep(500);
} catch (InterruptedException e) {
e.printStackTrace();
}
} else {
break;
}
}
}
System.out.println("出错了");//=======================看这里============================
foodShelf.add(food.get(0));//你在这里不停的取.取完数参数,却没做任何处理!取不到参数所以报空针异常.
System.out.println(foodShelf.get(m).toString(foodShelf.size()));
food.remove(0);
m++;
try {
Thread.sleep(500);
} catch (InterruptedException e) {
e.printStackTrace();
}
} else {
System.exit(0);
}
}
}
}
看上面的注释!