我慢慢变得疯狂......试图定义一个非常简单的类数组来保存其他引用类的实例。但是我一直收到空指针错误。我错了什么?对于任何帮助,我都非常感谢!
//-------------------------
// main activity
//-------------------------
package bangkokguy.android.fromscratch;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Palya kaki = new Palya();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
}
//-------------------------
// class Palya
//-------------------------
package bangkokguy.android.fromscratch;
public class Palya {
public Kocka sok_kocka [];
public Palya() {
sok_kocka = new Kocka[10];
<b>sok_kocka [1].letter = ' '; /*!!! null pointer here */</b>
}
}
//-------------------------
// class Kocka
//-------------------------
package bangkokguy.android.fromscratch;
public class Kocka /*implements _NewLetter, _IsFree*/ {
public char letter;
static final char c_empty = ' ';
public Kocka () {letter = c_empty;}
public Kocka (char letterke) {letter = letterke;}
public void _NewLetter (char letterke) {letter = letterke;}
public boolean _IsFree () {return letter == c_empty;}
}