How to fix ‘textview data ’ error in android I want to add the random number to put on textview in Dialogfragment that gets from Timer Activity;  i try to change many times  protected void onCreate(Bundle savedInstanceState) {     super.onCreate(savedInstanceState);     setContentView(R.layout.activity_main);     txt_v=(TextView)findViewById(R.id.hello);     txtv_2=(TextView)findViewById(R.id.textV_2);     btn_str=(Button)findViewById(R.id.btn_give_str);      dia=new DiagFragment();      nBtb=(Button)findViewById(R.id.bt);     nBtb.setOnClickListener(new View.OnClickListener() {         @Override         public void onClick(View view) {              dia.show(MainActivity.this.getSupportFragmentManager(), null);         }     });       timer.schedule(task, 1000, 5000);   }  TimerTask task = new TimerTask() {     public void run() {         if (dia!=null){              ((DiagFragment) dia).setData2(String.valueOf((Math.random() * 10)));          }     } };   public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {     View view=inflater.inflate(R.layout.list_dialog,null);     mContext=getActivity();      initView(view);      return view; }   public void initView(View view){     tx1=(TextView)view.findViewById(R.id.tv_1);      tx2=(TextView)view.findViewById(R.id.txv_2);  }    public void setData2(String string) {      str2=string;     Log.w(TAG, "setData2: "+string );     tx2.setText(string);   }  I can get data on diafragment, but I get an error when I add data to the TextVIew (tx2)  the error message is :     java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.TextView.setText(java.lang.CharSequence)' on a null object reference         at com.soundgil.dailogonclicklistend.DiagFragment.setData2(DiagFragment.java:68)         at com.soundgil.dailogonclicklistend.MainActivity$2.run(MainActivity.java:54)
What is a NullPointerException, and how do I fix it? 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?
How can I test whether my camera is working after it was dropped? Issue : How can I evaluate my cameras performance synthetically?  Scenario : Bought a Nikon D3100 an year back. Photos looked good enough. The camera fell, zoom lens effected.  But works. Cleaned lens using soap, water etc.  Carefully. Now photos look much worse.  How do I know if Photos are really bad?  Is there a tool?    Sample Photo  Now (Bad)   Original (Good)   Please help me realize whether my camera has gone bad.  Can you tell your personal opinion also? In how many ways can the letters of the word CHROMATIC be arranged? Reading the Result of Traceroute When you use tracert www.example.com in the command prompt, what exactly does the returned information tell you, and how does it go about getting that information. Up until now I have only used traceroute to get the I.P. address of a website without really thinking about the bigger purpose of traceroute. Solve $\lim_{x\to 0} \frac{\sin x-x}{x^3}$ In the Android App, if a question is closed, I won't be able to leave comments on either the question or any of its answers. There are simply no "Add Comment" buttons available anywhere if the question is closed.  See the screenshot below. The comment adding interface is simply removed on closed questions and their answers &mdash; no Reply button in the toolbar, and no Add Comment button under the question.        Occurs on Android app v1.0.50 and v1.0.51, on a HTC One running Android 4.4.3. The following message keeps appearing on my Samsung Galaxy S4 phone screen about every three seconds  "Unfortunately, Google Play Services has stopped".    Is it actually a virus or it is a problem with the Google Play Service?  I have tried disabling the Google Play Service but the message keeps appearing.  I have Norton Mobile running on my phone to pick up on viruses and to alert me to any possible security issues and also Lookout. They haven't picked up anything.  Does anyone have any suggestions? when to used had been and have been My friend just answered to one of my important questions. Now how should I reply to him?        That question had been in my head for a long time, finally, I got my answer      or        That question has been in my head for a long time, finally, I got an answer.      Basically, I am confused with had and have. Since that question is not anymore in my head after having got an answer, what should be used? (I am also confused whether it is possible to use having instead.) I need to make this equation in LateX but I get some errors when i try to do that.    Can you help me please?? Navigate folder structure in Open/Save File Dialog with keyboard? Solving $\sqrt{x+5} = x - 1$ I'm currently learning about radicals and simplifying them, and I came across this problem on the internet and tried to solve it:  $$\sqrt{x+5} = x - 1$$  So I used this logic:  $$ \begin{align} \sqrt{x+5} &amp;= x - 1 \\ x + 5 &amp;= (x-1)^2 \\ x + 5 &amp;= (x-1)(x-1) \\ x + 5 &amp;= x^2 - 2x + 1 \\ 0 &amp;= x^2 - 3x - 4 \\ 0 &amp;= (x-4)(x+1) \\ \end{align} $$  Therefore, $x = -1$ and $x = 4$ satisfy the equation $0 = (x-4)(x+1)$.  But then I tried to plug them in the original problem $\sqrt{x+5}=x-1$:  $$ \begin{align} \sqrt{4 + 5} &amp;= 4 - 1 \\ \sqrt{9} &amp;= 3 \\ 3 &amp;= 3 \end{align} $$  So using 4 works as expected, but when using $-1$:  $$ \begin{align} \sqrt{-1 + 5} &amp;= -1 - 1 \\ \sqrt{4} &amp;= -2 \\ 2 &amp;\ne -2 \end{align} $$  At what stage am I going wrong?  And according the , the solution is $x = 4$. Is there a quick way to get to the Control Panel in Windows 8? Obviously in all previous versions of Windows you could simply click START and then select "Control Panel" to get to it, but on Windows 8 there is no such option.  Is there an easy way to quickly get to it without having to press WIN, type "Control Panel", and then press Enter? What is the simplest way of proving (to a non-mathematician) that the power set of the set of natural numbers has the same cardinality as the set of the real numbers, i.e. how to construct a bijection from $\mathcal{P}(\mathbb{N})$ to $\mathbb{R}$? Why wasn't Restricted Section of the library better protected? Trying to understand formula for counting regions of hyperplane arrangements in $\mathbb{R}^2$ There are up to $\binom{n}{2} + n + 1$ regions created by a hyperplane arrangement in $\mathbb{R}^2$ containing $n$ hyperplanes.  I want to understand this in a demonstrative way. Each hyperplane splits each region it passes in two regions. A newly added hyperplane therefore creates a new region each time it crosses another hyplerplane or the plane. So the number of regions should be $1$ (plane) $+ \binom{n}{2}$ (number of intersections of $n$ lines). But as I know the answer, I know that I am missing $n$ regions.   Do you know where my mistake is? Why do I have to add the number of lines to get the max. number of regions? In first.bat, I use  var5=C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin\x86_amd64\ CALL scripts\vc64.bat %var5%   And in scripts\vc64.bat, I use  SET var6=%1vcvarsx86_amd64.bat CALL %var6%   But I get : 'C:\Programvcvarsx86_amd64.bat' is not internal or external command..... error.  If the path assigned to var5 has no space, then it is fine.  I tried several combination of quotations and %1vcvarsx86_amd64.bat, but no change.  How do I make it works with path with spaces?    To be more precise, suppose it is C:\a b c\  In first.bat:       SET var6=C:\a b c\  =====&gt;  '"C:\avcvarsx86_amd64.bat"' is not.....`      SET var6="C:\a b c\" ====&gt;   There should not be a b      SET var6=C:\a\ b\ c\ ====&gt;    Can't find the specified path      SET var6=C:\a b c\ + Using "%var6" ====&gt; There should not be a b     Update: Here is an example. Change a b to ab works.  call.bat in C:\  @ECHO OFF  SET var5=C:\a b\ CALL C:\1.bat "%var5%"  pause   1.bat in C:\  @ECHO OFF  SET var6=%~1Test.bat CALL %var6%  RMDIR /S C:\NoWorry   Test.bat in C:\a b Test.bat in C:\ab  @ECHO OFF  RMDIR /S C:\ThereIsNoSuchFolder Label callouts in QGIS Has anyone been using callout labelling with QGIS, either trunk or stable?   Used for clustered points. That means the point stays where it is, the label maybe moved if required and a leader (plain or pointed) shows the linkage between the label and the point.   How could I do it (you know what I mean, no coding....)? Prove by induction that $(x+1)^n - nx - 1$ is divisible by $x^2$ Basis step has already been completed. I've started off with the inductive step as just $n=k+1$, trying to involve $f(k)$ into it so that the left over parts can be deducible to be divisible by $x^2$ but getting stuck on this inductive step. Why is this power adapter transformerless? Amplitude of an electromagnetic wave containing a single photon Given a light pulse in vacuum containing a single photon with an energy $E=h\nu$, what is the peak value of the electric / magnetic field? Extracting usernames from the /etc/passwd file