public class temp
{
public int data0;//整数
public int data1;//小数
public int data2;
public int data3;
public long firsttime;
public temp(int type,int data0, int data1, int data2, int data3,
long firsttime) {
super();
this.data0 = data0;
this.data1 = data1;
this.data2 = data2;
this.data3 = data3;
this.firsttime = firsttime;
}
}
public class ShareDate {
public static temp mtemp=null;
public static date mdate=null;
}
the problem is in MainActivity I did like this
ShareDate.mtemp.date0=20;
then the program was stopped unexpected. I don't know where it's wrong?
Lucifer
29.7k25 gold badges93 silver badges144 bronze badges
-
take a breath while editing @KrishnabhadraLucifer– Lucifer2012年06月11日 06:33:55 +00:00Commented Jun 11, 2012 at 6:33
-
Do you even create an instance of temp class?nhahtdh– nhahtdh2012年06月11日 06:36:16 +00:00Commented Jun 11, 2012 at 6:36
-
@Krishnabhadra, i am just saying you to do meaningful edit :)Lucifer– Lucifer2012年06月11日 06:36:52 +00:00Commented Jun 11, 2012 at 6:36
-
what is mean ? i was use class ShareDate it in MainActivity ShareDate class include static temp mtemp. i mean why i can't evaluation for mtemp.date0 ?ninjiaquan– ninjiaquan2012年06月11日 07:36:37 +00:00Commented Jun 11, 2012 at 7:36
2 Answers 2
where is your initialization code?
mtemp=new temp();
A class's object must be initialized to use its data member/Methods.
answered Jun 11, 2012 at 6:35
Mohammed Azharuddin Shaikh
42.1k14 gold badges98 silver badges117 bronze badges
Sign up to request clarification or add additional context in comments.
3 Comments
ninjiaquan
but mtemp is static why it need initiaiztion?
ninjiaquan
you mean in class ShareDate? i was initialized as null ,then in MainActivity i still cannot evaluation; like this ShareDate.mtemp.date0=20;
ninjiaquan
oh thanks your answer helped me ,now it's ok .it's must that initialize first.
You need to initialize before object use.. There is no initialization code..
mtemp=new temp();
And why u use constructor?
If you use ,
ShareDate.mtemp.date0=20; like this ,,
no need a constructor.
answered Jun 11, 2012 at 6:36
stay_hungry
1,4481 gold badge14 silver badges21 bronze badges
Comments
lang-java