Click here to Skip to main content
15,881,281 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
why null is shown when reading from a file.
the value inserted are q-1-q-true
but the values shown are nullq-null-nullq-nulltrue
The code given below:-

Scanner sc1=new Scanner(fr);
				while(sc1.hasNextLine())
				{
					char []p=sc1.nextLine().toCharArray();
					char [] a=new char[p.length];	
					for(int i=0;i<p.length;i++)
					{
						if(p[i]!='-')
						{
							if(String.valueOf(p[i])==(null))
							{
							}
							else
							{
							a[i]=p[i];
							col[x][j]+=p[i];
							}
							
						}
						JOptionPane.showMessageDialog(null,"col "+col[x][j]+":"+ j);
						//procedure pr=new procedure();
						
						if(p[i]=='-')
						{
							j++;i++;
						}
					}x++;
				}
				sc1.close();n=0;j=0;int y=0;


What I have tried:

File fo="c:\Tables";
for(File fr:fo.listFiles())
{
Scanner sc1=new Scanner(fr);
				while(sc1.hasNextLine())
				{
					char []p=sc1.nextLine().toCharArray();
					char [] a=new char[p.length];	
					for(int i=0;i<p.length;i++)
					{
						if(p[i]!='-')
						{
							if(String.valueOf(p[i])==(null))
							{
							}
							else
							{
							a[i]=p[i];
							col[x][j]+=p[i];
							}
							
						}
						JOptionPane.showMessageDialog(null,"col "+col[x][j]+":"+ j);
						//procedure pr=new procedure();
						
						if(p[i]=='-')
						{
							j++;i++;
						}
					}x++;
				}
				sc1.close();n=0;j=0;int y=0;
Posted
Updated 12-Mar-23 21:37pm
v3

1 solution

Without access to your files and file system as input, we can't really tell.

So, it's going to be up to you.
Fortunately, you have a tool available to you which will help you find out what is going on: the debugger. How you use it depends on your compiler system, but a quick Google for the name of your IDE and "debugger" should give you the info you need.

Put a breakpoint on the first line in the function, and run your code through the debugger. Then look at your code, and at your data and work out what should happen manually. Then single step each line checking that what you expected to happen is exactly what did. When it isn't, that's when you have a problem, and you can back-track (or run it again and look more closely) to find out why.

Sorry, but we can't do that for you - time for you to learn a new (and very, very useful) skill: debugging!
 
Share this answer
 
Comments
Member 12712527 13-Mar-23 7:47am    
Run debugger but can't find the error. while debugging the file showed nullq instead of q. where is the error i can't find. just after sc1.hasnextline() the nullq is shown as if it was previously inserted in the file.but on seeing the file only q is inserted and the next value is 1 but shown null while running the program
OriginalGriff 13-Mar-23 8:15am    
So what did the debugger show you?
What went into the variables as you stepped through, what route did it take, and why?

We seriously can't do this for you - we can't run your app under the same conditions you do!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900