Ho definito una classe con due proprietà e un metodo costruttore ma non riesco ad utilizzarla...se creo la classe con il costruttore, es.1) l'errore è che il costruttore è indefinito (perchè???)
Se dichiaro la variabile del tipo class_calendario e la inizializzo a null es.2), il file è compilato ma ho NullPointerException...
Come si fa????
Thxxxxxx
1) class_calendario c = new class_calendario(submit,month_now,year_now);
2) class_calendario c=null;
c.class_calendario(submit,month_now,year_now);
String m = c.get_mese();
String y = c.get_anno();
class_calendario.java:
public class class_calendario
{
int mese;
int anno;
public Calendar class_calendario (String submit,String month_now,String year_now) {
Calendar cal = new GregorianCalendar();
int num_month_now = Integer.parseInt(month_now);
int num_year_now = Integer.parseInt(year_now);
int new_month_now = 0;
int new_year_now = 0;
if (submit.equals("Prev")){
new_month_now = num_month_now - 1;
if (new_month_now < 0){
new_month_now = 11;
new_year_now = num_year_now - 1;
}
}
else if (submit.equals("Next")){
new_month_now = num_month_now + 1;
if (new_month_now == 12){
new_month_now = 0;
new_year_now = num_year_now +1;
}
}
this.set_mese(new_month_now);
this.set_anno(new_year_now);
cal.set(new_year_now,new_month_now,1);
return cal;
}
public void set_mese(int m){
this.mese=m;
}
public void set_anno(int y){
this.anno=y;
}
public String get_mese(){
return Integer.toString(this.mese);
}
public String get_anno(){
return Integer.toString(this.anno);
}
}