Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8896711
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T00:08:45+00:00 2026-06-15T00:08:45+00:00

I’m trying to code a little tictactoe game. Now I came to a point

  • 0

I’m trying to code a little tictactoe game. Now I came to a point where it throws a nullPointerException which I can’t explain. Can anyone help?

code main activity:

    package de.android.pali;

    import android.app.Activity;
    import android.content.Intent;
    import android.os.Bundle;
    import android.view.View;
    import android.view.View.OnClickListener;
    import android.widget.Button;

    public class TicTacToeMenu extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_tic_tac_toe_menu);

    final Button createGame = (Button)findViewById(R.id.newGameButton);

    final Intent newGame = new Intent(TicTacToeMenu.this, newGame.class);

    createGame.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {

            startActivity(newGame);


        }
    });


}


}

Code of second Activity:

package de.android.pali;

import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageButton;
import android.widget.TextView;

public class newGame extends TicTacToeMenu{

int turn = 1;
int[] felder = new int[9];
TextView ergebnis = (TextView)findViewById(R.id.winners);

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.game);

    final ImageButton feld1 = (ImageButton)findViewById(R.id.feld1);
    final ImageButton feld2 = (ImageButton)findViewById(R.id.feld2);
    final ImageButton feld3 = (ImageButton)findViewById(R.id.feld3);
    final ImageButton feld4 = (ImageButton)findViewById(R.id.feld4);
    final ImageButton feld5 = (ImageButton)findViewById(R.id.feld5);
    final ImageButton feld6 = (ImageButton)findViewById(R.id.feld6);
    final ImageButton feld7 = (ImageButton)findViewById(R.id.feld7);
    final ImageButton feld8 = (ImageButton)findViewById(R.id.feld8);
    final ImageButton feld9 = (ImageButton)findViewById(R.id.feld9);




    feld1.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {


            if(turn==1){
            feld1.setBackgroundResource(R.drawable.kreis);
            turn = 0;
            felder[0] = 1;
            }
            else{
                feld1.setBackgroundResource(R.drawable.kreuz);
                turn = 1;
                felder[0] = 0;
            }
        }


    });

    feld2.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {

            if(turn==1){
                feld2.setBackgroundResource(R.drawable.kreis);
                turn = 0;
                felder[1] = 1;
                }
                else{
                        feld2.setBackgroundResource(R.drawable.kreuz);
                    felder[1] = 0;
                }
        }
    });

    feld3.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            if(turn==1){
                feld3.setBackgroundResource(R.drawable.kreis);
                turn = 0;
                felder[2] = 1;
                }
                else{
                    feld3.setBackgroundResource(R.drawable.kreuz);
                    turn = 1;
                    felder[2] = 0;
                };

        }
    });

    feld4.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {

            if(turn==1){
                feld4.setBackgroundResource(R.drawable.kreis);
                turn = 0;
                felder[3] = 1;
                }
                else{
                    feld4.setBackgroundResource(R.drawable.kreuz);
                    felder[3] = 0;
                }

        }
    });

    feld5.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {

            if(turn==1){
                feld5.setBackgroundResource(R.drawable.kreis);
                turn = 0;
                felder[4] = 1;
                }
                else{
                    feld5.setBackgroundResource(R.drawable.kreuz);
                    turn = 1;
                    felder[4] = 0;
                }

        }
    });

    feld6.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {

            if(turn==1){
                feld6.setBackgroundResource(R.drawable.kreis);
                turn = 0;
                felder[5] = 1;
                }
                else{
                    feld6.setBackgroundResource(R.drawable.kreuz);
                    turn = 1;
                    felder[5] = 0;
                }

        }
    });

    feld7.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {

            if(turn==1){
                feld7.setBackgroundResource(R.drawable.kreis);
                turn = 0;
                felder[6] = 1;
                }
                else{
                    feld7.setBackgroundResource(R.drawable.kreuz);
                    turn = 1;
                    felder[6] = 0;
                }

        }
    });

    feld8.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {

            if(turn==1){
                feld8.setBackgroundResource(R.drawable.kreis);
                turn = 0;
                felder[7] = 1;
                }
                else{
                    feld8.setBackgroundResource(R.drawable.kreuz);
                    turn = 1;
                    felder[7] = 0;
                }

        }
    });

    feld9.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {

            if(turn==1){
                feld9.setBackgroundResource(R.drawable.kreis);
                turn = 0;
                felder[8] = 1;
                }
                else{
                    feld9.setBackgroundResource(R.drawable.kreuz);
                    turn = 1;
                    felder[8] = 0;
                }

        }
    });


}

