Click here to Skip to main content
15,894,896 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
I don't know what to do?!

I solved that but there's another one...
Exception in thread "main" java.lang.NullPointerException<br />
java.util.NoSuchElementException: No line foundread exception<br />
        at java.io.Writer.write(Writer.java:140)<br />
        at nfa2dfa.NfaToDfa.OutputFile(NfaToDfa.java:236)<br />
        at nfa2dfa.Main.main(Main.java:32)<br />
Java Result: 1

Java
[code]//import java.lang.String;

package nfa2dfa;
import java.io.*;
import java.util.*;


/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author Emitis
 */
public class NfaToDfa {


        String strtmp=null;
        String strtmp2=null;
        String strtmp3=null;
        String strtmp4=null;
        int i, j;
        String[] Alpha=new String[27];
        String rulenfa=null; // tedad e qanunhaye harkat dar nfa
        String Fstate=null;
        String[] Lstate=new String[100];
        String[][] Rules=new String[100][3];
        String State[]=new String[100];
        String delimiter = ",";
        String s=null;
        String[][] dfa=new String[100][3];
        int[] check=new int[100];
        int n=0;
        int d,t,h;
        int p=0;
        int g=1 ;
        int x=0;
        int sum=0;
        String not="not";
        String[][] converted=new String[100][3];
        String temp=null;
        String[] Lsatateconvereted=new String[100];

       public void inputfile() throws FileNotFoundException {
      try{
        Scanner nfafile=new Scanner(new FileInputStream("input.txt"));
    //    C:/JAVA/Topics.txt
     //   File file=new File("input.txt");
       // Scanner scan=new Scanner(System.in);
       // alefbaye zaban


       strtmp = nfafile.nextLine();
       State = strtmp.split(delimiter);

       strtmp2=nfafile.nextLine();
       Alpha=strtmp2.split(delimiter);

       Fstate=nfafile.nextLine();

       strtmp3 = nfafile.nextLine();
       Lstate = strtmp3.split(delimiter);

       rulenfa=nfafile.nextLine();

       while(nfafile.hasNextLine()==true){
       for(i=0;i<=100;i++){
       strtmp4 = nfafile.nextLine();
       Rules[i] = strtmp4.split(delimiter);
                }

            }

   nfafile.close();

    }

catch (Exception e){
        System.out.println(e+"read exception");

}
}
//***************************************************************************************
 public void converter(){
   // dfa[0][0]=null;
    //dfa[0][0].concat(Rules[0][0]);
     dfa[0][0]=Rules[0][0];
     dfa[0][1]=Rules[0][1];
     n++;
     s=Rules[0][2];
     for( ;Rules[g][0].compareTo(Rules[0][0])==0 && Rules[g][1].compareTo(Rules[0][1])==0;g++){
     //   s.concat(','+Rules[g][2]);
              s=s+','+Rules[g][2];

    }

      dfa[0][2]=s;
      s=null;
//flag 
     int fl=0;
     for(int i=g;i<Rules.length && Rules[i][0]!=null ;i++ ){
  //dfa[n][0]=Rules[i][0];
    //    s=Rules[i-1][0];
        s=Rules[i-1][2];
         for(  ;i<100 && s!=null && i<Rules.length && Rules[i][0].compareTo(Rules[i-1][0])==0 && Rules[i][1].compareTo(Rules[i-1][1])==0;i++){

        s=s+Rules[i][2]+',';
        fl=1;

    }
       // if(searchDfa(s).compareTo(not)==0)
         // s.concat(dfa[n][2]);
    if(fl==1){
      i--;
      fl--;
    }
    else{
            if((i<99 && i<Rules.length-1) && (Rules[i][0]!=null && Rules[i+1][0]!=null)&& (Rules[i][0].compareTo(Rules[i+1][0])!=0 || Rules[i][1].compareTo(Rules[i+1][1])!=0))

       s=Rules[i][2];
    }
        if(Rules[i][0]!=null&& Rules[i][1]!=null && Rules[i+1][0]!=null && Rules[i-1][1]!=null && s!=null )
        if(i+1<Rules.length && (Rules[i][0].compareTo(Rules[i+1][0])!=0 || Rules[i][1].compareTo(Rules[i-1][1])!=0)){
       // if(Rules[i][0]!=null&& Rules[i][1]!=null && s!=null)
        dfa[n][0]=Rules[i][0];//
        dfa[n][1]=Rules[i][1];
        dfa[n][2]=s;
        }
          
        n++;
        s=null;
 }

    converted[0][0]=converted[0][0]+dfa[0][0]; //shorue amaliate convert
    for(int i=0;i<100 && i<converted.length ;i++){
    LandaTrance();//aya state i ba landa be jaiie rafte ya na
    for(int r=0;r<27 &&  r<Alpha.length && Alpha[r]!=null && converted[i][0]!=null ;r++){
    temp=search(converted[i][0],Alpha[r]);//ba tamame alphabet check mikone ke masalan state i be che jahaiie mire
    if(temp.compareTo(not)!=0){
        converted[i][1].concat(converted[i][1]+Alpha[r]);
        converted[i][2].concat(converted[i][2]+","+temp);

                      }
    LandaTrance();
                                          }

                             }
     for(d=0;d<converted.length && converted[d][0]!=null && d<100 ;d++){
     for(int m=0;m<Lstate.length && Lstate[m]!=null && m<100 ;m++){
     if(converted[d][0].contains(Lstate[m])==true ){
       Lsatateconvereted[x]=converted[d][0];
       x++;
       break;
                          }
    }
    }
i=0;
while (converted[i][0]!=null) {
        i++;
     sum=i;
     }

}
 public void LandaTrance(){
  for(p=0;p<100;p++){
      check[p]=0;
  }
  int k=0;
  h=i;
  int flag=0;
  String htc=null;
  //htc=htc+converted[h][0];
  htc=htc+dfa[h][0];
  //converted[h][1]=converted[h][1]+dfa[h][1];
  while(search(htc,"#")!=not){
      for (int j=0;j<100;j++){ 
          if (check[j]==t)
              flag=1;
      }
      if(flag==1)
          break;
      htc=search(htc,"#");
      check[p]=t;
    p++;
    h++;//che taasiri dare ke h ezafe beshe ?
    k++;
    }

  for(int g=0;g<=k ;g++)
    converted[i][0]= converted[i][0]+dfa[check[g]][0];
  }
 //*******************************************************************
   public String search(String q,String s){
          for(t=0;t<100 && dfa[t][0]!=null ;t++)
    {
     if(dfa[t][0].compareTo(q)==0 && dfa[t][1].compareTo(s)==0)


         return dfa[t][2];
      }
     return not;

    }
   //*****************************************************************

//public String searchDfa(String q){
  //  for (int l=0;l<=100;l++)
    //{
      //  if (converted[l][2].compareTo(q)==0)
        //    return converted[l][2];
    //}
    //return not;
    //}
//*******************************************************************

