0
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
asked Jun 11, 2012 at 6:31
4
  • take a breath while editing @Krishnabhadra Commented Jun 11, 2012 at 6:33
  • Do you even create an instance of temp class? Commented Jun 11, 2012 at 6:36
  • @Krishnabhadra, i am just saying you to do meaningful edit :) Commented 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 ? Commented Jun 11, 2012 at 7:36

2 Answers 2

1

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
Sign up to request clarification or add additional context in comments.

3 Comments

but mtemp is static why it need initiaiztion?
you mean in class ShareDate? i was initialized as null ,then in MainActivity i still cannot evaluation; like this ShareDate.mtemp.date0=20;
oh thanks your answer helped me ,now it's ok .it's must that initialize first.
0

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

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.