public int getTurn() {
    int whois = turn;
    return whois;
}

public void checkWinner(){
    if(felder[0]==1 & felder[1]==1 & felder[2]==1){
        ergebnis.setText(R.string.kreuz);

    }else
    { }

}
}

Logcat:

    11-13 12:26:55.579: I/ActivityManager(88): START {act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=de.android.pali/.TicTacToeMenu} from pid 772
11-13 12:26:55.589: W/WindowManager(88): Failure taking screenshot for (180x300) to layer 21005
11-13 12:26:55.629: D/AndroidRuntime(772): Shutting down VM
11-13 12:26:55.639: D/dalvikvm(772): GC_CONCURRENT freed 101K, 77% free 485K/2048K, paused 1ms+1ms
11-13 12:26:55.649: D/dalvikvm(772): Debugger has detached; object registry had 1 entries
11-13 12:26:55.659: D/dalvikvm(782): Not late-enabling CheckJNI (already on)
11-13 12:26:55.669: I/AndroidRuntime(772): NOTE: attach of thread 'Binder Thread #3' failed
11-13 12:26:55.719: I/ActivityManager(88): Start proc de.android.pali for activity de.android.pali/.TicTacToeMenu: pid=782 uid=10045 gids={}
11-13 12:26:55.948: W/NetworkManagementSocketTagger(88): setKernelCountSet(10045, 1) failed with errno -2
11-13 12:26:56.449: I/Process(88): Sending signal. PID: 782 SIG: 3
11-13 12:26:56.449: I/dalvikvm(782): threadid=3: reacting to signal 3
11-13 12:26:56.569: I/dalvikvm(782): Wrote stack traces to '/data/anr/traces.txt'
11-13 12:26:56.819: D/gralloc_goldfish(782): Emulator without GPU emulation detected.
11-13 12:26:56.868: I/ActivityManager(88): Displayed de.android.pali/.TicTacToeMenu: +1s263ms (total +37s914ms)
11-13 12:26:57.088: W/NetworkManagementSocketTagger(88): setKernelCountSet(10009, 0) failed with errno -2
11-13 12:27:00.828: I/ActivityManager(88): START {cmp=de.android.pali/.newGame} from pid 782
11-13 12:27:00.838: W/WindowManager(88): Failure taking screenshot for (180x300) to layer 21010
11-13 12:27:00.868: D/AndroidRuntime(782): Shutting down VM
11-13 12:27:00.868: W/dalvikvm(782): threadid=1: thread exiting with uncaught exception (group=0x409c01f8)
11-13 12:27:00.889: E/AndroidRuntime(782): FATAL EXCEPTION: main
11-13 12:27:00.889: E/AndroidRuntime(782): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{de.android.pali/de.android.pali.newGame}: java.lang.NullPointerException
11-13 12:27:00.889: E/AndroidRuntime(782):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1880)
11-13 12:27:00.889: E/AndroidRuntime(782):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
11-13 12:27:00.889: E/AndroidRuntime(782):  at android.app.ActivityThread.access$600(ActivityThread.java:123)
11-13 12:27:00.889: E/AndroidRuntime(782):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
11-13 12:27:00.889: E/AndroidRuntime(782):  at android.os.Handler.dispatchMessage(Handler.java:99)
11-13 12:27:00.889: E/AndroidRuntime(782):  at android.os.Looper.loop(Looper.java:137)
11-13 12:27:00.889: E/AndroidRuntime(782):  at android.app.ActivityThread.main(ActivityThread.java:4424)
11-13 12:27:00.889: E/AndroidRuntime(782):  at java.lang.reflect.Method.invokeNative(Native Method)
11-13 12:27:00.889: E/AndroidRuntime(782):  at java.lang.reflect.Method.invoke(Method.java:511)
11-13 12:27:00.889: E/AndroidRuntime(782):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
11-13 12:27:00.889: E/AndroidRuntime(782):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
11-13 12:27:00.889: E/AndroidRuntime(782):  at dalvik.system.NativeStart.main(Native Method)
11-13 12:27:00.889: E/AndroidRuntime(782): Caused by: java.lang.NullPointerException
11-13 12:27:00.889: E/AndroidRuntime(782):  at android.app.Activity.findViewById(Activity.java:1794)
11-13 12:27:00.889: E/AndroidRuntime(782):  at de.android.pali.newGame.<init>(newGame.java:13)
11-13 12:27:00.889: E/AndroidRuntime(782):  at java.lang.Class.newInstanceImpl(Native Method)
11-13 12:27:00.889: E/AndroidRuntime(782):  at java.lang.Class.newInstance(Class.java:1319)
11-13 12:27:00.889: E/AndroidRuntime(782):  at android.app.Instrumentation.newActivity(Instrumentation.java:1023)
11-13 12:27:00.889: E/AndroidRuntime(782):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1871)
11-13 12:27:00.889: E/AndroidRuntime(782):  ... 11 more
11-13 12:27:00.929: W/ActivityManager(88):   Force finishing activity de.android.pali/.newGame
11-13 12:27:00.929: W/ActivityManager(88):   Force finishing activity de.android.pali/.TicTacToeMenu
11-13 12:27:01.359: I/Process(88): Sending signal. PID: 782 SIG: 3
11-13 12:27:01.359: I/dalvikvm(782): threadid=3: reacting to signal 3
11-13 12:27:01.379: I/dalvikvm(782): Wrote stack traces to '/data/anr/traces.txt'
11-13 12:27:01.439: W/ActivityManager(88): Activity pause timeout for ActivityRecord{415b08b0 de.android.pali/.newGame}
11-13 12:27:01.439: I/Process(88): Sending signal. PID: 782 SIG: 3
11-13 12:27:01.439: I/dalvikvm(782): threadid=3: reacting to signal 3
11-13 12:27:01.459: I/dalvikvm(782): Wrote stack traces to '/data/anr/traces.txt'
11-13 12:27:01.488: W/NetworkManagementSocketTagger(88): setKernelCountSet(10009, 1) failed with errno -2
11-13 12:27:01.748: W/NetworkManagementSocketTagger(88): setKernelCountSet(10045, 0) failed with errno -2
11-13 12:27:02.169: I/Process(782): Sending signal. PID: 782 SIG: 9
11-13 12:27:02.178: I/ActivityManager(88): Process de.android.pali (pid 782) has died.
11-13 12:27:02.178: W/InputDispatcher(88): channel '415c53c8 de.android.pali/de.android.pali.TicTacToeMenu (server)' ~ Consumer closed input channel or an error occurred.  events=0x8
11-13 12:27:02.178: E/InputDispatcher(88): channel '415c53c8 de.android.pali/de.android.pali.TicTacToeMenu (server)' ~ Channel is unrecoverably broken and will be disposed!
11-13 12:27:02.189: I/WindowManager(88): WIN DEATH: Window{415c53c8 de.android.pali/de.android.pali.TicTacToeMenu paused=true}
11-13 12:27:02.189: W/InputDispatcher(88): Attempted to unregister already unregistered input channel '415c53c8 de.android.pali/de.android.pali.TicTacToeMenu (server)'
11-13 12:27:02.199: I/WindowManager(88): WINDOW DIED Window{415c53c8 de.android.pali/de.android.pali.TicTacToeMenu paused=true}
11-13 12:27:02.359: W/InputManagerService(88): Got RemoteException sending setActive(false) notification to pid 782 uid 10045
11-13 12:27:11.749: W/ActivityManager(88): Activity destroy timeout for  ActivityRecord{415a28b8 de.android.pali/.TicTacToeMenu}
11-13 12:27:11.749: W/ActivityManager(88): Activity destroy timeout for ActivityRecord{415b08b0 de.android.pali/.newGame}

I hope anyone can help 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T00:08:46+00:00Added an answer on June 15, 2026 at 12:08 am

    This line of your logcat is showing where in your code the error is:

    11-13 12:27:00.889: E/AndroidRuntime(782):  at de.android.pali.newGame.<init>(newGame.java:13)
    

    This appears to relate to this:

    feld1.setOnClickListener(new OnClickListener() {
    
        @Override
        public void onClick(View v) {
    ....
    

    For some reason, it isn’t finding feld1 when you call final ImageButton feld1 = (ImageButton)findViewById(R.id.feld1);. Are you sure this is the right ID for the ImageButton on that layout file (game)?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
I'm trying to select an H1 element which is the second-child in its group
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
Does anyone know how can I replace this 2 symbol below from the string
Basically, what I'm trying to create is a page of div tags, each has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.