i'm testing another simple program for drawing a line. First problem is the error.  Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException     at GUI$2.paint(GUI.java:57)     at javax.swing.JComponent.paintChildren(Unknown Source)     at javax.swing.JComponent.paint(Unknown Source)     at javax.swing.JComponent.paintChildren(Unknown Source)     at javax.swing.JComponent.paint(Unknown Source)   This is the code for line 57 g.drawLine(pointStart.x, pointStart.y, pointEnd.x, pointEnd.y);  panel = new JPanel(){         Point pointStart = null;         Point pointEnd = null;         int x = 1;         {                addMouseListener(new MouseAdapter(){                 public void mousePressed(MouseEvent e){                     pointStart = e.getPoint();                 }                 public void mouseReleased(MouseEvent e){                     pointEnd = e.getPoint();                 }             });             addMouseMotionListener(new MouseAdapter(){                 public void mouseMoved(MouseEvent e){                     pointEnd = e.getPoint();                 }                 public void mouseDragged(MouseEvent e){                     pointEnd = e.getPoint();                     repaint();                 }             });         }         public void paint(Graphics g){             super.paint(g);             g.setColor(a);             g.drawLine(pointStart.x, pointStart.y, pointEnd.x, pointEnd.y);         }     };   If i can ask, how do i save the lines that has been drawn? Thanks
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?
104352
I created lines using the line segment tool in Adobe Illustrator (latest Adobe Cloud version) and I can't change the color of the stroke (through the Appearance panel) if the stroke weight is less than 2.0pt.   If the stroke is 2pt or more, then the color around the line changes but not the line itself.    The whole behavior is odd for me as I've never faced in Illustrator before.  Edit: added screen below with the line selected.
31989
Something that confuses me, but has never caused any problems... the recommended way to dispatch an event is as follows:  public event EventHandler SomeEvent; ... {     ....     if(SomeEvent!=null)SomeEvent(); }   In a multi-threaded environment, how does this code guarantee that another thread will not alter the invocation list of SomeEvent between the check for null and the invocation of the event?
68217
How can I detect when an Exception has been thrown anywhere in my application?  I'm try to auto-magically send myself an email whenever an exception is thrown anywhere in my Java Desktop Application.  I figure this way I can be more proactive.  I know I could just explicitly log and notify myself whenever an exception occurs, but I'd have to do it everywhere and I might(more likely will) miss a couple.  Any suggestions?
9051
Check out the below program.   try {     for (String data : Files.readAllLines(Paths.get("D:/sample.txt"))){         String[] de = data.split(";");         System.out.println("Length = " + de.length);     } } catch (IOException e) {     e.printStackTrace(); }   Sample.txt:   1;2;3;4 A;B;; a;b;c;   Output:   Length = 4 Length = 2 Length = 3   Why second and third output is giving 2 and 3 instead of 4. In sample.txt file, condition  for 2nd and 3rd line is should give newline(\n or enter) immediately after giving delimiter for the third field. Can anyone help me how to get length as 4 for 2nd and 3rd line without changing the condition of the sample.txt file and how to print the values of de[2] (throws  ArrayIndexOutOfBoundsException)?
22087
This is a poll of sorts about common concurrency problems in Java.  An example might be the classic deadlock or race condition or perhaps EDT threading bugs in Swing.  I'm interested both in a breadth of possible issues but also in what issues are most common.  So, please leave one specific answer of a Java concurrency bug per comment and vote up if you see one you've encountered.
51588
I am very new to game development, but not to programming.  I am (again) playing around with a Pong type game using JavaScript's canvas element.  I have created a Paddle object which has the following properties...   width height x y colour   I also have a Pong object which has properties such as...   width height backgroundColour draw().   The draw() method currently is resetting the canvas and that is where a question came up.  Should the Paddle object have a draw() method responsible for its drawing, or should the draw() of the Pong object be responsible for drawing its actors (I assume that is the correct term, please correct me if I'm incorrect).  I figured that it would be advantagous for the Paddle to draw itself, as I instantiate two objects, Player and Enemy. If it were not in the Pong's draw(), I'd need to write similar code twice.  What is the best practice here?  Thanks.
439
Consider:  namespace WindowsApplication1 {     public partial class Form1 : Form     {         public Form1()         {             InitializeComponent();         }          private void button1_Click(object sender, EventArgs e)         {             //int[] val = { 0, 0};             int val;             if (textBox1.Text == "")             {                 MessageBox.Show("Input any no");             }             else             {                 val = Convert.ToInt32(textBox1.Text);                 Thread ot1 = new Thread(new ParameterizedThreadStart(SumData));                 ot1.Start(val);             }         }          private static void ReadData(object state)         {             System.Windows.Forms.Application.Run();         }          void setTextboxText(int result)         {             if (this.InvokeRequired)             {                 this.Invoke(new IntDelegate(SetTextboxTextSafe), new object[] { result });             }             else             {                 SetTextboxTextSafe(result);             }         }          void SetTextboxTextSafe(int result)         {             label1.Text = result.ToString();         }          private static void SumData(object state)         {             int result;             //int[] icount = (int[])state;             int icount = (int)state;              for (int i = icount; i &gt; 0; i--)             {                 result += i;                 System.Threading.Thread.Sleep(1000);             }             setTextboxText(result);         }          delegate void IntDelegate(int result);          private void button2_Click(object sender, EventArgs e)         {             Application.Exit();         }     } }   Why is this error occurring?     An object reference is required for the nonstatic field, method, or property 'WindowsApplication1.Form1.setTextboxText(int)
14731
It is much more convenient and cleaner to use a single statement like  import java.awt.*;   than to import a bunch of individual classes  import java.awt.Panel; import java.awt.Graphics; import java.awt.Canvas; ...   What is wrong with using a wildcard in the import statement?
113807
Why does the following code not work?  I want to instantiate prefabs in a list and then use  it as a GameObject like that :  public GameObject prefab;  void Start() {   ArrayList players = new ArrayList();    for(int i=0; i&lt;5; i++)   {         players.Add( (GameObject)Instantiate(prefab));   }    players[2].transform.position = new Vector3(1, 1, 1);  }   there is an error message
116653
I have this:  If String.IsNullOrEmpty(editTransactionRow.pay_id.ToString()) = False Then     stTransactionPaymentID = editTransactionRow.pay_id 'Check for null value End If   Now, when editTransactionRow.pay_id is Null Visual Basic throws an exception. Is there something wrong with this code?
6095
There are some nice features in ArcToolbox we can use, but for some reason, this is NOT working properly. It doesn't even throw me an error.  My software is running inside ArcMap, so no need to AoInitialize again, corret?      public void Execute()     {         InitializeProduct();         try         {             Geoprocessor gp = new Geoprocessor();             gp.OverwriteOutput = true;              FeatureToPoint featureToPoint = new FeatureToPoint();              string outputPathName = CurrentWorkspace.PathName + "\\teste_centroide";              featureToPoint.in_features = InputFeatureClass;             featureToPoint.out_feature_class = outputPathName;             featureToPoint.point_location = "INSIDE";              IGeoProcessorResult result = (IGeoProcessorResult)gp.Execute(featureToPoint, null);              if (result == null)             {                 for (int i = 0; i &lt;= gp.MessageCount - 1; i++)                 {                     Console.WriteLine(gp.GetMessage(i));                 }             }              IGPUtilities gpUtils = new GPUtilitiesClass();             this.OutputFeatureClass = gpUtils.OpenFeatureClassFromString(outputPathName);         }         catch (Exception ex)         {             MessageBox.Show(ex.Message + "\r\n");         }   This is a code example I'm having here. I generated the DataManagement tools assembly, but I could not find the file to sign it.  This code just gives me an error. is it because of the signing?  I've tried the other way too, using IVariantArray and calling from the tool name, without sucess. Is it just me or...?  Can anyone point me a "nicer" solution? I need to run several process that are already built in ArcToolbox that I really don't want to duplicate.
110820
I'm currently making a callout to a 3rd party vendor and I'm getting a huge response. What is currently messing me up is this section:   "MessageSeq":13,"Description":"config file: config-qa1.txt\"","MessageTS":"2014-02-17T14:46:58","MessageLevel":4,"IsSystemMessage":false   As you can see here, the portion at the end of the Description value is ended with backslash double quote. If I attempt to parse this via the JSONParser I get an exception. Does anyone have an recommendations on how to resolve this?  Exception Message:  System.JSONException: Unexpected character ('"' (code 34)): was expecting comma to separate OBJECT entries at [line:1, column:3699]  Updated with sample Code   public class ResponseWrapper{     // fields from JSON to auto map     public Integer messageSeq;     public String Description;     public String messageTS;     public Integer messageLevel;     public Boolean isSystemMessage;     // parsing fields     private ResponseWrapper theResponse;     private JSONParser parser;      public void parse(String jsonString){         parser = JSON.createParser(jsonString);         parseJSON();     }      private void parseJSON(){            while (parser.nextToken() != null) {             if (parser.getCurrentToken() == JSONToken.START_OBJECT) {                 theResponse = (ResponseWrapper)parser.readValueAs(ResponseWrapper.class);                            }         }     } }  String responseString = '{"MessageSeq":13,"Description":"config file: config-qa1.txt\"","MessageTS":"2014-02-17T14:46:58","MessageLevel":4,"IsSystemMessage":false}'; system.debug('\n\nBEFORE\n' + responseString); ****Place code in here to test such as ReplaceALL*** ResponseWrapper parser = new ResponseWrapper(); parser.parse(responseString);
81002
When a Java VM crashes with an EXCEPTION_ACCESS_VIOLATION and produces an hs_err_pidXXX.log file, what does that indicate? The error itself is basically a null pointer exception. Is it always caused by a bug in the JVM, or are there other causes like malfunctioning hardware or software conflicts?  Edit: there is a native component, this is an SWT application on win32.
9169
I want to see the stack trace in any function of my code, so i made somthing like this to call it and print the stack trace:  public function PrintStackTrace() {     try {         throw new Error('StackTrace');     } catch (e:Error) {         trace(e.getStackTrace());     } }   I like to know if there are other way to do this. In some place, the Error class creates the stack trace, but maybe it didn't do it with ActionScript 3.0 so maybe it's not posible, but i want to know.  Thanks!
59379
Am trying to draw a simple rectangle and there seems to be minor issue with two of the endpoints (f and d in the following). I tried line cap=rect as suggested by  but that did not seem to work.  The resulting image:    \documentclass{standalone} \setlength\PreviewBorder{5pt}%  \usepackage{tikz}  \newcommand*{\Width}{2.0} \newcommand*{\Height}{3.0} \newcommand*{\Depth}{1.0}  \begin{document} \begin{tikzpicture}%     \coordinate (A) at ( 0,       0,     \Depth);%     \coordinate (B) at (\Height,  0,     \Depth);%     \coordinate (C) at (\Height,  0,      0);%     \coordinate (D) at (\Height, \Width,  0);%     \coordinate (E) at ( 0,      \Width,  0);%     \coordinate (F) at ( 0,      \Width, \Depth);%     \coordinate (G) at (\Height, \Width, \Depth);%     \coordinate (H) at ( 0,       0,      0);%     %     \draw [blue, ultra thick,line cap=rect]%         (A) -- (B) -- (C) -- (D) -- (E) -- (F) -- cycle;%     \draw [blue, ultra thick,line cap=rect]%         (B) -- (G) -- (F) -- (E) -- (D) -- (G) -- cycle;%      \path (D)  [right] node {$d$};% Problem Point 1     \path (F)  [left ] node {$f$};% Problem Point 2 \end{tikzpicture}% \end{document}   This problem about  seems related, but I do not understand how to adapt that to my problem.
75578
How is it possible in Eclipse JDT to convert a multiline selection to String. Like the following  From:  xxxx yyyy zzz   To:  "xxxx " + "yyyy " + "zzz"   I tried the following template   "${line_selection}${cursor}"+   but that way I only get the whole block surrounded not each line separately. How can I achieve a multiline processing like commenting the selected block?