title: FATAL EXCEPTION: main....java.lang.RuntimeException: Unable to instantiate activity ComponentInfo.?
body: <p>I'm very new to Android Studio and I know a little java.So I'm trying a simple calculator app with simple layout.I hope all my code is correct but I don't know what's wrong in it.When I run the app it is not at all opening and showing a FATAL exception main.Here is the xml code,java code and logcat of my app.So please help me to make corrections.Thanks!</p>
  
  <p>XML Code ::</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;android.support.constraint.ConstraintLayoutxmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:app="http://schemas.android.com/apk/res-auto"
  xmlns:tools="http://schemas.android.com/tools"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:background="@color/colorPrimary"
  tools:context="com.example.narendra.calculator.MainActivity"
  tools:layout_editor_absoluteY="81dp"
  tools:layout_editor_absoluteX="0dp"&gt;
  
  
  &lt;EditText
      android:id="@+id/editText"
      android:layout_width="360dp"
      android:layout_height="159dp"
      android:background="@android:color/holo_blue_light"
      android:ems="10"
      android:hint="@string/num"
      android:inputType="number"
      android:textAlignment="center"
      android:textAllCaps="true"
      android:textSize="50sp"
      android:textStyle="bold"
      tools:ignore="MissingConstraints,RtlHardcoded"
      app:layout_constraintTop_toTopOf="parent"
      android:layout_marginTop="16dp"
      app:layout_constraintRight_toRightOf="parent"
      app:layout_constraintLeft_toLeftOf="parent"
      android:layout_marginRight="8dp"
      android:layout_marginLeft="8dp"
      android:layout_marginStart="8dp"
      android:layout_marginEnd="8dp" /&gt;
  
  &lt;EditText
      android:id="@+id/editText2"
      android:layout_width="360dp"
      android:layout_height="159dp"
      android:background="@android:color/holo_green_light"
      android:ems="10"
      android:hint="@string/Num2"
      android:inputType="number"
      android:textAlignment="center"
      android:textAllCaps="true"
      android:textSize="50sp"
      android:textStyle="bold"
      tools:ignore="MissingConstraints,RtlHardcoded"
      tools:layout_editor_absoluteY="180dp"
      tools:layout_editor_absoluteX="26dp" /&gt;
  
  &lt;Button
      android:id="@+id/button"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:onClick="onAddButtonClick"
      android:text="@string/a"
      android:textSize="50sp"
      app:layout_constraintLeft_toLeftOf="@+id/editText2"
      app:layout_constraintTop_toTopOf="@+id/editText"
      android:layout_marginTop="323dp"
      tools:ignore="RtlHardcoded"
      app:layout_constraintRight_toLeftOf="@+id/button3"
      app:layout_constraintHorizontal_bias="0.0"
      android:layout_marginRight="5dp"
      android:layout_marginEnd="5dp" /&gt;
  
  &lt;Button
      android:id="@+id/button2"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:onClick="onSubtractionButtonClick"
      android:text="@string/m"
      android:textSize="50sp"
      android:layout_marginLeft="5dp"
      app:layout_constraintTop_toTopOf="@+id/editText"
      android:layout_marginTop="323dp"
      tools:ignore="RtlHardcoded"
      app:layout_constraintLeft_toRightOf="@+id/button"
      app:layout_constraintHorizontal_bias="0.03"
      android:layout_marginRight="5dp"
      app:layout_constraintRight_toRightOf="@+id/button3"
      android:layout_marginStart="5dp"
      android:layout_marginEnd="5dp" /&gt;
  
  &lt;Button
      android:id="@+id/button3"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:onClick="onMultiplicationButtonClick"
      android:text="@string/p"
      android:textSize="50sp"
      android:layout_marginLeft="5dp"
      app:layout_constraintTop_toTopOf="@+id/editText"
      android:layout_marginTop="323dp"
      tools:ignore="RtlHardcoded"
      app:layout_constraintLeft_toRightOf="@+id/button2"
      android:layout_marginRight="5dp"
      app:layout_constraintRight_toRightOf="@+id/button4"
      app:layout_constraintHorizontal_bias="0.0"
      android:layout_marginStart="5dp"
      android:layout_marginEnd="5dp" /&gt;
  
  &lt;Button
      android:id="@+id/button4"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:onClick="onDivisionButtonClick"
      android:text="@string/d"
      android:textSize="50sp"
      android:layout_marginLeft="5dp"
      app:layout_constraintRight_toRightOf="@+id/editText2"
      app:layout_constraintTop_toTopOf="@+id/editText"
      android:layout_marginTop="323dp"
      tools:ignore="RtlHardcoded"
      app:layout_constraintLeft_toRightOf="@+id/button3"
      app:layout_constraintHorizontal_bias="0.0"
      android:layout_marginStart="5dp"
      android:layout_marginRight="5dp" /&gt;
  
  &lt;TextView
      android:id="@+id/textView"
      android:layout_width="360dp"
      android:layout_height="100dp"
      android:layout_marginBottom="8dp"
      android:layout_marginLeft="8dp"
      android:layout_marginRight="16dp"
      android:layout_marginTop="8dp"
      android:background="@color/colorAccent"
      android:text="@string/Result"
      android:textAlignment="center"
      android:textAllCaps="true"
      android:textSize="50sp"
      android:textStyle="bold"
      app:layout_constraintBottom_toBottomOf="parent"
      app:layout_constraintHorizontal_bias="0.771"
      app:layout_constraintLeft_toLeftOf="parent"
      app:layout_constraintRight_toRightOf="parent"
      app:layout_constraintTop_toTopOf="parent"
      app:layout_constraintVertical_bias="0.839"
      tools:ignore="RtlHardcoded" /&gt;
  </code></pre>
  
  <p></p>
  
  <p>Java Code ::</p>
  
  <pre><code>package com.example.narendra.calculator;
  
  import android.support.v7.app.AppCompatActivity;
  import android.os.Bundle;
  import android.view.View;
  import android.widget.EditText;
  import android.widget.TextView;
  import android.widget.Toast;
  
  public class MainActivity extends AppCompatActivity {
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
  }
  EditText e1=(EditText)findViewById(R.id.editText);
  EditText e2=(EditText)findViewById(R.id.editText2);
  TextView t1=(TextView)findViewById(R.id.textView);
  int num1=Integer.parseInt(e1.getText().toString());
  int num2=Integer.parseInt(e2.getText().toString());
  public void conditionCheck(){
      if(e1.getText().toString().isEmpty()){
          e1.setError("Please Enter a valid number");
      }
      else if(e2.getText().toString().isEmpty()){
          e2.setError("Please Enter a valid number");
      }
  }
  public void onAddButtonClick(View v){
      conditionCheck();
      int sum=num1+num2;
      t1.setText(sum);
      Toast.makeText(MainActivity.this, " Thank You ", Toast.LENGTH_SHORT).show();
  }
  public void onSubtractionButtonClick(View v){
      conditionCheck();
      int diff=num1-num2;
      t1.setText(diff);
      Toast.makeText(MainActivity.this, " Thank You ", Toast.LENGTH_SHORT).show();
  }
  public void onMultiplicationButtonClick(View v){
      conditionCheck();
      int product=num1*num2;
      t1.setText(product);
      Toast.makeText(MainActivity.this, " Thank You ", Toast.LENGTH_SHORT).show();
  }
  public void onDivisionButtonClick(View v){
      conditionCheck();
      if(num2==0){
          e2.setError(" Zero is not allowed here");
      }
      else {
          int quotient = num1 / num2;
          t1.setText(quotient);
          Toast.makeText(MainActivity.this, " Thank You ", Toast.LENGTH_SHORT).show();
      }
  }
  
  }
  </code></pre>
  
  <p>Logcat ::</p>
  
  <pre><code>    06-14 12:31:23.216 4822-4822/? I/art: Not late-enabling -Xcheck:jni (already on)
      06-14 12:31:23.216 4822-4822/? W/art: Unexpected CPU variant for X86 using defaults: x86
      06-14 12:31:23.342 4822-4822/? W/System: ClassLoader referenced unknown path: /data/app/com.example.narendra.calculator-2/lib/x86
      06-14 12:31:23.348 4822-4822/? I/InstantRun: starting instant run server: is main process
      06-14 12:31:23.405 4822-4822/? D/AndroidRuntime: Shutting down VM
      06-14 12:31:23.405 4822-4822/? E/AndroidRuntime: FATAL EXCEPTION: main
                                               Process: com.example.narendra.calculator, PID: 4822
                                               java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.narendra.calculator/com.example.narendra.calculator.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.Window$Callback android.view.Window.getCallback()' on a null object reference
                                                   at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2548)
                                                   at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2707)
                                                   at android.app.ActivityThread.-wrap12(ActivityThread.java)
                                                   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1460)
                                                   at android.os.Handler.dispatchMessage(Handler.java:102)
                                                   at android.os.Looper.loop(Looper.java:154)
                                                   at android.app.ActivityThread.main(ActivityThread.java:6077)
                                                   at java.lang.reflect.Method.invoke(Native Method)
                                                   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866)
                                                   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:756)
                                                Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.Window$Callback android.view.Window.getCallback()' on a null object reference
                                                   at android.support.v7.app.AppCompatDelegateImplBase.&lt;init&gt;(AppCompatDelegateImplBase.java:120)
                                                   at android.support.v7.app.AppCompatDelegateImplV9.&lt;init&gt;(AppCompatDelegateImplV9.java:155)
                                                   at android.support.v7.app.AppCompatDelegateImplV11.&lt;init&gt;(AppCompatDelegateImplV11.java:31)
                                                   at android.support.v7.app.AppCompatDelegateImplV14.&lt;init&gt;(AppCompatDelegateImplV14.java:55)
                                                   at android.support.v7.app.AppCompatDelegateImplV23.&lt;init&gt;(AppCompatDelegateImplV23.java:33)
                                                   at android.support.v7.app.AppCompatDelegateImplN.&lt;init&gt;(AppCompatDelegateImplN.java:33)
                                                   at android.support.v7.app.AppCompatDelegate.create(AppCompatDelegate.java:201)
                                                   at android.support.v7.app.AppCompatDelegate.create(AppCompatDelegate.java:185)
                                                   at android.support.v7.app.AppCompatActivity.getDelegate(AppCompatActivity.java:519)
                                                   at android.support.v7.app.AppCompatActivity.findViewById(AppCompatActivity.java:190)
                                                   at com.example.narendra.calculator.MainActivity.&lt;init&gt;(MainActivity.java:17)
                                                   at java.lang.Class.newInstance(Native Method)
                                                   at android.app.Instrumentation.newActivity(Instrumentation.java:1078)
                                                   at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2538)
                                                   at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2707) 
                                                   at android.app.ActivityThread.-wrap12(ActivityThread.java) 
                                                   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1460) 
                                                   at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                   at android.os.Looper.loop(Looper.java:154) 
                                                   at android.app.ActivityThread.main(ActivityThread.java:6077) 
                                                   at java.lang.reflect.Method.invoke(Native Method) 
                                                   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866) 
                                                   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:756) 
  </code></pre>