java之空指针异常

关于空指针异常
麻烦大佬帮我看下那里出现了BUG-----本来在学线程那块,想写点东西来用一下锁
结果到测试的时候发现出现了空指针异常。。。。。。
代码如下:
package threadApp;
import java.util.ArrayList;
/**

  • 四虎影院2–用容器list表示位置
    */
    import java.util.List;

class HappyCinemaV1{
public static void main(String[] args) {
//四虎影院中原有的座位号–可用的位置
List a = new ArrayList();
a.add(1);
a.add(2);
a.add(5);
a.add(6);
a.add(7);
a.add(3);
//嬲哥要买的座位号
List b = new ArrayList();
b.add(5);
b.add(2);
b.add(1);

	//包子要买的座位
	List<Integer> bb = new ArrayList<Integer>();
	bb.add(6);
	bb.add(2);
	bb.add(3);
	
  SihuCinema sihu = new SihuCinema(a, "四虎影院");
  happycustomer c = new happycustomer(b, "嬲哥");
  happycustomer d = new happycustomer(bb, "包子");
  c.start();
  d.start();
}

}

//四虎影院
class SihuCinema{
List uselocation;
String name ;
happycustomer people;
//构造器
public SihuCinema(List list , String name) {
this.name = name;
uselocation = list;
}

//买票看电影
public boolean buylocation(List<Integer> a) {
	List<Integer> copy = new ArrayList<Integer>();
	copy.addAll(uselocation);
	copy.removeAll(a);
	if (uselocation.size()-copy.size() != a.size()) {
		System.out.println("购票失败!!");
		return false;
	}
		System.out.println("购票成功!!");
		uselocation = copy;
	return true;
}

}

class happycustomer extends Thread{
SihuCinema sihu;
List location; //顾客要买的座位号
String name;

//要买票的信息传入

public happycustomer(List b,String name) {
this.location = b;
this.name = name;
}

@Override
public void run() {
	synchronized (sihu) {
	boolean flag = sihu.buylocation(location);
	if (flag) {
		System.out.println(Thread.currentThread().getName() + "买的位置是:" + location);
	}else {
		System.out.println("位置不够");
	}
	System.out.println("剩余的位置为:" + sihu.uselocation);
}
}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值