Answer the question
In order to leave comments, you need to log in
Error initializing Button. What could be the problem?
Here is the xml markup:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".Controller.GameActivity"
android:background="@drawable/wood_boards_002">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:id="@+id/textView"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:textSize="25sp"
android:textColor="#000000"
android:layout_marginTop="20dp"/>
<TableLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true">
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button
android:layout_width="100dp"
android:layout_height="100dp"
android:id="@+id/point0_0"
android:textSize="75sp"
android:textStyle="bold"
android:layout_margin="5dp"
android:background="#ae969696"
android:onClick="clickPoint0_0"/>
<Button
android:layout_width="100dp"
android:layout_height="100dp"
android:id="@+id/point0_1"
android:textSize="75sp"
android:textStyle="bold"
android:layout_margin="5dp"
android:background="#ae969696"
android:onClick="clickPoint0_1"/>
<Button
android:layout_width="100dp"
android:layout_height="100dp"
android:id="@+id/point0_2"
android:textSize="75sp"
android:textStyle="bold"
android:layout_margin="5dp"
android:background="#ae969696"
android:onClick="clickPoint0_2"/>
</TableRow>
Дальше аналогично
</TableLayout>
</RelativeLayout>
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_game);
mIntent = getIntent();
mStringDifficultyMode = mIntent.getStringExtra(Constants.KEY_INPUT_VALUE_WHEN_CALLED_GAME_ACTIVITY);
initViews();
if (mButtons[0][0].getText().equals("")) {
mTextView.setText("Работает!");
}
}
private void initViews() {
mButtons[0][0] = (Button) findViewById(R.id.point0_0);
mButtons[0][1] = (Button) findViewById(R.id.point0_1);
mButtons[0][2] = (Button) findViewById(R.id.point0_2);
mButtons[1][0] = (Button) findViewById(R.id.point1_0);
mButtons[1][1] = (Button) findViewById(R.id.point1_1);
mButtons[1][2] = (Button) findViewById(R.id.point1_2);
mButtons[2][0] = (Button) findViewById(R.id.point2_0);
mButtons[2][1] = (Button) findViewById(R.id.point2_1);
mButtons[2][2] = (Button) findViewById(R.id.point2_2);
mTextView = (TextView) findViewById(R.id.textView);
}
07-22 04:54:48.679 5836-5836/com.example.root.tick_tack_toe E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.root.tick_tack_toe, PID: 5836
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.root.tick_tack_toe/com.example.root.tick_tack_toe.Controller.GameActivity}: java.lang.NullPointerException: Attempt to read from null array
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: java.lang.NullPointerException: Attempt to read from null array
at com.example.root.tick_tack_toe.Controller.GameActivity.initViews(GameActivity.java:48)
at com.example.root.tick_tack_toe.Controller.GameActivity.onCreate(GameActivity.java:38)
at android.app.Activity.performCreate(Activity.java:6237)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
mButtons[0][0] = (Button) findViewById(R.id.point0_0);
initViews();
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question