yegane8
پنج شنبه 22 تیر 1391, 22:28 عصر
سلام
من می خوام از متد ActionListener در یک کلاس یک string به یک متد دیگر در کلاس دیگر بفرستم
اینطوری نوشتم :
public String question;
public String choice;
private void toefl1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
question =null;
question =evt.getActionCommand();
choice = question+"choice" ;
SwingRadioButton test1 = null;
try {
test1 = new SwingRadioButton();
} catch (FileNotFoundException ex) {
ex.printStackTrace();
}
test1.setChoiceFile(choice);
test1.setQuestionFile(question);
حالا تو اون یکی کلاس اینطوری نوشتم
private String choiceFile;
private String questionFile;
public void setChoiceFile(String choice){
this.choiceFile =choice;
}
public String getChoiceFile(){
return choiceFile;
}
public void setQuestionFile(String question){
this.questionFile =question;
}
public String getQuestionFile(){
return questionFile;
}
توی یک متد اینطوری ازشون استفاده کردم
Scanner input1 = new Scanner(new File(this.getChoiceFile()));
Scanner input2= new Scanner(new File(this.getQuestionFile()));
اما این خطا رو میده :
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at java.io.File.<init>(File.java:251)
at SwingRadioButton.testFrame(SwingRadioButton.java:5 5)
at SwingRadioButton.<init>(SwingRadioButton.java:33)
at NewJFrame.toefl1ActionPerformed
فکر کنم اصلاstring مقدار دهی نمیشه
باید چی کار کنم؟
باتشکر
من می خوام از متد ActionListener در یک کلاس یک string به یک متد دیگر در کلاس دیگر بفرستم
اینطوری نوشتم :
public String question;
public String choice;
private void toefl1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
question =null;
question =evt.getActionCommand();
choice = question+"choice" ;
SwingRadioButton test1 = null;
try {
test1 = new SwingRadioButton();
} catch (FileNotFoundException ex) {
ex.printStackTrace();
}
test1.setChoiceFile(choice);
test1.setQuestionFile(question);
حالا تو اون یکی کلاس اینطوری نوشتم
private String choiceFile;
private String questionFile;
public void setChoiceFile(String choice){
this.choiceFile =choice;
}
public String getChoiceFile(){
return choiceFile;
}
public void setQuestionFile(String question){
this.questionFile =question;
}
public String getQuestionFile(){
return questionFile;
}
توی یک متد اینطوری ازشون استفاده کردم
Scanner input1 = new Scanner(new File(this.getChoiceFile()));
Scanner input2= new Scanner(new File(this.getQuestionFile()));
اما این خطا رو میده :
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at java.io.File.<init>(File.java:251)
at SwingRadioButton.testFrame(SwingRadioButton.java:5 5)
at SwingRadioButton.<init>(SwingRadioButton.java:33)
at NewJFrame.toefl1ActionPerformed
فکر کنم اصلاstring مقدار دهی نمیشه
باید چی کار کنم؟
باتشکر