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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T02:30:23+00:00 2026-05-23T02:30:23+00:00

I am making an application for android which could grow somewhat large over time.

  • 0

I am making an application for android which could grow somewhat large over time. What I would like to do is implement into the main class sub files for logic. For example:

The main activity uses a surfaceview.

class Battle extends SurfaceView implements SurfaceHolder.Callback {

I want to add all logic related to touch events in a file called touchActions.java

public class touchActions extends Battle {

It appears to work fine with no errors in Eclipse. But when I try to run it on my phone, I get a null pointer exception for the following line.

if (_touch.checkHitBox(1)) {

_touch being initiated after the Battle class is declared.

public touchActions _touch;

What is the proper way to do this, or what could be causing the nullpointerexception?

EDIT:

The goal here is organization of code, so that I don’t end up with one gigantic file of code. Can I make an inner class while still using a different file? If you know of a tutorial, that would be great too.

  • 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-23T02:30:24+00:00Added an answer on May 23, 2026 at 2:30 am

    _touch being initiated after the Battle class is declared.

    public touchActions _touch;

    not initiated … just declared u need to initiatie it with something like this

    _touch = new touchActions();
    

    EDIT:

    if public touchActions _touch; is declared in Battle class you do it all wrong …

    it should be something like this

    class Battle extends SurfaceView implements SurfaceHolder.Callback {
       public touchActions _touch;
       public Battle (){
         _touch = new touchActions(this);
         _touch.callingMethodFromTouch();
       }
    }
    
    //should not extends Battle
    public class touchActions {
      Battle parent_;
      public touchActions (Battle parent){
         parent_ = parent;
      }
    
      .... rest of implemetation you can call parent_.methodFromBattleClass(); here
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am making an application for a windows mobile smartphone, and I would like
I will be making a mobile application in Android. My application is like Google
I am making an android application in which i have five items in a
Im making a client application for my ZTE Blade Android phone, which receives a
I am making an small application in android in which i used an image
I am making an android application in which I have put 10 images and
I am an android developer.I am making an application in which I have to
I m making an application in ANDROID which will be used at two ends.
im making an android application which requires a user to register using a form
I'm making an android application in which I want to show Punjabi text in

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.