I would like to call method of MainFragment.java from MainActivity.java  Here what I have tried:  MainActivity.java  MainFragment mainFragment;  ........  mainFragment = new MainFragment();  .........  mainFragment.deom();   MainFragment.java  public void deom() {      Toast.makeText(getActivity(), "Demo", Toast.LENGTH_LONG).show();  }   Log  java.lang.NullPointerException at android.widget.Toast.&lt;init&gt;(Toast.java:93) at android.widget.Toast.makeText(Toast.java:241) at com.example.x.b(Unknown Source) at com.example.MainActivity.onOptionsItemSelected(Unknown Source) at android.app.Activity.onMenuItemSelected(Activity.java:2633) at android.support.v4.b.ao.onMenuItemSelected(Unknown Source) at android.support.v7.app.t.onMenuItemSelected(Unknown Source) at android.support.v7.view.n.onMenuItemSelected(Unknown Source) at android.support.v7.view.n.onMenuItemSelected(Unknown Source)   May I know where I am doing mistake ? What I have missed ? Why I am getting NPE.
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?
Counting area percentage of overlapping polygons I have a set of points (meteorological stations) with 5km buffers around them. Additionally, I have a set of polygons (municipalities) in which those stations are located.  I would like to have data on how much of the buffer is filled by each polygon but I was not able to find a function or a way to do it. So for example for point A I would have that in the buffer of 5km there is 80% of polygon B and 20% of polygon C as the output.  Edit:  The anwsers provided do anwser this question in a setting in which I know what polygons and buffers I need to have in the code or when I can do it manualy. Problem is that in my setting with 1 shapefile having 500 polygons and one vector layer having 13000 buffers I am unable to do this manually and I am asking if there is an easier way to do it. I tried implementing the approaches in the questions but I was unable to use them on my example in big scale. Moreover I had problems with coding that I also noted in comments down below.   Main difference to the other similar question provided is that I have 2 vector layers (Buffer with 500 buffers and Municipalities a shape file with 500 different polygons). Previous questions were analyzing this question in situations in which I know precisely the polygons and buffers analyzed, at least that is how I understood them, so after trying to use those approaches on my datasets I was not able to replicate them.  Another way of approaching this problem for me is to use join attributes by location -one-to-many and then getting averages of the duplicate results, only problem is that then I take average of polygons instead of their weights corresponding to % of intersection with the buffer. In my case I do not know what polygons of the shapefile are going to intersect what buffers, or even if the buffer is going to be intersected by 1,2 or more polygons Path connected space that is not locally connected How do thrown weapons interact with the Extra Attack feature?  Can you throw more than one weapon per turn?  How about two-weapon fighting?  Do you need the Dual-Wielder feat to throw two weapons every turn? Is phonetic typing for Tamil available in Ubuntu 12.04?  How can I install it? Is there any way to increase the number of candy made? In Candy Box 2, the candies are being produced at a rate of 1 candy per second. Is there any way to increase the potential amount of candy made at a faster rate? (notice that I am only up to the part where the person with the cellar in their house gives me a map. I think my son was trying to guess the passcode! What do I do?  I can't wait 42 years! Why is Newton's method not widely used in machine learning? This is something that has been bugging me for a while, and I couldn't find any satisfactory answers online, so here goes:  After reviewing a set of lectures on convex optimization, Newton's method seems to be a far superior algorithm than gradient descent to find globally optimal solutions, because Newton's method can provide a guarantee for its solution, it's affine invariant, and most of all it converges in far fewer steps. Why is second-order optimization algorithms, such as Newton's method not as widely used as stochastic gradient descent in machine learning problems? How do I escape a backtick ` within a code block?  This is probably a duplicate, since I'm sure it's a common concern, but I can't find a question that addresses this specifically.  How do I write List'1 with the "1" character still in the code-text format? How to setup OpenVPN Client How to prove ${n \choose p} \equiv\left\lfloor \frac{n}{p} \right\rfloor\pmod p$ Prove ${n \choose p} \equiv \left\lfloor \frac{n}{p} \right\rfloor \pmod p$   ($n$ is natural and $p$ is a prime number)  How can i prove this statement? Can the notion of vector space or algebra over a field be meaningfully extended to fractional dimensions, so that for example $\mathbb{R}^{-2/3}$ makes sense? Has this been explored somewhere?  I know that super vector spaces can be thought of as one way of generalizing vector spaces to negative integer dimensions. Is there a similar concept for dimensions that are rational numbers? I'm not talking about Hausdorff dimension, because it doesn't allow for negative rationals, and I'm rather looking for extensions from a more algebraic point of view (dimension as the trace of the identity map), without recurring to a given metric. What is the meaning of “runneth”? What is the meaning of “runneth” in ? Invalid field count when uploading CSV to a data extension I tried uploading non-English text to my Data Extensions but the system is throwing error named &quot;Invalid Field Count&quot;. How can I use robots.txt to disallow subdomain only? My code base is shared between several environments (live, staging, dev) &amp; sub-domains (staging.example, dev.example, etc.) and only two should be allowed to be crawled (ie. www.example and example). Normally I'd modify /robots.txt and add Disallow: /, but due to shared code base I cannot modify /robots.txt without affecting all (sub)domains.  Any ideas how to go about it? Which is correct, and why?     some days we went on adventures — him maneuvering our scooter, me resting my chin …   or     some days we went on adventures — he maneuvering our scooter, I resting my chin … "All of these things are not beneficial and (they) do not help her" Should I mention the pronoun again in this case?     "All of these things are not beneficial and (they?) do not   help her"   I know that there is already answer about the question "if it's needed to repeat on the pronoun in case that they are in the same position of grammar tense". But in this case it's different because the question deals with case of two different  tenses (in bold). Need to get logfile smaller Compensation for missed connection due to delay with same airline but separate bookings Long story short, I had to fly from A (in Spain) to C (in the UK) and I booked two separate flights with the same budget airline, so the actual route was A (Spain) -> B (UK) -> C (UK).  The first flight was delayed by 90 minutes, which means that I was unable to catch the second one (the layover time was around an hour and a half) and had to buy another ticket for the following day (with another airline).  I googled a lot and found mixed responses. Is there any chance I can get a refund for my second flight? I will obviously ask them but I'm unsure what my best course of action is. I just bought an Xbox 360 game with wrong region. What should I do? I just bought a  game (Forza 4) for my Xbox 360 (bought in the US). When I tried to play the game, it wouldn't load because of region issue. Is there a legal way to solve this (no crack)? How to draw Venn diagrams (especially: complements) in LaTeX