    public void OutputFile( )throws FileNotFoundException, IOException{
        File file=new File("output.txt");
        FileWriter out=new FileWriter(file);
        out.write(converted[0][0]);
        for (int i = 1; i<converted.length && converted[i][0]!=null; i++) {
            out.write(","+converted[i][0]);
        }
        out.write(";\n");
        out.write(Alpha[0]);
        for (int i = 1; i < Alpha.length && Alpha[i]!=null; i++) {
           out.write(","+Alpha[i]);
        }
        out.write(";\n");
        out.write(converted[0][0]);
        out.write(";\n");

        out.write(Lsatateconvereted[0]);
        for (int i = 1; i < Lsatateconvereted.length && Lsatateconvereted[i]!=null; i++) {
            out.write(","+ Lsatateconvereted[i]);
        }
        out.write(";\n");
        out.write(sum);
        out.write(";\n");
        for (int i = 0; i < sum; i++) {
            out.write(converted[i][0]+","+converted[i][1]+","+converted[i][2]);
            out.write(";\n");
        }
        out.flush();
        out.close();
    }
}[/code]



Java
[code]/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */


package nfa2dfa;
import java.io.*;
import java.util.*;


/**
 *
 * @author ahangari
 */
public class Main {
    
    /**
     * @param args the command line arguments
     */
  //delimiter
       // Reader inp=new FileReader("nfa.txt");
 public static void main(String[] args) throws IOException, ClassNotFoundException {
//******************************************************
  // TODO code application logic here
       
       NfaToDfa n2d=new NfaToDfa();
//       File f = new File("input.txt");
   //    System.out.println(f.getAbsolutePath());
       n2d.inputfile();
       n2d.converter();
       n2d.OutputFile();      
}
             }
[/code]
Posted
Updated 30-Jan-12 19:35pm
v2
Comments
Sergey Alexandrovich Kryukov 30-Jan-12 13:24pm    
"Null pointer", not "point" :-)
OK, and where are those line 140, 236, 32? Comment them in your code.
Better yet, run it under debugger, you will find to problem pretty soon -- this one is usually very easy to find out.
--SA
tusharkaushik 30-Jan-12 15:15pm    
sORRY BRO! I DONT KNOW!

1 solution

BRO!

YU NO make methods with capital start. That is only suitable for Classes BRO!

Which IDE do you use BRO? Is it frealin' Eclipse or the funky Netbeans? tellma!

------------------

Edit:

LandaTrance and Outputfile are still wrong.

Which IDE do you use? They would not only prevent that, but help you to find your errors.
Please use one. Eclipse and also Netbeans are free.
 
Share this answer
 
v2

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