我正在尝试在 Android 中另一个活动的类中设置一个数组。
这是我的主要活动:
public class main_activity extends Activity {
int i = 0;
TextView title;
TextView inst;
TextView word;
EditText edittext;
Button btn;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_four);
MyArray mine = new MyArray();
mine.shuffle(getApplicationContext());
}
}
这是我的数组:
public class MyArray{
String[] words = new String[2];
public void choose(int id) {
switch (id) {
case 1:
words[0] = "zero";
words[1] = "one";
break;
case 2:
words[0] = "two";
words[1] = "three";
}
public void shuffle(Context mcontext) {
MyArray mine = new MyArray();
mine.choose(2);
Log.d("TEST", words[1]);
Log.d("TEST", words[2]);
}
}
我因 NullPointer 错误而强制关闭Log.d("TEST", words[1]);
。无法弄清楚我做错了什么。提前致谢。