title: java.lang.RuntimeException: Unable to instantiate activity...(android studio)
body: <p>i was learning in tutorial <em>todolist</em>, but have problem with app. Emulator and my phone show "<em>todolist4 has stopped</em>". 
  In "Sync" all in green, but in logcat show some errors. I watched different answers, but they didn't help me. I tried to change firmware in emulator and app, but it too didn't solved problem.</p>
  
  <pre><code>    public class MainActivity extends AppCompatActivity {//ActivityAppCompatActivity
  
  List&lt;ToDo&gt; toDoList = new ArrayList&lt;&gt;();
  FirebaseFirestore db;
  
  RecyclerView listItem;
  RecyclerView.LayoutManager layoutManager;
  
  FloatingActionButton fab;
  
  public MaterialEditText title, description;
  public boolean isUpdate = false;
  public String idUpdate = "";
  
  ListItemAdapter adapter;
  
  //AlertDialog dialog;
  android.app.AlertDialog dialog=new SpotsDialog(MainActivity.this);
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(com.example.sud.todolist4.R.layout.activity_main);
  
  
      //Init FireStore
      db = FirebaseFirestore.getInstance();
  
      //View
      dialog = new SpotsDialog(this);
      title = (MaterialEditText)findViewById(com.example.sud.todolist4.R.id.title);
      description = (MaterialEditText)findViewById(com.example.sud.todolist4.R.id.description);
      fab = (FloatingActionButton)findViewById(com.example.sud.todolist4.R.id.fab);
      fab.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
              //Add New
  
              if(!isUpdate)
              {
                  setData(title.getText().toString(), description.getText().toString());
              }
              else
              {
                  updateData(title.getText().toString(), description.getText().toString());
                  isUpdate = !isUpdate; //reset flag
              }
  
          }
  
      });
  
      listItem = (RecyclerView)findViewById(com.example.sud.todolist4.R.id.listTodo);
      listItem.setHasFixedSize(true);
      layoutManager = new LinearLayoutManager(this);
      listItem.setLayoutManager(layoutManager);
  
      loadData(); //load data from FireStore
  }
  
  @Override
  public boolean onContextItemSelected(MenuItem item) {
      if (item.getTitle().equals("DELETE"))
          deleteItem(item.getOrder());
      return super.onContextItemSelected(item);
  }
  private void deleteItem(int index) {
      db.collection("ToDoList")
              .document(toDoList.get(index).getId())
              .delete()
              .addOnSuccessListener(new OnSuccessListener&lt;Void&gt;() {
                  @Override
                  public void onSuccess(Void aVoid) {
                      loadData();
                  }
              });
  }
  private void updateData(String title, String description) {
      db.collection("ToDoList").document(idUpdate)
              .update("title",title,"descripton",description)
              .addOnSuccessListener(new OnSuccessListener&lt;Void&gt;() {
                  @Override
                  public void onSuccess(Void aVoid) {
                      Toast.makeText(MainActivity.this, "Updated !", Toast.LENGTH_SHORT).show();
                  }
              });
  
      //Realtime update refresh data;
      db.collection("ToDoList").document(idUpdate)
              .addSnapshotListener(new EventListener&lt;DocumentSnapshot&gt;() {
                  @Override
                  public void onEvent(@Nullable DocumentSnapshot documentSnapshot, @Nullable FirebaseFirestoreException e) {
                      loadData();
                  }
              });
  
  }
  private void setData(String title, String description) {
      //Random id
      String id = UUID.randomUUID().toString();
      Map&lt;String, Object&gt; todo = new HashMap&lt;&gt;();
      todo.put("id", id );
      todo.put("title", title );
      todo.put("description", description );
  
      db.collection("ToDoList").document(id)
              .set(todo).addOnSuccessListener(new OnSuccessListener&lt;Void&gt;() {
          @Override
          public void onSuccess(Void aVoid) {
              //Refresh data;
              loadData();
          }
      });
  }
  private void loadData() {
      dialog.show();
      if(toDoList.size() &gt; 0)
          toDoList.clear(); //Remove old value
      db.collection("ToDoList")
              .get()
              .addOnCompleteListener(new OnCompleteListener&lt;QuerySnapshot&gt;()
              {
                  @Override
                  public void onComplete(@NonNull Task&lt;QuerySnapshot&gt; task)
                  {
                      for(DocumentSnapshot doc:task.getResult())
                      {
                          ToDo todo = new ToDo(doc.getString("id"),
                                  doc.getString("title"),
                                  doc.getString("description"));
                          toDoList.add(todo);
                      }
                      adapter = new ListItemAdapter(MainActivity.this,toDoList);
                      listItem.setAdapter(adapter);
                      dialog.dismiss();
  
                  }
              })
              .addOnFailureListener(new OnFailureListener() {
                  @Override
                  public void onFailure(@NonNull Exception e) {
                      Toast.makeText(MainActivity.this, ""+e.getMessage(), Toast.LENGTH_SHORT).show();
                  }
              });
  }}
  </code></pre>
  
  <p>LogCat</p>
  
  <pre><code>04-24 16:33:44.697 16627-16627/com.example.sud.todolist4 E/AndroidRuntime: FATAL EXCEPTION: main
  Process: com.example.sud.todolist4, PID: 16627
  java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.sud.todolist4/com.example.sud.todolist4.MainActivity}: java.lang.IllegalStateException: System services not available to Activities before onCreate()
      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2679)
      at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2856)
      at android.app.ActivityThread.-wrap11(Unknown Source:0)
      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1589)
      at android.os.Handler.dispatchMessage(Handler.java:106)
      at android.os.Looper.loop(Looper.java:164)
      at android.app.ActivityThread.main(ActivityThread.java:6494)
      at java.lang.reflect.Method.invoke(Native Method)
      at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
   Caused by: java.lang.IllegalStateException: System services not available to Activities before onCreate()
      at android.app.Activity.getSystemService(Activity.java:5915)
      at android.app.Dialog.&lt;init&gt;(Dialog.java:183)
      at android.app.AlertDialog.&lt;init&gt;(AlertDialog.java:201)
      at android.app.AlertDialog.&lt;init&gt;(AlertDialog.java:197)
      at dmax.dialog.SpotsDialog.&lt;init&gt;(SpotsDialog.java:39)
      at dmax.dialog.SpotsDialog.&lt;init&gt;(SpotsDialog.java:25)
      at com.example.sud.todolist4.MainActivity.&lt;init&gt;(MainActivity.java:55)
      at java.lang.Class.newInstance(Native Method)
      at android.app.Instrumentation.newActivity(Instrumentation.java:1174)
      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2669)
      at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2856) 
      at android.app.ActivityThread.-wrap11(Unknown Source:0) 
      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1589) 
      at android.os.Handler.dispatchMessage(Handler.java:106) 
      at android.os.Looper.loop(Looper.java:164) 
      at android.app.ActivityThread.main(ActivityThread.java:6494) 
      at java.lang.reflect.Method.invoke(Native Method) 
      at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438) 
      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
  </code></pre>
  
  <p>Manifest</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  </code></pre>
  
  <p></p>
  
  <pre><code>&lt;application
      android:allowBackup="true"
      android:icon="@mipmap/ic_launcher"
      android:label="@string/app_name"
      android:roundIcon="@mipmap/ic_launcher_round"
      android:supportsRtl="true"
      android:theme="@style/AppTheme"&gt;
      &lt;uses-library android:name="com.google.android.maps" /&gt;
      &lt;activity android:name=".MainActivity"&gt;
          &lt;intent-filter&gt;
              &lt;action android:name="android.intent.action.MAIN" /&gt;
  
              &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
          &lt;/intent-filter&gt;
      &lt;/activity&gt;
  &lt;/application&gt;
  </code></pre>
  
  <p></p>