Getting Null Pointer Exception in my addMarking method.  I'm new to buffered images so I'm not completely sure what the problem is. I have a seperate class that breaks an image up into 3x3 arrays and calls findEnds() with it. When findEnds find the correct condition in the 3x3 array it calls addMarking with the coordinates to make a red dot on the picture.  Note: Previously I tried using a 2dGraphic to write the picture on the bufferedImage but took it out in an attempt to fix this problem and copy the pixels manually with setRGB (haven't written this method yet).  Note: The reason I can't just make the buffered image with the original file is that the file has a black and white color type not TYPE_INT_RGB.   Error:  Exception in thread "main" java.lang.NullPointerException     at findFeatures.addMarking(findFeatures.java:43)     at getImage.getColor(getImage.java:44)     at fingerprintDriver.main(fingerprintDriver.java:15)   The getImage is a class that breaks the photo into 3x3 arrays, it also returns the coordinates of requested arrays to the addMarking class.   fingerprintDriver:  /**  * Driver for the ElevationScanner Class  *   * @author benjamincole  * @version 4/23/18  */ public class fingerprintDriver {     public static void main(String[] args) {         String fileName = JOptionPane.showInputDialog("Please enter a name for the file");         getImage test = new getImage(fileName);         findFeatures find = new findFeatures();         find.imageConstructor();         test.getColor();      } }   findFeatures class:   /**      * This class tests a 3x3 array. The method findEnds tests this array for      * two black pixels. If this condition is found it is an end and the x        * and y-coords are marked.      *       * @author benjamincole      *  */ public class findFeatures {     BufferedImage markedImage;     int counter;     public void imageConstructor() { // creates image to add markings to             markedImage = new BufferedImage(getImage.width, getImage.height, BufferedImage.TYPE_INT_RGB);     }      public void findEnds(boolean[][] colorArray) { // finds the ends of arches         counter = 0;         System.out.println();         for (int x = 0; x &lt; 3; x++) {             System.out.println();             for (int y = 0; y &lt; 3; y++) {                 System.out.print(" " + colorArray[x][y]);                 if (colorArray[x][y])                     counter++;             }         }             if (counter == 2 || counter == 1) { // if only 2 or less pixels are                                                 // black in the 3x3                 System.out.println(getImage.xCord + " " + getImage.yCord);                 System.out.println(" end found"); // end has been found                 addMarking(getImage.getXCord(), getImage.getYCord(), Color.red.getRGB());             }            }      public void addMarking(int x, int y, int rgb) { // adds red `marking to image`         markedImage.setRGB(x, y, rgb); //ERROR HERE! (Null Pointer)         markedImage.setRGB(x + 1, y + 1, rgb);         markedImage.setRGB(x + 2, y + 2, rgb);         markedImage.setRGB(x, y + 2, rgb);         markedImage.setRGB(x + 2, y, rgb);     }
129
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?
57448
So, I've been spending considerable more time on SO recently than I normally have, and one thing that I've noticed is quite a few people saying stuff like "There's a Null Pointer Error in this block of code, please help me fix it", with a huge amount of code posted, and no real clue as to where the NPE is. So my question is, what can we do to accomplish 2 goals?   Help the person asking the question become a better programmer. Help them to solve their problems.
2516
I am trying to get a FileInputStream object on an image that the user selects from the picture gallery. This is the android URI returned by android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI  content://media/external/images/media/3   When I try to construct a java URI object from this object, I get an IllegalArgumentException with the exception description Expected file scheme in URI: content://media/external/images/media/3 whereas the android URI shows the scheme as content  Update: Never found a solution for the original question. But if you want the byte stream of an image in the pictures gallery, this piece of code will do that.  Bitmap bitmap = Media.getBitmap(getContentResolver(), imageUri); ByteArrayOutputStream bytes = new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.JPEG, 40, bytes); ByteArrayInputStream fileInputStream = new ByteArrayInputStream(bytes.toByteArray());
66985
When I run the attached code I get this error:  ************************************ Missing \endcsname inserted. &lt;to be read again&gt;                     \c@float@type  l.23 \end{algorithm} ************************************   Any help would be highly appreciated.  \documentclass[aip, amsmath, amssymb, reprint]{revtex4-1}  \usepackage{graphicx} \usepackage{dcolumn} \usepackage{bm} \usepackage{float} \usepackage{algorithm} \usepackage{algpseudocode}  \begin{document}  \begin{algorithm*}   \caption{Hello}   \label{EPSA}    \begin{algorithmic}[1]    \State $T_m= \min\limits_k (T_c(k)),  k_m= \arg\min\limits_k (T_c(k))$    \end{algorithmic} \end{algorithm*}  \end{document}
74108
When I try to change the color after tracing a JPEG image in Illustrator and expanding it, it becomes gray. I have tried lots of color changes but the result is always the same.   Why can't I change the color to anything other than gray, on an image I've traced in Adobe Illustrator?  How can I change the traced image's color?
61954
Note I'm running windows, the path just looks like it's linus because I typed it manually and thats how I think of paths.  I'm trying to run a java class That I have built to diagnose my connection to a databse, it references the oracle jdbc adaptor.  When I just run it without a class path:  %&gt; java DBDiagnostics &lt;connectionString&gt;   I get an exception when it reaches the following line of code:  Class.forName("oracle.jdbc.pool.OracleDataSource").newInstance();   with the following exception:  java.lang.ClassNotFoundException: oracle.jdbc.pool.OracleDataSource         at java.net.URLClassLoader$1.run(URLClassLoader.java:200)         at java.security.AccessController.doPrivileged(Native Method)         at java.net.URLClassLoader.findClass(URLClassLoader.java:188)         at java.lang.ClassLoader.loadClass(ClassLoader.java:307)         at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)         at java.lang.ClassLoader.loadClass(ClassLoader.java:252)         at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)         at java.lang.Class.forName0(Native Method)         at java.lang.Class.forName(Class.java:169)         at DBDiagnostics.GetConnection(DBDiagnostics.java:43)         at DBDiagnostics.runDiagnostic(DBDiagnostics.java:29)         at DBDiagnostics.main(DBDiagnostics.java:18) Creating connection. java.sql.SQLException: No suitable driver found for lskd         at java.sql.DriverManager.getConnection(DriverManager.java:602)         at java.sql.DriverManager.getConnection(DriverManager.java:207)         at DBDiagnostics.GetConnection(DBDiagnostics.java:55)         at DBDiagnostics.runDiagnostic(DBDiagnostics.java:29)         at DBDiagnostics.main(DBDiagnostics.java:18) Veryfying connectivity to Database Exception in thread "main" java.lang.NullPointerException         at DBDiagnostics.verifyTable(DBDiagnostics.java:86)         at DBDiagnostics.verifyTable(DBDiagnostics.java:76)         at DBDiagnostics.verifyDatabseConnectivity(DBDiagnostics.java:68)         at DBDiagnostics.runDiagnostic(DBDiagnostics.java:36)         at DBDiagnostics.main(DBDiagnostics.java:18)   I assume that this is because I need to include it in the classpath.   So, I tried adding it to the classpath like this:  %&gt; java -classpath .:ojdbc6.jar DBDiagnostics &lt;connectionString&gt;   The VM just says it cant find the class:   Exception in thread "main" java.lang.NoClassDefFoundError: DBDiagnostics Caused by: java.lang.ClassNotFoundException: DBDiagnostics         at java.net.URLClassLoader$1.run(URLClassLoader.java:200)         at java.security.AccessController.doPrivileged(Native Method)         at java.net.URLClassLoader.findClass(URLClassLoader.java:188)         at java.lang.ClassLoader.loadClass(ClassLoader.java:307)         at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)         at java.lang.ClassLoader.loadClass(ClassLoader.java:252)         at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320) Could not find the main class: DBDiagnostics.  Program will exit.   I know this is a question I should just know the answer to, but what am I doing wrong?
13369
I have an Object[] array, and I am trying to find the ones that are primitives. I've tried to use Class.isPrimitive(), but it seems I'm doing something wrong:  int i = 3; Object o = i;  System.out.println(o.getClass().getName() + ", " +                    o.getClass().isPrimitive());   prints java.lang.Integer, false.  Is there a right way or some alternative?
113159
I'm not sure why I'm getting this error, but shouldn't this code compile, since I'm already checking to see if queue is getting initialized?   public static void Main(String[] args) {     Byte maxSize;     Queue queue;      if(args.Length != 0)     {         if(Byte.TryParse(args[0], out maxSize))             queue = new Queue(){MaxSize = maxSize};         else             Environment.Exit(0);     }     else     {         Environment.Exit(0);     }      for(Byte j = 0; j &lt; queue.MaxSize; j++)         queue.Insert(j);     for(Byte j = 0; j &lt; queue.MaxSize; j++)         Console.WriteLine(queue.Remove()); }   So if queue is not initialized, then the for loops aren't reachable right? Since the program already terminates with Environment.Exit(0)?  Hope ya'll can give me some pointers :)  Thanks.
99011
Drawing a parallelgram is nicely supported with Graphics.DrawImage:  Bitmap destImage = new Bitmap(srcImage.Width, srcImage.Height); using (Graphics gr = new Graphics.FromImage(destImage)) {     Point[] destPts = new Point[] { new PointF(x1, y1),          new PointF(x2, y2), new PointF(x4, y4)};     gr.DrawImage(srcImage, destPts);   How, do you do 4 points (obviously the following is not supported, but this is what is wanted):  Bitmap destImage = new Bitmap(srcImage.Width, srcImage.Height); using (Graphics gr = new Graphics.FromImage(destImage)) {     Point[] destPts = new Point[] { new PointF(x1, y1), new PointF(x2, y2),         new PointF(x3, y3), new PointF(x4, y4)};     gr.DrawImage(srcImage, destPts); }
72722
getRealPath() is returning the actual path in the local system, but returns null when deployed with a .war file.  &lt;%@ page import="java.io.*" %&gt; &lt;%@ page contentType="text/html;charset=ISO-8859-1" %&gt;  &lt;% int iLf = 10; char cLf = (char)iLf; String a= application.getResource("/"); //String myfile = application.getRealPath("/")+ "generate.xml"; //String myfile = request.getContextPath()+"generate.xml"; //String myfile = request.getRealPath("/")+"generate.xml";  out.println(myfile);     File outputFile = new File(myfile); outputFile.createNewFile(); FileWriter outfile = new FileWriter(outputFile); outfile.write(" &lt;?xml version='1.0' encoding='UTF-8'?&gt; "+cLf); outfile.write(" &lt;playlist version='1' xmlns = 'http://xspf.org/ns/0/' &gt; " +cLf); outfile.write(" &lt;title&gt;My Band Rocks Your Socks&lt;/title&gt; "+cLf);  outfile.write("&lt;trackList&gt;"+cLf);  %&gt;  &lt;%! String[] sports; %&gt;  &lt;%     sports = request.getParameterValues("sports");      out.println("&lt;html&gt;&lt;body&gt;&lt;h1&gt;hello&lt;/h1&gt;&lt;/body&gt;&lt;/html&gt;");      if (sports != null)     {           for (int i = 0; i &lt; sports.length; i++)          {                // outfile.writeln (sports[i]);                String total=sports[i];               String[] sa=total.split("[,]");               // String[] sub=new String();               outfile.write("&lt;track&gt;"+cLf);               for (int j=0;j&lt;sa.length;j++)               {                 // outfile.writeln(sa[j]);                 // outfile.writeln("sa["+j+"]="+sa[j]);                 if( j == 0)                 {                      outfile.write("&lt;location&gt;" + sa[0] +"&lt;/location&gt;"+cLf);                  }                 else if (j == 1)                      {                         outfile.write("&lt;image&gt;" + sa[1] +"&lt;/image&gt;"+cLf);                       }                      else if( j==2)                           {                             outfile.write("&lt;title&gt;" + sa[2] +"&lt;/title&gt;"+cLf);                           }                 }// end of inner for loop()                       outfile.write("&lt;/track&gt;"+cLf);          //outfile.writeln();       }// end of outer for()     }      //else outfile.writeln ("&lt;b&gt;none&lt;b&gt;");    outfile.write(" &lt;/trackList&gt; "+cLf);   outfile.write(" &lt;/playlist&gt; "+cLf);   outfile.close();    %&gt; &lt;object type="application/x-shockwave-flash" width="400" height="170"           data="xspf_player.swf?playlist_url=generate.xml"&gt;           &lt;param name="movie" value="xspf_player.swf?playlist_url=generate.xml" /&gt;  &lt;/object&gt;   Can anyone provide me with an alternative for this? It would be very helpful if you showed some sample code too.
108187
I am trying to add simple legend to the map.  I wrote some simple test code below to see what happens but it did not work.  var map = activeView.FocusMap;              IGraphicsContainer graphicsContainer = activeView.GraphicsContainer;             IMapFrame mapFrame = graphicsContainer.FindFrame(map) as IMapFrame;             UID uid = new UID();             uid.Value = "esriCarto.Legend";             IMapSurround mapSurround = map.CreateMapSurround(uid, null); mapFrame.CreateSurroundFrame(uid, null);              var legend = (ILegend)mapSurround;              var legendItem = new VerticalLegendItemClass();             legendItem.HeadingSymbol.Text = "served";             legend.AddItem(legendItem);              var legendItema = new VerticalLegendItemClass();             legendItema.HeadingSymbol.Text = "unserved";             legend.AddItem(legendItema);               IElement element = legend as IElement;             element.Geometry = envelope as IGeometry;             graphicsContainer.AddElement(element, 0);              activeView.Refresh();   The legend I am after, must be similar to this:    Can anyone assist?
20509
I have a small code example I want to include in the Javadoc comment for a method.    /**  * -- ex: looping through List of Map objects --  * &lt;code&gt;  * for (int i = 0; i &lt; list.size(); i++) {  *      Map map = (Map)list.get(i);  *      System.out.println(map.get("wordID"));  *      System.out.println(map.get("word"));  * }  * &lt;/code&gt;  *   * @param query - select statement  * @return List of Map objects  */   The problem is the code example shows up in the Javadoc with no line breaks making it hard to read.    -- ex: looping through List of Map objects -- for (int i = 0; i list.size(); i++) { Map map = (Map)list.get(i); System.out.println(map.get("wordID")); System.out.println(map.get("word")); }  Parameters query - - select statement  Returns: List of Map objects    I guess I am wrong in assuming the code tag would handle line breaks.  What is the best way to format code examples in Javadoc comments ?
107801
I posted the code below to the Sun developers forum since I thought it was erroring (the true error was before this code was even hit).  One of the responses I got said it would not work and to throw it away.  But it is actually working.  It might not be the best code (I am new to Java) but is there something inherently "wrong" with it?   =============  CODE:   private static void ImportFromCsvToAccessTable(String mdbFilePath, String accessTableName  , String csvDirPath , String csvFileName ) throws ClassNotFoundException, SQLException {      Connection msConn = getDestinationConnection(mdbFilePath);     try{          String strSQL = "SELECT * INTO " + accessTableName + " FROM [Text;HDR=YES;DATABASE=" + csvDirPath + ";].[" + csvFileName + "]";         PreparedStatement selectPrepSt = msConn.prepareStatement(strSQL );         boolean result = selectPrepSt.execute();                 System.out.println( "result = " + result );      } catch(Exception e) {         System.out.println(e);     } finally {         msConn.close();     } }
34848
I used to use the implicit call of toString when wanting some debug info about an object, because in case of the object is null it does not throw an Exception.  For instance:    System.out.println("obj: "+obj);   instead of:  System.out.println("obj: "+obj.toString());   Is there any difference apart from the null case? Can the latter case work, when the former does not?  Edit: What exactly is done, in case of the implicit call?
99846
I need to determine if a Class object representing an interface extends another interface, ie:   package a.b.c.d;     public Interface IMyInterface extends a.b.d.c.ISomeOtherInterface{     }   according to  Class.getSuperClass() will return null for an Interface.       If this Class represents either the   Object class, an interface, a   primitive type, or void, then null is   returned.   Therefore the following won't work.  Class interface = Class.ForName("a.b.c.d.IMyInterface") Class extendedInterface = interface.getSuperClass(); if(extendedInterface.getName().equals("a.b.d.c.ISomeOtherInterface")){     //do whatever here }   any ideas?
77421
Is there a cheap way to get the dimensions of an image (jpg, png, ...)? Preferably, I would like to achieve this using only the standard class library (because of hosting restrictions). I know that it should be relatively easy to read the image header and parse it myself, but it seems that something like this should be already there. Also, I’ve verified that the following piece of code reads the entire image (which I don’t want):  using System; using System.Drawing;  namespace Test {     class Program     {         static void Main(string[] args)         {             Image img = new Bitmap("test.png");             System.Console.WriteLine(img.Width + " x " + img.Height);         }     } }
11494
App version 1.0.27  If you the notification pane and click on the loading icon while it's spinning, the app will cause the app to crash.  03-26 22:51:08.331 E/AndroidRuntime(5927): FATAL EXCEPTION: main 03-26 22:51:08.331 E/AndroidRuntime(5927): java.lang.ArrayIndexOutOfBoundsException: length=0; index=-1 03-26 22:51:08.331 E/AndroidRuntime(5927): at java.util.ArrayList.get(ArrayList.java:310) 03-26 22:51:08.331 E/AndroidRuntime(5927): at com.stackexchange.marvin.ui.BaseActivity$3.onItemClick(BaseActivity.java:266) 03-26 22:51:08.331 E/AndroidRuntime(5927): at android.widget.AdapterView.performItemClick(AdapterView.java:298) 03-26 22:51:08.331 E/AndroidRuntime(5927): at android.widget.AbsListView.performItemClick(AbsListView.java:1100) 03-26 22:51:08.331 E/AndroidRuntime(5927): at android.widget.AbsListView$PerformClick.run(AbsListView.java:2788) 03-26 22:51:08.331 E/AndroidRuntime(5927): at android.widget.AbsListView$1.run(AbsListView.java:3463) 03-26 22:51:08.331 E/AndroidRuntime(5927): at android.os.Handler.handleCallback(Handler.java:730) 03-26 22:51:08.331 E/AndroidRuntime(5927): at android.os.Handler.dispatchMessage(Handler.java:92) 03-26 22:51:08.331 E/AndroidRuntime(5927): at android.os.Looper.loop(Looper.java:137) 03-26 22:51:08.331 E/AndroidRuntime(5927): at android.app.ActivityThread.main(ActivityThread.java:5103) 03-26 22:51:08.331 E/AndroidRuntime(5927): at java.lang.reflect.Method.invokeNative(Native Method) 03-26 22:51:08.331 E/AndroidRuntime(5927): at java.lang.reflect.Method.invoke(Method.java:525) 03-26 22:51:08.331 E/AndroidRuntime(5927): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737) 03-26 22:51:08.331 E/AndroidRuntime(5927): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553) 03-26 22:51:08.331 E/AndroidRuntime(5927): at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:126) 03-26 22:51:08.331 E/AndroidRuntime(5927): at dalvik.system.NativeStart.main(Native Method)   (Think I should calm down on finding bugs for a little while? :P)