עזרה דחופה ב- java

ehudl1

New member
עזרה דחופה ב- java

שלום,
יש לי הודעת שגיאה כל הזמן שקשורה להגדרת אובייקט:


public static void main(String[] args)
{
Questions q= new Questions();
int x;
Random rand = new Random();
x =rand.nextInt(10);
for (int i=0; i < 10; i++)
{
if (q.q.getAlreadyShown()==0)
JOptionPane.showMessageDialog(null, q.q.getQ());
}
}

הבעיה היא בתוך הלולאה for
השגיאה:

Exception in thread "main" java.lang.NullPointerException
at trivia.main(trivia.java:22)

מישו יודע מה הבעיה?
תודה.
 

ehudl1

New member
ככה:

public class Questions
{
private static final int SIZE = 10;
private static final int OPCOUNT = 4;
Question q[]= new Question[SIZE];
 

ehudl1

New member
עוד משהו קטן

הגדרתי את הדבר הבא:

ButtonGroup group= new ButtonGroup();
JRadioButton choise1= new JRadioButton("1");
JRadioButton choise2= new JRadioButton("2");
JRadioButton choise3= new JRadioButton("3");
JRadioButton choise4= new JRadioButton("4");
group.add(choise1);
group.add(choise2);
group.add(choise3);
group.add(choise4);
setSize(300,300);
setVisible(true);

עשתי בתפריט שהוא יצירה כמו תמיד, והגדרתי את הבנאי ככה:

public T()
{
super("T");
RandQuestions();

}

בפועל לא נפתח לי שום חלון..
למה?
 

Pitzuk

New member
לדעתי הבעיה בקוד

היא שיש לך משתנה סאטטי במחלקה ולכן אתה לא יכול להשתמש ב NEW כשאתה משתמש במחלקה הזו
תנסה בMAIN לכתוב במקום

Questions q = new Questions();

תכתוב רק

Questions q;
 

ehudl1

New member
פתרתי את זה, השאלה לגבי החלון שלא קופץ?

מישהו יודע למה זה?
 

ehudl1

New member
עזרה? ButtonGroup

שלום,
אני מנסה לעשות דבר פשוט (יחסית): לפתוח חלון עם 4 אופציות סימון (העיגולים שמסמנים את התשובה הנכונה) ולא נפתח לי אף חלון.
הנה הקוד שוב, אם זה יעזור.


public void ShowQuestions() throws FileNotFoundException
{
String str;

for (int i=0; i < 10; i++)
{
JOptionPane.showMessageDialog(null,"blabla");

str=q.q.getQ();
ButtonGroup group= new ButtonGroup();
for (int j=0; j < 4; j++)
{
str=q.q.getOp(j+1);
JRadioButton choisej= new JRadioButton(str);
choisej.addActionListener(this);
// random on board?
group.add(choisej);
}
}
}

בפועל שום דבר לא נפתח לי.
הנה המקום שאני קורא למתודה:

public Trivia() throws FileNotFoundException
{
super("Trivia");
ShowQuestions();
setSize(300,300);
setVisible(true);
}

חשבתי בהתחלה שהשורות:

setSize(300,300);
setVisible(true);

צריכות להיות בתוך המתודה אבל זה עדיין לא פותח לי את החלון בכלל...
מישהו יודע?
 
למעלה