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

  • Home
  • SEARCH
  • 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 8028585
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T00:10:48+00:00 2026-06-05T00:10:48+00:00

i have 2 class. One is MainBaby.java and it contains: public class MainBaby extends

  • 0

i have 2 class. One is MainBaby.java and it contains:

public class MainBaby extends SurfaceView implements SurfaceHolder.Callback {

public MainBaby(Context context){
    super(context);
    init();
}

public MainBaby(Context context, AttributeSet attrs) {
      super(context, attrs);
      // TODO Auto-generated constructor stub
      init();
}

public MainBaby(Context context, AttributeSet attrs, int defStyle) {
      super(context, attrs, defStyle);
      // TODO Auto-generated constructor stub
      init();
}

public void init(){
    // adding the callback (this) to the surface holder to intercept events

    getHolder().addCallback(this);

    // create the game loop thread
    thread = new ThreadBaby(getHolder(), this);

    mPath = new Path();
    mBitmapPaint = new Paint(Paint.DITHER_FLAG);
    p = new Paint();
    p.setAntiAlias(true);
    p.setDither(true);
    p.setColor(Color.BLACK);
    p.setStyle(Paint.Style.STROKE);
    p.setStrokeJoin(Paint.Join.ROUND);
    p.setStrokeCap(Paint.Cap.ROUND);
    p.setStrokeWidth(50);

    setFocusable(true);

}

public void callMe(){

    Log.v("tag", "the button successfully pressed");
}   
}

this class in inflated in main.xml

<AbsoluteLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
  <coba.gesture.Main
    android:id="@+id/LayoDalam"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" />
</AbsoluteLayout>

and i want to call method callMe() at cobaGesture.java like this:

public class CobaGesture extends Activity {
MainBaby mb;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);  
    ImageButton resetBut = (ImageButton) findViewById(R.id.reset);
    resetBut.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            mb.callMe();
        }
    });      
}

but when i click the button, the application was force closed and here’s the logcat:

05-30 10:55:58.433: ERROR/AndroidRuntime(704): FATAL EXCEPTION: main
05-30 10:55:58.433: ERROR/AndroidRuntime(704): java.lang.NullPointerException
05-30 10:55:58.433: ERROR/AndroidRuntime(704):     at coba.gesture.CobaGesture$1.onClick(CobaGesture.java:41)
05-30 10:55:58.433: ERROR/AndroidRuntime(704):     at android.view.View.performClick(View.java:2485)
05-30 10:55:58.433: ERROR/AndroidRuntime(704):     at android.view.View$PerformClick.run(View.java:9080)
05-30 10:55:58.433: ERROR/AndroidRuntime(704):     at android.os.Handler.handleCallback(Handler.java:587)
05-30 10:55:58.433: ERROR/AndroidRuntime(704):     at android.os.Handler.dispatchMessage(Handler.java:92)
05-30 10:55:58.433: ERROR/AndroidRuntime(704):     at android.os.Looper.loop(Looper.java:123)
05-30 10:55:58.433: ERROR/AndroidRuntime(704):     at android.app.ActivityThread.main(ActivityThread.java:3647)
05-30 10:55:58.433: ERROR/AndroidRuntime(704):     at java.lang.reflect.Method.invokeNative(Native Method)
05-30 10:55:58.433: ERROR/AndroidRuntime(704):     at java.lang.reflect.Method.invoke(Method.java:507)
05-30 10:55:58.433: ERROR/AndroidRuntime(704):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
05-30 10:55:58.433: ERROR/AndroidRuntime(704):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
05-30 10:55:58.433: ERROR/AndroidRuntime(704):     at dalvik.system.NativeStart.main(Native Method)

what does it means? and how to solve it?

thank you in advance.

UPDATE!
here’s the edited code and the error:
enter image description here

  • 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-05T00:10:51+00:00Added an answer on June 5, 2026 at 12:10 am

    You should initial object with the correct context (in this case, it is your activity). So it is:

      mb = new MainBaby(CobaGesture.this);
    OR:
      mb = new MainBaby(getApplicationContext());
    

    Put this code into onClick event or onCreate, so you can use mb.callMe();

    All about the context is here and from Android document

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

Sidebar

Related Questions

Hi have one class like this import java.util.ArrayList; public class MobilePhone { private String
I have class which have one public method Start , one private method and
I have some questions regarding java finalization. For example I have one class FileHelper
I have one class which contains two more classes like hierarchy. When I'm displaying
I have one class called Person that basically looks like: public class Person {
I have one class that declares an enumeration type as: public enum HOME_LOAN_TERMS {FIFTEEN_YEAR,
I have following class with one static method: public class Helper { public static
So assume I have one class named Program which contains my whole program of
I have one class named A and one class B public class A :
I have one class called HyperlinkEventMonitor that implements a HyperlinkListener. I want to extend

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.