I'm new and learning android studio and understanding it more, but I'm stuck here. I can't reload my mainActivity using a button in a different class which has a custom Dialog. I've searched many solutions but none of them work, it always end up 'NullPointerException' error. Can anyone please help me understand this problem more.  this is my mainAcitivity  `  public class MainActivity extends AppCompatActivity {  DialogHandler dialogHandler; Context mainContext; Dialog dialog; @Override protected void onCreate(Bundle savedInstanceState) {     super.onCreate(savedInstanceState);     setContentView(R.layout.activity_main);      mainContext = this;     dialog = new Dialog(this);     dialogHandler = new DialogHandler(MainActivity.this);      Button showButton = (Button) findViewById(R.id.showButton);      showButton.setOnClickListener(new View.OnClickListener() {         @Override         public void onClick(View view) {             dialogHandler.showDialog(mainContext);         }     }); }   `  and this is my second class (DialogHandler)  '  public class DialogHandler {    Activity activity;    MainActivity mainActivity;    Dialog dialog;  public DialogHandler (Activity activity) {     this.activity = activity; }  public void showDialog (Context context) {     mainActivity = new MainActivity();     dialog = new Dialog(context);       dialog.setContentView(R.layout.activity_dialog);     dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));     dialog.show();      Button changeButton = dialog.findViewById(R.id.changeButton);      changeButton.setOnClickListener(new View.OnClickListener() {         @Override         public void onClick(View view) {             mainActivity.finish();             mainActivity.startActivity(mainActivity.getIntent()); // error occurs this line         }     }); }   } '  This is my error  '  E/AndroidRuntime: FATAL EXCEPTION: main Process: com.example.dialogpractice, PID: 30511 java.lang.NullPointerException: Attempt to invoke virtual method 'android.app.ActivityThread$ApplicationThread android.app.ActivityThread.getApplicationThread()' on a null object reference     at android.app.Activity.startActivityForResult(Activity.java:3843)     at androidx.fragment.app.FragmentActivity.startActivityForResult(FragmentActivity.java:676)     at android.app.Activity.startActivityForResult(Activity.java:3804)     at androidx.fragment.app.FragmentActivity.startActivityForResult(FragmentActivity.java:663)     at android.app.Activity.startActivity(Activity.java:4114)     at android.app.Activity.startActivity(Activity.java:4082)     at com.example.dialogpractice.DialogHandler$1.onClick(DialogHandler.java:41)     at android.view.View.performClick(View.java:4781)     at android.view.View$PerformClick.run(View.java:19907)     at android.os.Handler.handleCallback(Handler.java:739)     at android.os.Handler.dispatchMessage(Handler.java:95)     at android.os.Looper.loop(Looper.java:160)     at android.app.ActivityThread.main(ActivityThread.java:5541)     at java.lang.reflect.Method.invoke(Native Method)     at java.lang.reflect.Method.invoke(Method.java:372)     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:964)     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:759)   '
What are Null Pointer Exceptions (java.lang.NullPointerException) and what causes them?  What methods/tools can be used to determine the cause so that you stop the exception from causing the program to terminate prematurely?
No room for a new \dimen How do I make the method return type generic? Consider this example (typical in OOP books):    I have an Animal class, where each Animal can have many friends. And subclasses like Dog, Duck, Mouse etc which add specific behavior like bark(), quack() etc.  Here's the Animal class:  public class Animal {     private Map&lt;String,Animal&gt; friends = new HashMap&lt;&gt;();      public void addFriend(String name, Animal animal){         friends.put(name,animal);     }      public Animal callFriend(String name){         return friends.get(name);     } }   And here's some code snippet with lots of typecasting:  Mouse jerry = new Mouse(); jerry.addFriend("spike", new Dog()); jerry.addFriend("quacker", new Duck());  ((Dog) jerry.callFriend("spike")).bark(); ((Duck) jerry.callFriend("quacker")).quack();   Is there any way I can use generics for the return type to get rid of the typecasting, so that I can say      jerry.callFriend("spike").bark(); jerry.callFriend("quacker").quack();   Here's some initial code with return type conveyed to the method as a parameter that's never used.   public&lt;T extends Animal&gt; T callFriend(String name, T unusedTypeObj){     return (T)friends.get(name);         }   Is there a way to figure out the return type at runtime without the extra parameter using instanceof? Or at least by passing a class of the type instead of a dummy instance. I understand generics are for compile time type-checking, but is there a workaround for this? If moderators can view , can we see comments we've deleted? We can see our deleted answers, but why not our deleted comments? How to prove reflexivity, symmetry and transitivity for the following relation? Which versions of C++ redistributables can I remove? I have a number of Microsoft Visual C++ 2005 and 2008 Redistributable and I would like to know which ones are safe to remove, because there are actually more than 10 installed on my computers.   Microsoft Visual C++ 2005 ATL Update kb973923 - x64 8.0.50727.4053 Microsoft Visual C++ 2005 Redistributable Microsoft Visual C++ 2005 (x64) Microsoft Visual C++ 2008 ATL Update kb973924 - x64 9.0.30729.4148 Microsoft Visual C++ 2008 Redistributable - x64 9.0.30729.17 Microsoft Visual C++ 2008 Redistributable - x86 9.0.30729.17 Microsoft Visual C++ 2008 Redistributable - x86 9.0.30729.4148 Microsoft Visual C++ 2008 Redistributable - x86 9.0.30729.4974 Microsoft Visual C++ 2010 x64 Runtime - 10.0.30319   It could be that these versions are all different, but a confirmation of that is fine for me as well. Thanks in advance.  PS. I'm using an x64 machine one windows 7. Prove that the dihedral group $D_4$ can not be written as a direct product of two groups Can I register a domain name that contains a company name or trademark? I wonder is it legal to register a domain name that contains a company name. For example cococola.cc (considering that this domain name is available). Can I buy and use any domain names that contain a name of a trademark? This formula provides the $n$th term in the Fibonacci Sequence, and is defined using the recurrence formula: $u_n = u_{n − 1} + u_{n − 2}$, for $n &gt; 1$,  where $u_0 = 0$ and $u_1 = 1$.   Show that     $$u_n = \frac{(1 + \sqrt{5})^n - (1 - \sqrt{5})^n}{2^n \sqrt{5}}.$$    Please help me with its proof. Thank you. Proof with 3D vectors Let ${a} = \begin{pmatrix}x_a\\y_a\\z_a\end{pmatrix}$, ${b} = \begin{pmatrix}x_b\\y_b\\z_b\end{pmatrix}$, and ${c} = \begin{pmatrix}x_c\\y_c\\z_c\end{pmatrix}$. Show that $(x_a,y_a,z_a)$, $(x_b,y_b,z_b)$, and $(x_c,y_c,z_c)$ are collinear if and only if ${a} \times {b} + {b} \times {c} + {c} \times {a} ={0}.$  Hello,  Is there any other way to do this problem without bashing?  I can't seem to find a nice and slick solution to this.  Thanks in advance! Show that if $n>2$, then $(n!)^2>n^n$. I have upgraded 14.04 to 16.04 . Now I am trying to open the gedit from terminal by passing the command:    sudo gedit /some/where/file.txt   but it is throwing an error stating that:    (gedit:2090): Gtk-WARNING : Calling Inhibit failed: GDBus.Error:org.freedesktop.DBus.Error.ServiceUnknown:   The name org.gnome.SessionManager was not provided by any .service files**   However, it is opening the file. When I try to save any modification then it is showing this error after saving the file:    (gedit:2090): WARNING : Set document metadata failed: Setting attribute metadata::gedit-position not supported   I am not getting why this is happening in 16.04 only; it was not on 14.04. Name an Armor Stand using the Standard Galactic Alphabet The Standard Galactic Alphabet is what appears in the Enchanting Table. Is there a way to give a name to an Armor Stand using these character.  I know there is a LingoJam Translator that give ASCII characters that look like the SGA, but that is not what I'm looking for. Can I use the same characters as the Enchanting Table? Where should shell tools be installed? Are there Apple guidelines for where user shell tools in Mountain Lion should be installed? Some (e.g. TeX, or Apple's Git) end up in /usr, and others (e.g. X11) seem to end up in /opt (sometimes with a symlink from /usr), while others (e.g., Git) end up in /user/local, and I wonder what the difference is, and whether one is preferred over the other. find exclude directory What does this $\asymp$ symbol mean? (subject: analytic number theory) I'm reading a  by Andrew Granville on analytic number theory.  On page 22 of the paper, there appears a strange looking symbol, undefined.  I've circled it in red in the screenshot below.    Since it's not defined in the paper, I'm assuming it must be standard notation.   From the context, I'm assuming it means something like "as compared to", or "with reference to", but that's just a guess.  Can anyone identify the symbol, even better explain what it means and/or provide a reference?  Is there a name to speak the symbol?  Thanks in advance. Let $x_1 = 2$, and define $$x_{n+1} = \frac{1}{2} \left(x_n + \frac{2}{x_n}\right).$$ Show that $x_n^2$ is always greater than or equal to $2$, and then use this to prove that $x_n − x_{n+1} ≥ 0$. Conclude that $\lim x_n = \sqrt2$.   My question:  So I know how to do this problem but I don't know how to prove that $x_n &gt;0$ for all $n\in \mathbb{N}$. Samba+Windows: Allow multiple connections by different users? I have a machine running Ubuntu with Samba that I use to share stuff with my family's Windows machines in our local network.  Currently they access a share for movies/music/etc with one user.  I want to connect them to another share as a different user (for example, user "goytacaz").  When I try connecting to this new share, Windows gives me "Error 1219" and complains about multiple connections by the same user.  How do I get my machine to accept multiple connections by the same user? Help needed with definite integral for $\lim_{n\rightarrow \infty}\sum_{k=1}^{n} \frac{1}{n+k}$ How to test if a player is near coordinates in 1.13? What Lagrangian counterterms might be needed in a $\phi^ 6$ theory in 3D?