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 7547835
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T09:33:20+00:00 2026-05-30T09:33:20+00:00

Basically, I’m making a reversi app for Android, and I am currently at the

  • 0

Basically, I’m making a reversi app for Android, and I am currently at the point of setting up the game board. The way I am intending to do this is to create a 2D array of the position class. Each position is represented by an imageview that is used as a button which represents a board position. Here is a snippet of the code that contains the error:

setupBoard(board);
....
public void setupBoard(Position board[][]) {
    for (int y = 0; y < 8; y++) {
        for (int x = 0; x < 8; x++) {
            Log.d("Error","Error a");
            board[x][y] = new Position(getApplicationContext());
            Log.d("Error","Error b");
            board[x][y].isPositionEmpty = true;

        }
    }
}

In the position class:

public class Position {

Context myContext;
public Position(Context context) {
    Log.d("Error","Error c");
    myContext = context;
    // TODO Auto-generated constructor stub

}


public boolean isPositionEmpty = true;
public int positionID;


public  ImageView button = new ImageView(myContext);

}

The program gets to error a, but no further. The error in LogCat is:
java.lang.NullPointerException

Any help will be much appreciated. Thanks in advance!

Exception:
02-20 16:52:20.820: ERROR/AndroidRuntime(365): FATAL EXCEPTION: main
02-20 16:52:20.820: ERROR/AndroidRuntime(365): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{trinity.hazard.reversi/trinity.hazard.reversi.SinglePlayerActivity}: java.lang.NullPointerException
02-20 16:52:20.820: ERROR/AndroidRuntime(365): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2585)
02-20 16:52:20.820: ERROR/AndroidRuntime(365): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
02-20 16:52:20.820: ERROR/AndroidRuntime(365): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
02-20 16:52:20.820: ERROR/AndroidRuntime(365): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
02-20 16:52:20.820: ERROR/AndroidRuntime(365): at android.os.Handler.dispatchMessage(Handler.java:99)
02-20 16:52:20.820: ERROR/AndroidRuntime(365): at android.os.Looper.loop(Looper.java:123)
02-20 16:52:20.820: ERROR/AndroidRuntime(365): at android.app.ActivityThread.main(ActivityThread.java:4627)
02-20 16:52:20.820: ERROR/AndroidRuntime(365): at java.lang.reflect.Method.invokeNative(Native Method)
02-20 16:52:20.820: ERROR/AndroidRuntime(365): at java.lang.reflect.Method.invoke(Method.java:521)
02-20 16:52:20.820: ERROR/AndroidRuntime(365): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
02-20 16:52:20.820: ERROR/AndroidRuntime(365): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
02-20 16:52:20.820: ERROR/AndroidRuntime(365): at dalvik.system.NativeStart.main(Native Method)
02-20 16:52:20.820: ERROR/AndroidRuntime(365): Caused by: java.lang.NullPointerException
02-20 16:52:20.820: ERROR/AndroidRuntime(365): at android.content.ContextWrapper.getApplicationContext(ContextWrapper.java:100)
02-20 16:52:20.820: ERROR/AndroidRuntime(365): at trinity.hazard.reversi.SinglePlayerActivity.(SinglePlayerActivity.java:24)
02-20 16:52:20.820: ERROR/AndroidRuntime(365): at java.lang.Class.newInstanceImpl(Native Method)
02-20 16:52:20.820: ERROR/AndroidRuntime(365): at java.lang.Class.newInstance(Class.java:1429)
02-20 16:52:20.820: ERROR/AndroidRuntime(365): at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
02-20 16:52:20.820: ERROR/AndroidRuntime(365): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2577)
02-20 16:52:20.820: ERROR/AndroidRuntime(365): … 11 more

  • 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-05-30T09:33:21+00:00Added an answer on May 30, 2026 at 9:33 am

    In your Position class, try moving the line where you create the ImageView into the constructor, but AFTER initializing myContext.

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

Sidebar

Related Questions

Basically, I'm implemeting a reversi app for android for my year 13 coursework and
Basically I'm trying to improve on the Ghosts in a Pacman game I'm making.
Basically I have this server app I built in vc#, and for some reason
Basically what I want to do it this: a pdb file contains a location
Basically, something better than this: <input type=file name=myfile size=50> First of all, the browse
Basically, what I'm trying to create is a page of div tags, each has
Basically from a database I am getting data that is formatted like this nameofproject101
Basically I'm attempting to add rows to a table, I need to do this
Basically this function is meant to store the height value of the element that
Basically my task is to make the counter on a micro controller board count

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.