Итак, у меня были проблемы с добавлением кнопок через кодирование. Это сообщение об ошибке я получаю от LogCat, когда я к деятельности, которая, как предполагается сделать вещи:Ошибка кодирования пользовательского интерфейса Android
09-30 09:36:51.591: E/AndroidRuntime(14956): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.gameproj/com.example.gameproj.MapMain}: java.lang.NullPointerException
Вот код, который, как представляется уместным:
map = new Button[loadedMap.getX()][loadedMap.getY()];
LinearLayout layout = (LinearLayout) findViewById(R.id.mapything);
LinearLayout.LayoutParams coord;
for (int i = 0; i < map.length; i++){
for (int j = 0; j < map[i].length; j++){
map[i][j] = new Button(this);
coord = new LayoutParams(16*i, 75+16*j);
map[i][j].setLayoutParams(coord);
map[i][j].setGravity(Gravity.CENTER_HORIZONTAL);
layout.addView(map[i][j]);
}
}
Из того, что я мог бы debug, ошибка находится вокруг строки layout.addView (map [i] [j]), но мне не удалось выяснить, как заставить ее работать.
Edit: Я не уверен, что еще поставить, но я буду идти вперед и поместить файл XML, чтобы увидеть, если он сделает что-то более ясно
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/mapything"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="${relativePackage}.${activityClass}" >
<Button
android:id="@+id/button1"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:onClick="toCharacter"
android:text="Back" />
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/button1"
android:layout_alignBottom="@+id/button1"
android:layout_centerHorizontal="true"
android:text="Map"
android:textSize="18sp" />
</RelativeLayout>
отправьте еще несколько кодов ... – donison24x7
Я добавил еще несколько кодов, но я не уверен, что еще мне нужно добавить. – aattss