In my application i want to select image from gallery and compress it. For compress i use this library :   I wrote below codes for it, but when i run the application and select image from gallery, it throws force close  and show below errors in logCat :   My activity codes :       @Override     public void onActivityResult(int requestCode, int resultCode, Intent data) {         super.onActivityResult(requestCode, resultCode, data);         if (resultCode == RESULT_OK) {             if (requestCode == REQUEST_TAKE_PHOTO || requestCode == REQUEST_PICK_PHOTO) {                 if (data != null) {                     // Get the Image from data                     Uri selectedImage = data.getData();                     String[] filePathColumn = {MediaStore.Images.Media.DATA};                      Cursor cursor = getActivity().getContentResolver().query(selectedImage, filePathColumn, null, null, null);                     assert cursor != null;                     cursor.moveToFirst();                      int columnIndex = cursor.getColumnIndex(filePathColumn[0]);                     mediaPath = cursor.getString(columnIndex);                     cursor.close();                      postPath = mediaPath;                     uploadImageToServer(postPath);                 }              }         } else if (resultCode != RESULT_CANCELED) {         }     } }     private void uploadImageToServer(String imagePath) {         if (imagePath == null || imagePath.equals("")) {             return;         } else {             showpDialog();             Map&lt;String, RequestBody&gt; map = new HashMap&lt;&gt;();             File file = new File(imagePath);             try {                 compressedImage = new Compressor(getActivity())                         .setMaxWidth(2000)                         .setMaxHeight(1400)                         .setQuality(90)                         .setCompressFormat(Bitmap.CompressFormat.JPEG)                         .setDestinationDirectoryPath(Environment.getExternalStoragePublicDirectory(                                 Environment.DIRECTORY_PICTURES).getAbsolutePath())                         .compressToFile(file);             } catch (IOException e) {                 e.printStackTrace();             } }   LogCat error :   Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'int android.graphics.Bitmap.getWidth()' on a null object reference                                                                        at id.zelory.compressor.ImageUtil.decodeSampledBitmapFromFile(ImageUtil.java:70)                                                                        at id.zelory.compressor.ImageUtil.compressImage(ImageUtil.java:33)                                                                        at id.zelory.compressor.Compressor.compressToFile(Compressor.java:60)                                                                        at id.zelory.compressor.Compressor.compressToFile(Compressor.java:56)                                                                        at com.app.android.Fragments.NewAddressFragment.uploadImageToServer(NewAddressFragment.java:486)                                                                        at com.app.android.Fragments.NewAddressFragment.onActivityResult(NewAddressFragment.java:353)                                                                        at android.support.v4.app.FragmentActivity.onActivityResult(FragmentActivity.java:156)                                                                        at android.app.Activity.dispatchActivityResult(Activity.java:7295)   Show error for this line : .compressToFile(file);  UPDATE : show this error just for some images no all images! How can i fix it? please help me
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?
Why does pizza cheese seem hotter than the crust? When I eat hot pizza or a melted cheese sandwich, the cheese feels a lot hotter than the crust or bread: in particular, the cheese might scald the roof of my mouth. but the crust will not. Is this   my imagination, or because the crust cools a little faster than the cheese, so has already cooled a bit by the time I eat it, or because the cheese cools a little faster than the crust, so transfers heat to the roof of my mouth a bit more, or what? I am lost.   So far...  If $\gcd (a,b) = 1$, by Bezout's Formula  $ax + by = 1$  If $c|(a+b)$, then $cf = a+b$  Then,  $a (x-y) + cfy = 1$   $b(yx) + cfx = 1$  Am I on the right track? Any suggestions? Assuming I have an ArrayList  ArrayList&lt;MyClass&gt; myList;   And I want to call toArray, is there a performance reason to use  MyClass[] arr = myList.toArray(new MyClass[myList.size()]);   over  MyClass[] arr = myList.toArray(new MyClass[0]);   ?  I prefer the second style, since it's less verbose, and I assumed that the compiler will make sure the empty array doesn't really get created, but I've been wondering if that's true.  Of course, in 99% of the cases it doesn't make a difference one way or the other, but I'd like to keep a consistent style between my normal code and my optimized inner loops... Does more reflective aluminum foil make a room cooler compared to less reflective foil? Aluminum foil is said to be not absorbing light at all. It reflects light. So, does it mean that a more shiny aluminum foil will reflect more light and thus make the room more cooler as compared to less shiny foil?  If yes, then where does unreflected light go in case of less shiny aluminum foil?  Does less shiny and more shiny actually make a difference? Why?  In order to keep whole room cool will it help if I stick the foil to the outside of wooden door (exposed to the sunlight) too? How to prove $\lim\limits_{n \to \infty} (1+\frac1n)^n = e$? Prove $(x+y)(y+z)(x+z)≤\frac8{27}(x+y+z)^3$ The entire exercise was like $$8xyz≤(x+y)(y+z)(x+z)≤\frac8{27}(x+y+z)^3\quad x,y,z&gt;0$$  and I managed to solve (demonstrate) the first inequality (from the left) using $$\frac{x+y}2≥\sqrt{xy}$$ but I can't solve the second one. I tried several ideas but I haven't succeeded. Thanks a lot. Geometry with Trigonometry From the given figure, prove that      $$\cot\ \theta=\cot\ A+\cot\ B+\cot\ C$$     I could not even start to the first point. Please help me to solve this.  Thanks in advance What is the difference between encrypting something and hashing something?  in what situations would I want one or the other? Calculate the area of an irregular cyclic convex polygon How to find patches with data in Raster and then how to extract those patches? I have a single band raster file as drawn in the labeled image attached.  The size of raster is around 4k pixel in each x and y axis. Large part of this raster is empty. Only in small portions of the raster contains data as labeled. Is there any efficient way I can extract rectangular patches around the data portions of the large tif raster file? Any pythonic way using gdal or rasterio or some other package. What I have done so far: I have followed from sklearn.feature_extraction.imageway to extract 2D patches where there is data as follows. from sklearn.feature_extraction.image import extract_patches_2d im = imageio.imread(largeFilePath) # reading the large image x, y = np.nonzero(im) # taking xy locations with non zero values  # determining xleft, xright, yleft and yright of the non zero area in  raster  xl,xr = x.min(),x.max()  yl,yr = y.min(),y.max()   #Extraing the non zero area from my original raster only_desired_area = im[xl:xr+1, yl:yr+1]  # my desired window to extract  window_shape = (480, 480)  # 2D Ptaches extraction B = extract_patches_2d(only_desired_area, window_shape, max_patches=100)  Issue: This doesn't have georeference information because I haven't used gdal or rasterio Upgrade SQL Server database Using Compatibility Level I've made a backup of a SQL Server database running on SQL Server 2008. I've restored that backup into a SQL Server 2012 instance. I've set the compatibility level on the restored instance to SQL Server 2012 (110).   What does this do to the database?   Does it, for example,    cause stored procedures to be examined for incompatibilities cause any updates to all of the data pages in the database Cause updates to to datapages as the are accessed in the future Cause errors in the future if stored procedures or views are executed that use incompatible syntax   Where in books on line, or else where, can I find more detail? I am a platform diver. I am trying to figure out how deep in the water I go depending on which platform I dive from.  The platforms are 1m, 3m, 5m, 7.5m and 10m above the water surface.  By ignoring air resistance (we assume that I do not do any tricks) I can easily compute the energy that my 90 kg body has when it is hitting the water:  E = mgh = 0.5mv^2   My problem is to find the deceleration in water and thus how deep my feet will go into the water before coming to a halt. We can assume that I stand straight and fall straight down and have a height of 190cm.  How do I compute that? This is a follow-up to this question:   Hans Bethe wrote a paper in 1944, "Theory of Diffraction by Small Holes," Phys. Rev. 66, 163. I don't have access to the paper, but from descriptions online it sounds like he proved the following. Suppose a plane wave impinges on an absorbing sheet, and there is a hole in the sheet of diameter $d$, with $d&lt;\lambda$. Let $P_0$ be the power incident on the hole, and $P$ the power diffracted through the hole. Then the transmission is $T=P/P_0=(d/\lambda)^4$.  As a practical application, I think this explains why microwaves don't leak strongly through the metal grille in the front of a microwave oven.  Questions:   Does the thickness of the sheet matter? From references online, it sounds like the hole is treated as a waveguide...? This seems to relate to cutoff frequencies of waveguides, etc.? It seems to me that Huygens' principle would give $T=1$ for $d\ll\lambda$, since in this limit the wavelets are in phase. Why is Huygens' principle invalid here? Is this related to question #1? Is there a simple argument for the proportionality to $(d/\lambda)^4$? Or if not, how does one prove this using the gory details of Bessel functions, etc.? If APS-C and similar crop-sensor digital cameras have a focal length multiplying effect such that a 50mm lens has an apparent focal length closer to the field of view of an 80mm on a full frame camera, and yet at the same time the depth of field for the smaller sensor camera is more like the depth of field a 50mm lens would produce on a full frame camera (using the same aperture), then this would seem to suggest the concept of an "aperture dividing effect."  In other words, a 50mm f/1.8 lens on an APS-C camera would act more like a 80mm f/2.8 (approx. 1.8 * 1.6x) lens in 35mm equivalent — for depth of field, not considering exposure.  Can someone with a better understanding of the physics involved clarify this for me.  I've never seen this concept explicitly mentioned anywhere, so I am a bit suspect of it. It's my understanding that a z-score can only be calculated and accurately used for data sets that are normally distributed.  Since "perfect" normal distribution almost never occurs in real-world data (where "perfect" normal distribution is defined as 1. The mean, median, and mode all equal the same number, 2. the distribution is perfectly symmetrical between all standard deviations on both sides of the mean, and 3. the distribution is asymptotic), how "close" can the distribution be to perfectly normal for the z-score to still be a valid statistical measure?  If the answer is it has to be a perfectly normal distribution, then my question is why is the z-score so important since it would seldom be a valid measure on real-world data? Idiomatic batch processing of text in Emacs? Can I travel to Kuwait on a visa with old passport number? I have a Kuwait visa, obtained from a hotel in Kuwait, with my old passport number. But as the validity of the present passport is expiring within 6 months, I got a new passport with a new passport number. Can I travel with the same visa or do I have to obtain a new visa with my new passport number? HDMI over cat extender video Is there an editor or IDE (or a script) for substituting the TeX-Commands $ and $$ for opening and closing math regions into the corresponding LaTeX-Commands \(,\) and \[,\]? I'm sure there is a tool - and I'm searching for. I think, this will result in better readable code. A simple search and replace wont do that - but with regular expressions, that should not be problem. I simply do not want to invent the wheel a second time. Can the JVM recover from an OutOfMemoryError without a restart