另一个"不能使静态参考..."题 [英] Another "Cannot make static reference..." Question
问题描述
我试图写有一些意见,认为设置的意见(是不是静态的,因为它必须利用getContentResolver)一fillView()方法的活动,这使得一个随机选择从光标,然后一个静态方法运行fillView()方法。
我不得不因fillView不是静态的,pickRandom是静态的这个问题,所以我试图initialzize的类的实例,但现在它崩溃就行了instance.fillView();
样code以下。任何帮助将是AP preciated。或许有一个更容易实现什么,我试图做的方法。
谢谢,
乔希
公共类MyView的扩展活动实现OnClickListener {
@覆盖
公共无效的onCreate(捆绑savedInstanceState){
super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE);
的setContentView(R.layout.myView);fillView(); }
公共无效fillView(){ //创建视图,运行光标和适用成果创建的视图}公共静态无效pickRandom(){
//运行光标,随意挑选进入,接下来我想申请的结果
//观点,所以我跑... MyView的V =新MyView的();
v.fillView(); }
请静态实例变量,并在OnCreate中设置:
私有静态MyView的实例;
在OnCreate()
实例=这一点;
静态pickrandom()
instance.fillView();
I am trying to write an Activity that has some views, a fillView() method that sets the views (which is not static because it must utilize getContentResolver), and a static method that makes a random choice from a cursor and then runs the fillView() method.
I had problems with this due to fillView not being static and pickRandom being static, so I tried to initialzize an instance of the class, but now it crashes on the line instance.fillView();
Sample code below. Any help would be appreciated. Perhaps there is a much easier way to accomplish what I am trying to do.
Thanks, Josh
public class myView extends Activity implements OnClickListener {
@Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.myView);
fillView();
}
public void fillView(){
//creates views, runs cursor and applies results to the view created
}
public static void pickRandom() {
// runs cursor, picks random entry, next I want to apply the result to
// view, so I run...
myView v = new myView();
v.fillView();
}
Make a static instance variable and set in in oncreate:
private static myView instance;
oncreate()
instance = this;
static pickrandom()
instance.fillView();
这篇关于另一个"不能使静态参考..."题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!