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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T19:39:32+00:00 2026-05-27T19:39:32+00:00

I am getting a fatal error in an application that I have been working

  • 0

I am getting a fatal error in an application that I have been working on. The log file and code is as follows. From what I can tell it is not even getting to the main activity.

Log File:

Shutting down VM
threadid=1: thread exiting with uncaught exception (group=0x401db760)
FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{A3.cal/A3.cal.A3Activity}: java.lang.NullPointerException
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1739)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1831)
    at android.app.ActivityThread.access$500(ActivityThread.java:122)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1024)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:132)
    at android.app.ActivityThread.main(ActivityThread.java:4123)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:491)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
    at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
    at android.content.ContextWrapper.getResources(ContextWrapper.java:81)
    at android.view.View.<init>(View.java:2366)
    at android.view.View.<init>(View.java:2411)
    at android.widget.TextView.<init>(TextView.java:371)
    at android.widget.Button.<init>(Button.java:108)
    at android.widget.Button.<init>(Button.java:104)
    at android.widget.Button.<init>(Button.java:100)
    at A3.cal.A3Activity.<init>(A3Activity.java:32)
    at java.lang.Class.newInstanceImpl(Native Method)
    at java.lang.Class.newInstance(Class.java:1301)
    at android.app.Instrumentation.newActivity(Instrumentation.java:1022)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1730)
    ... 11 more

Code:

package A3.cal;

import java.util.Calendar;
import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.view.Display;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup.LayoutParams;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.TimePicker;

public class A3Activity extends Activity {
    public int currentMonth = 0;
    private TextView[] dayTableTV = new TextView[6*7]; 
    private Integer[] dayTable = null;
    public Integer currentYear = 0;
    public int firstDayOfWeek = 0;
    public boolean leapYear = false;
    private PopupWindow createEventPopup = null;
    boolean click = false;
    private Button closeAddEventButton = new Button(this);
    private Button submitAddEventButton = new Button(this);

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

        Button addEvent = (Button) findViewById(R.id.addEvent);
        addEvent.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                if(click == false){
                    addEventPopup();
                    click = true;
                }else{
                    createEventPopup.dismiss();
                    click = false;
                }
            }
        });

        Button nextMonthButton = (Button) findViewById(R.id.nextMonthButton);
        nextMonthButton.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
               changeMonthNext(getMonth(currentMonth, 1));
            }
        });

        Button previousMonthButton = (Button) findViewById(R.id.previousMonthButton);
        previousMonthButton.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
               changeMonthBack(getMonth(currentMonth, -1));
            }
        });

        closeAddEventButton.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                createEventPopup.dismiss();
            }
        });

        submitAddEventButton.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
               submitEvent();
            }

        });

    }

There is more code after this, but for saving characters I am not posting it. If you need it please let me know in the comments.

  • 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-27T19:39:33+00:00Added an answer on May 27, 2026 at 7:39 pm

    Initialize your buttons elsewhere, like in onCreate.


    The problem is this‘s (the A3Activity) state when the Button instances are instantiated in the instance variable initializers (closeAddEventButton and submitAddEventButton).

    Instance variable initializers run before constructors, but an object is not completely initialized until its constructor(s) are executed. Objects referenced prior to that will be in an indeterminate state.

    (The state could be determined; I just mean the instance may not be fully-usable yet.)

    Something in the Button initialization flow uses an uninitialized value from the A3Activity and throws an NPE. (JLS 12.5: Creation of New Class Instances details instance initialization process.)

    Noting that initializers run in textual order (JLS 12.4.2), before constructors, here’s a simple demo:

    public class ThisHere {
        public String aww;
        public String notYet = this.aww;
    
        GedankenExperiment wat = new GedankenExperiment(this);
    
        // public class GedankenExperiment {
        //     public GedankenExperiment(thatThere) {
        //         thatThere.aww = ???
        //     }
        // }
    
        public ThisHere() {
            this.aww = "Hi there";
        }
    
        public static void main(String[] args) {
            ThisHere thisHere = new ThisHere();
            System.out.println("aww=" + thisHere.aww);
            // > aww=Hi there (initialized in ctor)
            System.out.println("notYet=" + thisHere.notYet);
            // > notYet=null (initialized before ctor)
        }
    }
    

    FYI, the tell-tale sign was this log line:

    at A3.cal.A3Activity.<init>(A3Activity.java:32)
    

    This is the only log line I really saw, because my first step was looking for a reference to anything outside of Android and Java packages. The <init> part means it wasn’t in a method, so it had something to do with the instance’s initializers.

    The stack trace included Button initializer entries. That plus the use of this in their constructors meant that was the only real possibility, hence the quick turn-around without much digging.

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

Sidebar

Related Questions

I'm getting this weird error in my Zend application with this piece of code:
i'm getting a Finalizing a Cursor that has not been deactivated or closed error
Copied a working website from one server to another, now I'm getting this error
I am getting a fatal error in a CI app that I just moved
I am getting the error OperationalError: FATAL: sorry, too many clients already when using
Getting the above error in following code. How to rectify it. Thanks. Please look
Getting this error with jquery & jquery.form. Site has been live for awhile..upgraded to
One of the requirements for the application that I'm working on is to enable
I'm getting an error when my application starts. It appears to be after it's
I don't totally understand how all this works, but I'm getting this error: Fatal

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.