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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T01:09:58+00:00 2026-05-31T01:09:58+00:00

Ok I have a simple main activity that just presents the user with a

  • 0

Ok I have a simple main activity that just presents the user with a button to click on and I will add more buttons later.
When I go to compile it compiles but it force closes immediately on my device.

Heres my Activity code followed by my logcat output.

package com.michaelpeerman.probability;


import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import com.michaelpeerman.probability.R;
public class MainActivity extends BaseActivity
{
  View.OnClickListener buttonhandler = new View.OnClickListener()
  {
    public void onClick(View v)
    {
      Intent localIntent;
      switch (v.getId())
      {
      case R.id.cointoss:

        localIntent = new Intent(MainActivity.this, CoinActivity.class);
        MainActivity.this.startActivity(localIntent);
        break;

      }
    }
  };

  public void onCreate(Bundle savedInstanceState)
  {
    super.onCreate(savedInstanceState);
    tracker.trackPageView("/ApplicationHomeScreen");
    setContentView(R.layout.main);
    Button localButton1 = (Button)findViewById(R.id.cointoss);
    //Button localButton2 = (Button)findViewById(R.id.doctor10);
    //Button localButton3 = (Button)findViewById(R.id.doctor11);
    localButton1.setOnClickListener(this.buttonhandler);
    //localButton2.setOnClickListener(this.buttonhandler);
    //localButton3.setOnClickListener(this.buttonhandler);
  }





}

Heres My LogCat Output.

03-08 18:29:12.664: E/AndroidRuntime(6467): FATAL EXCEPTION: main
03-08 18:29:12.664: E/AndroidRuntime(6467): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.michaelpeerman.probability/com.michaelpeerman.probability.MainActivity}: java.lang.NullPointerException
03-08 18:29:12.664: E/AndroidRuntime(6467):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956)
03-08 18:29:12.664: E/AndroidRuntime(6467):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
03-08 18:29:12.664: E/AndroidRuntime(6467):     at android.app.ActivityThread.access$600(ActivityThread.java:123)
03-08 18:29:12.664: E/AndroidRuntime(6467):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
03-08 18:29:12.664: E/AndroidRuntime(6467):     at android.os.Handler.dispatchMessage(Handler.java:99)
03-08 18:29:12.664: E/AndroidRuntime(6467):     at android.os.Looper.loop(Looper.java:137)
03-08 18:29:12.664: E/AndroidRuntime(6467):     at android.app.ActivityThread.main(ActivityThread.java:4424)
03-08 18:29:12.664: E/AndroidRuntime(6467):     at java.lang.reflect.Method.invokeNative(Native Method)
03-08 18:29:12.664: E/AndroidRuntime(6467):     at java.lang.reflect.Method.invoke(Method.java:511)
03-08 18:29:12.664: E/AndroidRuntime(6467):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
03-08 18:29:12.664: E/AndroidRuntime(6467):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
03-08 18:29:12.664: E/AndroidRuntime(6467):     at dalvik.system.NativeStart.main(Native Method)
03-08 18:29:12.664: E/AndroidRuntime(6467): Caused by: java.lang.NullPointerException
03-08 18:29:12.664: E/AndroidRuntime(6467):     at com.michaelpeerman.probability.MainActivity.onCreate(MainActivity.java:36)
03-08 18:29:12.664: E/AndroidRuntime(6467):     at android.app.Activity.performCreate(Activity.java:4465)
03-08 18:29:12.664: E/AndroidRuntime(6467):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
03-08 18:29:12.664: E/AndroidRuntime(6467):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
03-08 18:29:12.664: E/AndroidRuntime(6467):     ... 11 more

Heres base Activity

package com.michaelpeerman.probability;


import com.google.android.apps.analytics.GoogleAnalyticsTracker;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;

public class BaseActivity extends Activity {
private String donate_link = "market://details?id=com.michaelpeerman.donate";
private String rate_link = "market://details?id=com.michaelpeerman.probability";
private String more_apps = "market://search?q=pub:Michael Peerman";
private String sharetext = "Check out this amazing Probability app." + "\n"
        + "\n" + "http://goo.gl/yU3jy";
GoogleAnalyticsTracker tracker;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    tracker = GoogleAnalyticsTracker.getInstance();
    tracker.startNewSession("REMOVED", 60, this);
    }
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.menu, menu);
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case R.id.donate:
        tracker.trackEvent("Menu_Item", "donate", "clicked", 0);
        startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(donate_link)));
        break;
    case R.id.rate:
        tracker.trackEvent("Menu_Item", "rate", "clicked", 0);
        startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(rate_link)));
        break;
    case R.id.moreapps:
        tracker.trackEvent("Menu_Item", "more_apps", "clicked", 0);
        startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(more_apps)));
        break;
    case R.id.share:
        tracker.trackEvent("Menu_Item", "share", "clicked", 0);
        Intent sharingIntent = new Intent(Intent.ACTION_SEND);
        sharingIntent.setType("text/plain");
        sharingIntent
                .putExtra(android.content.Intent.EXTRA_TEXT, sharetext);
        startActivity(Intent.createChooser(sharingIntent, "Share using"));
        break;
    }
    return true;
}
@Override
public void onPause() {
     super.onPause();
     tracker.dispatch();


 }
@Override
 public void onDestroy() {
     super.onDestroy();
     tracker.dispatch();
     tracker.stopSession();

 }
}

And heres Main.xml

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >
    <TableRow 
        android:background="@drawable/coin_toss_banner"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"></TableRow>
   <Button android:id="@+id/cointoss"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:text="Coin Toss" />
    </LinearLayout>
  • 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-31T01:09:59+00:00Added an answer on May 31, 2026 at 1:09 am

    EDIT: This has nothing to do with main.xml or the Button. The following line is throwing the null pointer:

    tracker.trackPageView("/ApplicationHomeScreen");
    

    Looking at BaseActivity there is no access modifier specified for tracker, so it takes on the default access modifier, which apparently does not allow access to inheriting classes, even if they’re in the same package. Looking at your code, the two classes do seem to be in the same package. Regardless, explicitly defining tracker as protected will allow it to be accessed from inheriting classes, regardless of package.

    I’m still a little stumped by this. As far as I’m concerned it shouldn’t have compiled. Somehow the tracker variable is accessible, but the instantiation of it is not…any Java experts lurking to shed some light?

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

Sidebar

Related Questions

I have a simple main activity with 3 buttons, and a background service that
I have one simple widget consisting in a simple button that launches the main
What i have here is a simple webview activity that when loaded it auto
Im kinda stuck. I have an activity in my app that just wont go
I have some main activity and clicking on a button it launches a custom
I have a simple ViewPager example that just places a TextView with the current
I have following goal: From a list in main activity that extends ListActivity, I
I am using jQuery for a simple website and have a main page 'index.html'
I have simple win service, that executes few tasks periodically. How should I pass
I have a problem on going back (clicking the Back button) from sub-activity to

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.