We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › Exception in thread "Animation Thread" - ......uh
Page Index Toggle Pages: 1
Exception in thread "Animation Thread" - ......uh (Read 1257 times)
Exception in thread "Animation Thread" - ......uh
Mar 31st, 2010, 11:19am
 
Hey. Another Processing Noob.

I have a confusing issue with my code. The error message that pops up (on occasion might I add) is:

Code:

Exception in thread "Animation Thread" java.lang.NullPointerException
at DrawBoxNew$TweetBlock.<init>(DrawBoxNew.java:378)
at DrawBoxNew.addTweetBlock(DrawBoxNew.java:64)
at DrawBoxNew.draw(DrawBoxNew.java:194)
at processing.core.PApplet.handleDraw(PApplet.java:1425)
at processing.core.PApplet.run(PApplet.java:1327)
at java.lang.Thread.run(Thread.java:637)


Processing highlights the problem being at line 95 of the following code:

Code:

33   // constructor
34   public TweetBlock(int yPosition, int boxX, int boxY, int boxLength, int boxWidth, boolean colour, Tweet tweet, User user, String nameTag)
35   {
36     active = false;
37     // boxLength (horizontal)
38     // boxWidth (vertical)
39    
40     x = 10+boxX; // 10 pixels to the right -- position of the block
41     if (yPosition == 0)
42       y = 10+boxY; // 10 pixels down -- position of the block
43     else
44       y = yPosition + boxY;
45      
46      
47     labelX = 15+x; // a bit into the block
48    
49     labelY = 15+y; // "    "    "    "    "
50    
51     this.boxLength = boxLength;
52     this.boxWidth = boxWidth;
53    
54     blockLength = boxLength-20;
55     blockWidth = boxWidth/15;
56    
57     yboundary = boxY+boxWidth; // vertical
58     shift = 40;
59    
60     blockDistance = yboundary-y;
61    
62     this.colour = colour;
63    
64     this.tweet = tweet;
65     this.user = user;
66     this.nameTag = nameTag;
67    
68     tweetText = new ArrayList(0);
69     tweetText.add(tweet.getText());
70    
71     tempName = "";
72     if (this.user == null)
73       {tempName = "NoName";}
74     else
75       tempName = user.name();
76    
77    
78     tempText = tweet.getText();
79     if (tempText.length() > 80)
80     {
81       labelY = labelY-30;
82       StringBuffer sb = new StringBuffer("");
83       for (int i = 0; i<tempText.length(); i++)
84       {
85         if (i < 80)
86           sb.append(tempText.charAt(i));
87         if (i==80)
88           sb.append("\n");
89         if (i>80)
90           sb.append(tempText.charAt(i));
91       }
92       tempText = sb.toString();
93     }
94    
95     label = "User " + user.name() + " posted: " + tempText;
96   }



Any ideas?  Cry

Shakka
Re: Exception in thread "Animation Thread" - ......uh
Reply #1 - Mar 31st, 2010, 11:41am
 
user might be null. just check as you do at line 72.
Re: Exception in thread "Animation Thread" - ......uh
Reply #2 - Apr 1st, 2010, 1:21pm
 
Java dosn't use the same convention to compare strings as it does Numbers....  do a search on compareTo on http://java.sun.com/j2se/1.5.0/docs/api/java/lang/String.html

I believe you get that error because its passing the null value.
Page Index Toggle Pages: 1