I am doing some asynchronous tasks with http to fetch some data.   When I close the app in the middle of an asynchronous operation, I get an a NullPointerException error. This seems to be happening because the asynchronous task is being competed and onTaskCompleted is called; But the app is already closed.  Does anyone know how to handle this?  I'm running with Android Studio, android version 4.4.2. Galaxy S4.  java.lang.NullPointerException         at com.example.lu.seed_2.Tabs.Tab4$3.onTaskCompleted(Tab4.java:174)         at com.example.lu.seed_2.ArticleAsync.onPostExecute(ArticleAsync.java:36)         at com.example.lu.seed_2.ArticleAsync.onPostExecute(ArticleAsync.java:11)         at android.os.AsyncTask.finish(AsyncTask.java:632)         at android.os.AsyncTask.access$600(AsyncTask.java:177)         at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:645)         at android.os.Handler.dispatchMessage(Handler.java:102)         at android.os.Looper.loop(Looper.java:157)         at android.app.ActivityThread.main(ActivityThread.java:5356)         at java.lang.reflect.Method.invokeNative(Native Method)         at java.lang.reflect.Method.invoke(Method.java:515)         at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265)         at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)         at dalvik.system.NativeStart.main(Native Method)   As requested, here is the onTaskComplete code  articles = convertJsonToArticles(httpResult.getBody()); articleAdapter = new ArticleAdapter(getActivity().getApplicationContext(), articles);  //&lt;-- APP CRASHES HERE listView = (ListView) getActivity().findViewById(R.id.mobile_list4); listView.setAdapter(articleAdapter); listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {     @Override     public void onItemClick(AdapterView&lt;?&gt; adapterView, View view, int i, long l) {         Intent intent = new Intent(getActivity().getApplication(), WebViewActivity.class);         intent.putExtra("_id", articles.get(i).getId());         startActivity(intent);     } }); listView.setOnScrollListener(new AbsListView.OnScrollListener() {     @Override     public void onScrollStateChanged(AbsListView absListView, int scrollState) {      }      @Override     public void onScroll(AbsListView absListView, int firstVisibleItem, int visibleItemCount, int totalItemCount) {         int itemsLeftCount = totalItemCount - firstVisibleItem;          if (itemsLeftCount &gt; 8) {             return;         }          if (isLoadingMore == true) {             return;         }         loadMoreArticles();     } }); listView.addFooterView(footerView); showNotLoading(); v.refreshComplete();
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?
Let $p$ be prime and $(\frac{-3}p)=1$. Prove that $p$ is of the form $p=a^2+3b^2$ Let $p$ be prime and $(\frac{-3}p)=1$, where $(\frac{-3}p)$ is Legendre symbol. Prove that $p$ is of the form $p=a^2+3b^2$.   My progress:  $(\frac{-3}p)=1 \Rightarrow$ $(\frac{-3}p)=(\frac{-1}p)(\frac{3}p)=(-1)^{\frac{p-1}2}(-1)^{\lfloor\frac{p+1}6\rfloor}=1 \Rightarrow$ $\frac{p-1}2+\lfloor\frac{p+1}6\rfloor=2k$  I'm stuck here. This is probably not the way to prove that.  Also tried this way:  $(\frac{-3}p)=1$, thus $-3\equiv x^2\pmod{p} \Rightarrow$ $p|x^2+3 \Rightarrow$ $x^2+3=p\cdot k$ stuck here too.  Any help would be appreciated. How to compute the determinant of a tridiagonal matrix with constant diagonals? How to show that the determinant of the following $(n\times n)$ matrix  $$\begin{pmatrix} 5 &amp; 2 &amp; 0 &amp; 0 &amp; 0 &amp; \cdots &amp; 0 \\ 2 &amp; 5 &amp; 2 &amp; 0 &amp; 0 &amp; \cdots &amp; 0 \\ 0 &amp; 2 &amp; 5 &amp; 2 &amp; 0 &amp; \cdots &amp; 0 \\ \vdots &amp; \vdots&amp; \vdots&amp; \vdots &amp; \vdots &amp; \vdots &amp; \vdots \\ 0 &amp; \cdots &amp; \cdots &amp; 0 &amp; 2 &amp; 5 &amp; 2 \\ 0 &amp; \cdots &amp; \cdots &amp; \cdots &amp; \cdots &amp; 2 &amp; 5 \end{pmatrix}$$  is equal to $\frac13(4^{n+1}-1)$?    More generally:     How does one compute the determinant of the following  (where the three diagonals are constant)?      $$M_n(a,b,c) = \begin{pmatrix} a &amp; b &amp; 0 &amp; 0 &amp; 0 &amp; \cdots &amp; 0 \\ c &amp; a &amp; b &amp; 0 &amp; 0 &amp; \cdots &amp; 0 \\ 0 &amp; c &amp; a &amp; b &amp; 0 &amp; \cdots &amp; 0 \\ \vdots &amp; \vdots&amp; \vdots&amp; \vdots &amp; \vdots&amp; \vdots &amp; \vdots \\ 0 &amp; \cdots &amp; \cdots &amp; 0 &amp; c &amp; a &amp; b \\ 0 &amp; \cdots &amp; \cdots &amp; \cdots &amp; \cdots &amp; c &amp; a \end{pmatrix}$$      Here $a,b,c$ can be taken to be real numbers, or complex numbers.   In other words, the matrix $M_n(a,b,c) = (m_{ij})_{1 \le i,j \le n}$ is such that $$m_{ij} = \begin{cases} a &amp; i = j, \\ b &amp; i = j - 1, \\ c &amp; i = j + 1, \\ 0 &amp; \text{otherwise.} \end{cases}$$  There does not seem to be an easy pattern to use induction: the matrix is not a diagonal  of the type $M = \bigl(\begin{smallmatrix} A &amp; C \\ 0 &amp; B \end{smallmatrix}\bigr)$ (where we could use $\det(M) = \det(A) \det(B)$ for the induction step), and there are no lines or columns with only one nonzero entry, so  gets complicated quickly.  Is there a general pattern that one could use? Or is the answer only known on a case-by-case basis? It's possible to compute the determinant by hand for small $n$:  $$\begin{align} \det(M_1(a,b,c)) &amp; = \begin{vmatrix} a \end{vmatrix} = a  \\ \det(M_2(a,b,c)) &amp; = \begin{vmatrix} a &amp; b \\ c &amp; a \end{vmatrix} = a^2 - bc \\ \det(M_3(a,b,c)) &amp; = \begin{vmatrix} a &amp; b &amp; 0 \\ c &amp; a &amp; b \\ 0 &amp; c &amp; a \end{vmatrix} = a^3 - 2abc \end{align}$$  But there is no readily apparent pattern and the computation becomes very difficult when $n$ gets large. What does the symbol $\otimes$ mean? Can the “while attuned” powers of Solarian stellar revelations be used while attuned to either mode, or only the matching one? I have a sample composed by 2500 count data values. I've plotted in R the corresponding histogram and ecdf. I've run the One-Sample Kolmogorov-Smirnov test to check if the distribution is either exponential or poisson, but I got negative results.  Is it possible that the One-Sample Kolmogorov-Smirnov test, it's not the correct test to work with this count data.  What is the best way to identify a distribution for this kind of data? What are complex numbers, actually? Which Java Collection should I use? The first and (the) second chapter(s) are difficult - which is correct? What is the string concatenation operator in Oracle? What is the string concatenation operator in Oracle SQL?    Are there any "interesting" features I should be careful of?    (This seems obvious, but I couldn't find a previous question asking it). Recurrence relation for the integral, $ I_n=\int\frac{dx}{(1+x^2)^n} $ Express recurrence relation  of the integral  $$ I_n=\int\frac{dx}{(1+x^2)^n} $$  [My Answer]  $$ I_n = \int\frac{1+x^2}{(1+x^2)^n}dx-\int\frac{x^2}{(1+x^2)^n}dx $$  $$ I_n=I_{n-1}-\int x\cdot\frac{x}{(1+x^2)^n}dx $$  $$ I_n=I_{n-1}-\frac{x}{2(1-n)(x^2+1)^{n-1}}+\frac{1}{2(1-n)}I_{n-1} $$  $$ I_n=\frac{2n-3}{2(n-1)}I_{n-1}+\frac{x}{2(n-1)(x^2+1)^{n-1}} \ \ \ \ (n&gt;1) $$  $$ I_1=\arctan(x) $$  Is my answer correct? A doubt regarding change of variables in Double Integrals. So I have recently learnt to calculate &quot;Double Integrals&quot; and I have a doubt on change of variables. Lets say we are evaluating a double integral of the form I = $\int\int _R F(x,y) dx dy $ , where $F(x,y)$ is an integrable smooth function and $R$ is the region of integration in the $xy$ plane. Now I want to convert to polar co-ordinates $x(r,\theta)=r \cos(\theta)$ and $y(r,\theta) = r \sin(\theta)$. Now the region $R$ in the $xy$ palne can be suitably converted to some region $R'$ in the $r \theta$ plane. The function $F(x,y)$ may take the form of some smooth and integrable $G(r,\theta)$. My main doubt is with the change of the area element. According to my textbook, $dx dy = \frac{\partial (x,y)}{\partial(r,\theta)} = rdrd\theta$. So the area element in the $r\theta$ plane is $rdr d\theta$. Now I want to experiment a little bit with my understanding : I write $dx = d(r\cos\theta) = -r\sin\theta d\theta + \cos \theta dr$  and $dy = d(r\sin\theta)=r\cos\theta d\theta + \sin\theta dr $. And now I multiply the two expression for $dx$ and $dy$ : $dxdy= -r^2\sin\theta\cos\theta d\theta d\theta - r \sin^2 \theta drd\theta + r \cos^2 \theta dr d\theta + \sin \theta \cos\theta dr dr$. Why isn't this expression equal to $rdrd\theta$ ? The $d\theta d\theta$ and $dr dr$ terms look very odd to me. Am I commiting some abuse of notation or something ? Also there are no higher order terms like $dr dr d\theta$ which I can ignore. I am totally confused with all this. Can someone explain this to me a bit clearly? Thanks in Advance :). EDIT 1 : I know differentials are not the &quot;usual&quot; kind of algebraic quantities and we can't just add and multiply them casually. I am just multiplying $dx$ with $dy$ with the spirit of multiplying some $\delta x$ and $\delta y$ and letting both $\delta x$ and $\delta y$ tend to zero. EDIT 2 : Is there a branch of Mathematics where addition and multiplication of differentials is very common? Is there something like differential of a differential ? Why are the Ringwraiths fearful of coming into contact with water? At least twice in The Lord of the Rings: The Fellowship of the Ring, Ringwraiths cower away from bodies of water.  The second time (the ford of Bruinen) can be explained away by their fear of some Elvish magical trap through the enchantment of the water; but what about the first time, at the ferry? One of the Nazgûl could have easily made the jump onto the barge and quickly dispatched those pesky Hobbitsses. I use the native Clock app, and my alarm used to just have a normal ringtone. I assume there was some automatic update recently because this morning, in addition to the normal ringtone, there was a robotic voice saying "It is 7:25 AM." Then later I got a notification from the native Calendar app, and in addition to my normal ringtone, the robotic voice announced the text of the notification.  How do I shut this off? It's really annoying and I don't see an option in Settings. Class teardown in junit 3? Possible Duplicate:          On  it's a stated fact that if $I$ and $J$ are coprime ideals of a ring $A$, then $I^k$ and $J^\ell$ are also coprime for any integers $k,\ell$.   There's no proof given. Why is this fact true? Execute bash commands over SSH while staying in interactive mode afterwards Probably it is a weird thing I would like to achieve but: I would like to SSH to a remote host and then execute some bash commands like "alias" automatically to use them afterwards in an interactive mode. The remote host does not allow the personal environment.    Is this possible? Would "expect" do it? Or is there any other way to achieve this? Basically I would like to have my bashrc without modifying any files on the remote host. What is the noun for someone who receives a referral? When a referrer (noun) gives a referral (noun) to another person, what is the term (noun) used for the recipient of the referral? "The referred" may work, but am I missing another term? "Referred" indicates past-tense, but I intend to use the term in future and present tense as well. Limit of a Piecewise Function defined on Rationals and Irrationals replacement wood threshold insert for metal door I have some late 70's doors and one is missing a threshold insert (the adjustable wood kind), anybody know of where one could by just the "wood strip" that goes in and screws down (there is a metal piece that sticks up into the wood, though you can't see it)?    They have about 4 screws that go down into them? How to return to the GUI? I am very new to Linux and Ubuntu. I use Ubuntu 11.10.  I was trying to exit the X server (in order to install some Nvidia drivers) and I typed in the terminal:  sudo service lightdm stop   How can I return to the Ubuntu interface?