Hello all.

I have the TreeSet Component that won't add any thing uising the add method
ex:

nameSet.add(projectName);

The exception always gets the text in the String projectName
xxx for example.
and Throws nullpointer
and traces out the string but adds null to it.

ex xxxnull

What more do I have to do to add an element to a Set?

have you instantiated the Set? if not it will not allow to add.

have you instantiated the Set? if not it will not allow to add.

Instantiated the set and it works. I am creating tabbed panels from the set. If I close and re run the program how do I have that list to use?

You can put elements into the set and then Serialize it.That way your instance of the set will be saved. You can de-serialize it later and retrieve the instance.

You can put elements into the set and then Serialize it.That way your instance of the set will be saved. You can de-serialize it later and retrieve the instance.

thanks
I will have to look that up. I just learned how to write a file.

I thought writing a file would save the set.

Do you know how to put a file "log.txt" in the programs package and
have the program look for the file so it can always use it.

File log=new File("log.txt"); 
log.getAsolutePath();

was cool and It just wrote it to the project folder.

how does a program like excel store tab names? a Serialized set?
Thanks again

Well you may try this:

File file = new File("testFile.txt");
	   try
	   {
		   //create the file 
		    file.createNewFile();

                  //write into file

                 //read  from the file 
  
          }
           catch(Exception e)
	   {
		   e.printStackTrace();
	   }

What do you want to find duplicates in?

I am going to explore the set serialization to save strings to load in tabs and see if it is good.

But, on creating a file. I will also need to be able to create a file that (r,w) and name it a specific name and put it in a specific dir.
Is all this possible?

Well I have written a code that creates a file,writes into it and reads from it. Hope this helps you.

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;


public class FileCreateWriteRead 
{
   public static void main(String[] args)
   {
	   File file = new File("testFile.txt");
	   
	  
	   try
	   {
		   //create the file 
		    file.createNewFile();
	     
	       //write into the file
		    System.out.println("Write something to be put in file");
		    
		    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		    
		    BufferedWriter bw  = new BufferedWriter(new FileWriter("testFile.txt"));
		    PrintWriter pw = new PrintWriter(bw);
		    
		    String str=br.readLine();
		   
		    pw.write(str);
		    pw.close();
		    
		    //read from the file and print it in console
		    System.out.println("Contents of the file :");
		    
		    BufferedReader br2 = new BufferedReader(new FileReader("testFile.txt"));
		    
		    String str2 = "";
		    String text = "";
		    
		    while((str2=br2.readLine())!=null)
		    {
		      text += str2;	
		    }
		   
		    System.out.println(text);
		    		
	       
	   }
	   catch(Exception e)
	   {
		   e.printStackTrace();
	   }
	    
	   
	   
   }
}

Well I have written a code that creates a file,writes into it and reads from it. Hope this helps you.

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;


public class FileCreateWriteRead 
{
   public static void main(String[] args)
   {
	   File file = new File("testFile.txt");
	   
	  
	   try
	   {
		   //create the file 
		    file.createNewFile();
	     
	       //write into the file
		    System.out.println("Write something to be put in file");
		    
		    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		    
		    BufferedWriter bw  = new BufferedWriter(new FileWriter("testFile.txt"));
		    PrintWriter pw = new PrintWriter(bw);
		    
		    String str=br.readLine();
		   
		    pw.write(str);
		    pw.close();
		    
		    //read from the file and print it in console
		    System.out.println("Contents of the file :");
		    
		    BufferedReader br2 = new BufferedReader(new FileReader("testFile.txt"));
		    
		    String str2 = "";
		    String text = "";
		    
		    while((str2=br2.readLine())!=null)
		    {
		      text += str2;	
		    }
		   
		    System.out.println(text);
		    		
	       
	   }
	   catch(Exception e)
	   {
		   e.printStackTrace();
	   }
	    
	   
	   
   }
}

That is a good example thanks.
I have to find out how to serialize tab names
and
take your example and try to create a dir and name and save that file to a specific folder in that dir.

Could take a while.
any classes that you know of that are built to do that already?
Thanks again

I have to find out how to serialize tab names

I am not sure exactly what you mean by this.And what functionality do want in classes?

hi ceyesuma if it helped you why dont u mark it as solved?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.