Results 1 to 9 of 9
Thread: NullPointerException
- 03-18-2012, 05:21 AM #1
Member
- Join Date
- Feb 2012
- Posts
- 35
- Rep Power
- 0
NullPointerException
Why does it happen? Code:
I have no Idea why it errors.Java Code:package org.Bart.Tests.AI; import java.io.*; public class Main { public static void print(String a) { System.out.println(a); } public static void main(String[] args) { BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); String input; String[] brain; brain = new String[30000]; brain[0] = "Hello|Hi"; print("Hello, welcome to my failish AI"); try { input = reader.readLine(); for (String thing : brain) { thing.substring(0,thing.indexOf("|") ); thing.toLowerCase(); if (thing.contains(input)) { print("Found it!"); } } } catch (IOException e) { print("You suck at typing"); } } }
- 03-18-2012, 05:44 AM #2
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,547
- Rep Power
- 11
Re: NullPointerException
The stacktrace will tell you why the error occurs. What is the stacktrace? And which lines of your code does it refer to?I have no Idea why it errors.
- 03-18-2012, 06:06 AM #3
Member
- Join Date
- Feb 2012
- Posts
- 35
- Rep Power
- 0
Re: NullPointerException
Line 19
- 03-18-2012, 06:33 AM #4
Re: NullPointerException
Moved from Advanced Java. Inability to resolve a rather obvious NPE is in no way an advanced topic.
dbWhy do they call it rush hour when nothing moves? - Robin Williams
- 03-18-2012, 06:34 AM #5
Re: NullPointerException
Hint: What's the default value of an element of an array of any reference type?
dbWhy do they call it rush hour when nothing moves? - Robin Williams
- 03-18-2012, 06:36 AM #6
Member
- Join Date
- Feb 2012
- Posts
- 35
- Rep Power
- 0
Re: NullPointerException
null?
- 03-18-2012, 06:48 AM #7
Re: NullPointerException
Next hint: What happens when you attempt to invoke a method call on a reference that has a null value?
dbWhy do they call it rush hour when nothing moves? - Robin Williams
- 03-18-2012, 06:50 AM #8
Member
- Join Date
- Feb 2012
- Posts
- 35
- Rep Power
- 0
Re: NullPointerException
It thorws a null pointer exception.
- 03-18-2012, 07:10 AM #9
Member
- Join Date
- Feb 2012
- Posts
- 35
- Rep Power
- 0
Similar Threads
-
NullPointerException
By s0meb0dy in forum New To JavaReplies: 3Last Post: 10-09-2010, 08:12 PM -
NullPointerException
By GPB in forum New To JavaReplies: 8Last Post: 02-21-2010, 03:05 PM -
NullPointerException
By Juuno in forum New To JavaReplies: 1Last Post: 02-11-2010, 05:43 PM -
NullPointerException help?
By fab5freddy in forum New To JavaReplies: 2Last Post: 02-04-2010, 08:26 PM -
NullPointerException: I can't get rid of it.
By mcashe in forum AWT / SwingReplies: 2Last Post: 08-17-2009, 09:16 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks