猿问

这个程序一直在21行和99行抛出空指针异常,谁知道怎么回事?

package overlaod;


//import java.awt.print.Book;


public class OverloadTest {

private Book[ ] booksList;

    void OverloadTest(Book[] booksList ){

Book booskList[] = {

new Book("郁达夫随笔:伤感旅行","郁达夫","北京大学出版社",38.0f),

new Book("教育法学","李晓燕 主编","高等教育出版社",23.9f),

new Book("普通化学原理与应用","毕德乐","高等教育出版社",89.0f),

new Book("机关工会工作指南","郭红美","中国工人出版社",36.0f)

};

this.booksList = booksList;

}

OverloadTest(Book ... book){

booksList = book;

}

void getBookInfo(){

System.out.println("全部图书:");

//System.out.println(booksList);

for(int i = 0; i< booksList.length; i++){

System.out.println("\t"+(i+1)+"."+booksList[i].title+

                    "\t"+booksList[i].author+

                    "\t"+booksList[i].publisher+

                    "\t"+booksList[i].price);

}

}

void getBookInfo(float price){

System.out.println("价格为“"+price+"”的图书");

int m = 1;

for(int i = 0; i< booksList.length; i++){

if(booksList[i].price == price){

System.out.println("\t"+m+"."+booksList[i].title+

                    "\t"+booksList[i].author+

                    "\t"+booksList[i].publisher);

m++;

}

}

}

void getBookInfo(String publisher){

System.out.println("出版社为“"+publisher+"”的图书:");

 int m = 1;

for(int i = 0; i < booksList.length; i++){

if(booksList[i].publisher == publisher){

System.out.println("\t"+m+"."+booksList[i].title+

                    "\t"+booksList[i].author+

                    "\t"+booksList[i].publisher);

m++;

}

}

}

void getBookInfo(float price, String publisher){

System.out.println("价格为“"+price+"”且出版社为“"+publisher+"”的图书:");

int m = 1;

for(int i = 0; i < booksList.length; i++){

if((booksList[i].price == price) & (booksList[i].publisher == publisher)){

System.out.println("\t"+m+"."+booksList[i].title+

                    "\t"+booksList[i].author);

m++;

}

}

}

void getBookInfo(String publisher,float price){

System.out.println("出版社为“"+price+"”且价格为“"+publisher+"”的图书:");

int m = 1;

for(int i = 0; i < booksList.length; i++){

if((booksList[i].publisher == publisher) & (booksList[i].price == price)){

System.out.println("\t"+m+"."+booksList[i].title+

                    "\t"+booksList[i].author);

m++;

}

}

}

void getBookInfo(float...price)

{

String s ="";

int  m = 1;

for(float bookPrice:price){

s = s + bookPrice + " ";

}

System.out.println("价格为“"+s.trim( )+"”的图书:");

for(float bookPrice:price){

int i = 0;

while(i < booksList.length){

if(bookPrice == booksList[i].price){

System.out.println("\t"+(i+1)+"."+booksList[i].title+

                    "\t"+booksList[i].author+

                    "\t"+booksList[i].publisher+

                    "\t"+booksList[i].price);

}

i++;

}

}

}

//void getBookInfo(float[] price){}//方法重复

public static void main(String[ ] args){

OverloadTest  overloadTest = new OverloadTest( );

overloadTest.getBookInfo( );

overloadTest.getBookInfo(36f);

overloadTest.getBookInfo("高等教育出版社");

overloadTest.getBookInfo(89f,"高等教育出版社");

overloadTest.getBookInfo("北京大学出版社",38f);

overloadTest.getBookInfo(36f,28f);

overloadTest = null;

overloadTest = new OverloadTest(

new Book("艺术批评学","陈汉青","北京大学出版社",28.0f),

new Book("工程力学","范钦山","高等教育出版社",71.0f));

overloadTest.getBookInfo( );

}

}

class Book{

String title;

String author;

String publisher;

float price;

Book(String title, String author, String publisher, float price){

this.title = title;

this.author = author;

this.publisher = publisher;

this.price = price;

}

}


慕粉2347349578
浏览 1116回答 1
1回答

DaRKeViL

没发现哪里报空指针
随时随地看视频慕课网APP

相关分类

Java
我要回答