자바 문자열구분 후 배열에 저장하는 것 질문이요ㅠ
파일에서 텍스트를 입력받아 Stringtokenizer로 문자열을 구분한 후
객체 배열을 생성해서 배열에 저장하려고하는데
오류가 떠서요ㅠㅠ.. 코드에 오류부분이라고 써놓은 곳에서 자꾸 오류가 뜨네요ㅜㅜ
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
Type mismatch: cannot convert from String to Book
at Manager.main(Manager.java:33)
제가 뭘 잘못입력한걸까요?ㅜㅜ..
**split()말고 StringTokenizer로만 사용하고 싶습니다
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.Scanner;
import java.util.StringTokenizer;
import java.io.*;
public class Manager{
public static void main(String[] args) {
File datafile = new File("D:/Booklist.txt");
String readData;
StringTokenizer st;
//Menu mn = new Menu;
try {
BufferedReader br = new BufferedReader(new FileReader(datafile));
while((readData = br.readLine())!=null) {
st = new StringTokenizer(readData,"/");
//String number = st.nextToken();
//String rNum = st.nextToken();
//String name = st.nextToken();
//String author = st.nextToken();
//String pHouse = st.nextToken();
//String pYear = st.nextToken();
//String bKind = st.nextToken();
//int x = Integer.parseInt(number);
//int y = Integer.parseInt(pYear);
while(st.hasMoreTokens()) {
int i=0;
Book[] book = new Book[st.countTokens()];//50436개의 Book객체배열 생성
for(i=0; i
book[i]= st.nextToken();//***오류부분***
System.out.println(book[i]);
}
//System.out.println(number+"/"+rNum+"/"+name+"/"+author+"/"+pHouse+"/"+pYear+"/"+bKind);
}
br.close();
}catch(IOException e) {
System.out.println(e.getMessage());
}catch(NumberFormatException e) {
}
https://translate.google.com/
https://translate.google.com/#view=home&op=translate&sl=auto&tl=ko&text=Type%20mismatch%3A%20cannot%20convert%20from%20String%20to%20Book
Book 클래스는 직접 만든 클래스죠? 그리고 String과는 아무런 관계가 없죠?
book클래스를 만들고 메인클래스에서 book클래스의
book클래스를 만들고 메인클래스에서 book클래스의 배열객체를 만들어서 집어넣은건데 잘못된건가요..?
댓글 달기