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());
}
}
myArrayは次のとおりです。
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]);
。私が間違っていることを理解することはできません。前もって感謝します。