null 포인터 예외 문제가 있고 나는 몇 가지 문서를 읽은 그 오류가 여전히 무엇을 문제를 coundnt 알아 냈어.NullPointerException 오류를 수정하는 중 오류가 발생 했습니까?
오류는 방법으로 CompatibleActivity[topIndex]=new Activity(aNum,bNum,c);
topIndex=0
에서 발생합니다.
누구나 문제를 강조 할 수 있습니까?
여기 내 수업
public class Schedulingtest {
public static void main (String[] args) throws IOException
{
Scanner fileScan;
fileScan=new Scanner(new File("data.txt"));
Schedule compatibility = new Schedule();
while(fileScan.hasNext())
{String url=fileScan.nextLine();
compatibility.addActivity(url);
}
}
public class Schedule{
import java.util.Scanner;
import java.util.Arrays;
public class Schedule {
Activity[] CompatibleActivity;
int totalTime=0,topIndex=0;
Scanner urlScan;
public Schedule(){
Activity[] CompatibleActivity=new Activity[30];
}
public int getTotalTime()
{return totalTime;
}
public void addActivity(String entry){
urlScan=new Scanner(entry);
urlScan.useDelimiter(" ");
String c=null;
int aNum = 0,bNum=0;
while(urlScan.hasNext())
{String a=urlScan.next();
String b=urlScan.next();
c=urlScan.next();
aNum=Integer.parseInt(a);
bNum=Integer.parseInt(b);
}
CompatibleActivity[topIndex]=new Activity(aNum,bNum,c);
topIndex++;
System.out.println("Activity added: start "+aNum+ " stop "+bNum+" "+c);
}
}
활동 Class 구성 NullPointerException이 그 줄에 확실히 경우
public class Activity {
private int start,stop,duration;
private String name;
public Activity(int Start,int Stop,String Name)
{
start=Start;
stop=Stop;
name=Name;
duration=Stop-Start;
}
public String getName()
{return name;
}
public int getStart()
{return start;
}
public int getStop()
{return stop;
}
public int getDuration()
{return duration;
}
public boolean compatible(int Start1,int Stop1,int toMatchsideStart,int toMatchsideStop)
{
int Start=Start1;
int Stop=Stop1;
int toMatchStart=toMatchsideStart;
int toMatchStop=toMatchsideStop;
if(toMatchStop<=Start)
{return true;
}
if(toMatchsideStart>=Stop)
{return true;
}
else
{return false;}
}
public String toString()
{return(name+"<"+start+","+stop+">"); }
}
전체 스택 트레이스는 무엇인가 : 당신은 그것을 (예를 들어, 귀하의 생성자)에 충분한 요소가 실제 배열을 할당 할 필요가? – DaveJohnston
어디에서'CompatibleActivity'를 선언합니까? 그리고이 배열을 어디에서 초기화합니까 (null이 아니기 위해)? – Thilo
던져진 예외의 전체 스택 추적을 게시하십시오. –