GIDForums  

Go Back   GIDForums > Computer Programming Forums > Java Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 26-Oct-2009, 11:02
anut anut is offline
New Member
 
Join Date: Oct 2009
Posts: 1
anut is on a distinguished road

Please resolve this error


Hi !!

I am getting this error : Exception in thread "main" java.lang.NullPointerException
by running this program :

JAVA Code:
import java.io.*;
import java.util.*;

/**
 * @author Anu
 *
 */
public class TestReAlloc {
	static int chunksize;

	   public static void main(String args[]) throws IOException
	   {
		 if(args.length != 1)
		 {
		   System.err.println("usage: TestRealloc chunksize");   
		   System.exit(1);
		 }
		chunksize = Integer.parseInt(args[0]);
		alloc obj = new alloc();
		obj.alloc(chunksize);
	   }
	
}



public class alloc {

	public void alloc(int chunksize) throws IOException  
	{
		alloc obj = new alloc();
		obj.process();
	}
	
	 void process() throws IOException
	{
        int chunksize = 0;
        int chr = 0;
        byte a = 0;
        a = (byte) chr;
	    int input = getInput(chr, chunksize, a);
	    System.out.println("Chunksize :" + chunksize);
	    
	}
	
	 int getInput(int chr, int chunksize, byte a) throws IOException
	{
		 int line = 0;
		 byte[] array = null;
		
		while(chr != -1)
		{
			chr = System.in.read();
			if(chr == 0)
			{ 
				array = new byte[chunksize];
			}
			
			if(chr == array.length - 1)
			{
				array = ReAlloc.realloc(array, chunksize);
			}
			array[chr] = a;
			
			if(a == '\n')
				line++;
				
		}
		System.out.println("Total lines read : " +line);
		return a;
	}
}



Please help me in resolving this problem

Thanks !
Last edited by LuciWiz : 26-Oct-2009 at 11:32. Reason: Please insert your Java code between [java] & [/java] tags
  #2  
Old 27-Oct-2009, 20:17
TurboPT's Avatar
TurboPT TurboPT is offline
Senior Member
 
Join Date: Feb 2006
Location: Atlanta, GA
Posts: 1,140
TurboPT is a jewel in the roughTurboPT is a jewel in the roughTurboPT is a jewel in the rough

Re: Please resolve this error


There is not enough information.

1. Where is the rest of stack dump message for the null pointer?
2. What is 'alloc'?
3. Is the 'parseInt()' call failing? (no try/catch block around the operation??)
__________________
Use the force...read the source!!
WYCIWYG -- what you code is what you get!
 
 

Recent GIDBlogOnce again, no time for hobbies by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Two-Tier data dissemination code installation problem nidhibansal1984 Computer Software Forum - Linux 6 16-Sep-2007 11:13
Linked Lists advice request promsan C Programming Language 74 23-May-2007 09:29
Major newbie problem cynack MS Visual C++ / MFC Forum 1 08-Apr-2007 12:25
Winsock error when compiling FLTK 2.0 Projects mauriciorossi FLTK Forum 3 16-Aug-2005 11:18
Help with syntax errors PeteGallo C Programming Language 7 08-Aug-2005 21:30

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 19:25.


vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.