Problems in Stringtokenizer

Problems in Stringtokenizer

hi 

here is my code

import java.util.*;
import java.io.*;
import java.util.Scanner;
class Node
{
public boolean marked;
public int node_no;
public String node_type;
//public float value;
//public float control_value;
public  String usevar[];
public String defvar[];
public int child[];
public int par[];
public int actIn[];
public int actOut[];
public int advice;
}
public class Input
{
public int n,nn,vn;                                 //vn total no of variables,    n total no of node ,nn  node no.
public int i,use_var,def_var,p_c,c_c;               //
public String c,f,var_nam[];
public Node node[];
StringTokenizer str,str1;
Input() throws Exception
{
FileReader df=new FileReader("Input.txt");
Scanner fr=new Scanner(df);
str=new StringTokenizer(fr.nextLine(),"$");
this.n=Integer.parseInt(str.nextToken());        //total no of nodes
this.vn=Integer.parseInt(str.nextToken());       //toal no of variables
var_nam=new String[vn];                         //for total variables
str=new StringTokenizer(fr.nextLine(),"$");
System.out.println("rtryutrty"+n+vn);
for(int i=0;i<vn;i++)
{
String a=str.nextToken();
var_nam[i]=a;
}
node=new Node[n+1];
for(int i=1;i<=n;i++)
{
node[i]=new Node();
}
i=1;
while(fr.hasNextLine())
    {
    c=fr.nextLine();
    str=new StringTokenizer(c,"$");                         //node no is parsed
    nn=Integer.parseInt(str.nextToken());      
    System.out.println(nn);
    node[i].node_no=nn;                                 //node no is assigned


    str1=new StringTokenizer(str.nextToken()," ");
   use_var=str1.countTokens();                              // no of use var
   node[i].usevar=new String[use_var];  
   for(int j=0;j<use_var;j++)
        {
            node[i].usevar[j]=str1.nextToken();
        }
for(int j=0;j<use_var;j++)
        {
            System.out.println(node[i].usevar[j]);
        }


    str1=new StringTokenizer(str.nextToken()," ");      // for def var
    def_var=str1.countTokens();
    node[i].defvar=new String[def_var];
     for(int j=0;j<def_var;j++)
        {
            node[i].defvar[j]=str1.nextToken();
        }
        for(int j=0;j<def_var;j++)
        {
            System.out.println(node[i].defvar[j]);
        }



str1=new StringTokenizer(str.nextToken()," ");          // parents node info
p_c=str1.countTokens();
node[i].par=new int[p_c];
     for(int j=0;j<p_c;j++)
        {
            node[i].par[j]=Integer.parseInt(str1.nextToken());
        }
         for(int j=0;j<p_c;j++)
        {
            System.out.println(node[i].par[j]);
        }

System.out.println("erhiwe");       
str1=new StringTokenizer(str.nextToken()," ");          // child node info
c_c=str1.countTokens();
node[i].child=new int[c_c];
     for(int j=0;j<c_c;j++)
        {
            node[i].child[j]=Integer.parseInt(str1.nextToken());
        }
        for(int j=0;j<c_c;j++)
        {
            System.out.println(node[i].child[j]);
        }
        node[i].node_type=str.nextToken();   // node type
//System.out.println("sfdsrsr\n\n\n");      
        int temp=Integer.parseInt(str.nextToken());
        System.out.println(temp);
        node[i].actIn= new int[temp];
        str1=new StringTokenizer(str.nextToken()," ");
        for(int  temp1=0;str1.hasMoreTokens();temp1++)
        node[i].actIn[temp1]=Integer.parseInt(str1.nextToken());        //total actIn are Obtained
         temp=Integer.parseInt(str.nextToken());
         System.out.println(temp);
         node[i].actOut= new int[temp];
        str1=new StringTokenizer(str.nextToken()," ");
        for(int  temp1=0;str1.hasMoreTokens();temp1++)
        node[i].actOut[temp1]=Integer.parseInt(str1.nextToken());                  //total actOut are Obtained
            node[i].advice=Integer.parseInt(str.nextToken());                   //advice vertex if not then simply put zero



i++;                                                                            //next node
}
    }


public static void main(String args[])throws Exception
{
Input i=new Input();
System.out.println("\nnew main\n");
for(int k=1;k<=i.n;k++)
{
//System.out.println("\nnew main\n");
System.out.print(i.node[k].marked);
System.out.print(i.node[k].node_no+" a121a ");
for(int j=0;j<i.node[k].usevar.length;j++)
System.out.print(i.node[k].usevar[j]+" ");
for(int j=0;j<i.node[k].defvar.length;j++)
System.out.print(i.node[k].defvar[j]+" ");
for(int j=0;j<i.node[k].child.length;j++)
System.out.print(i.node[k].child[j]+"  ");
for(int j=0;j<i.node[k].par.length;j++)
System.out.print(i.node[k].par[j]+"  ");
for(int j=0;j<i.node[k].actOut.length;j++)
System.out.print(i.node[k].actOut[j]+"  ");
for(int j=0;j<i.node[k].actIn.length;j++)
System.out.print(i.node[k].actIn[j]+"  ");
System.out.print(i.node[k].node_type+"  ");
System.out.println(" ");
}
}

}

When i am trying to compile the code i found the following error

Error: Exception in thread "main" java.util.NoSuchElementException at java.util.StringTokenizer.nextToken(Unknown Source) at Input.(Input.java:84) at Input.main(Input.java:130)

Actually this is an implementation of a slicing algorithm. The class Input.java specifies the Input to the program with the help of a text file. Below I am attaching the text file named Input.txt. the input file is too large in size. Please let me know more about the flaws.

58$14
name$Threadname$t$k$e$i$j$sc$x$y$z$a$b$n
57$$$$0$58$$$$$
58$$$$57$59 60$$$$$
59$$$$58$6$$$$$
60$$$$58$33$$$$$
6$7 33 34$7$59$7 8 9 10 12$$$$$$
33$34 6 7$34$60$67 34 35 36 37 38 39$$$$$$
7$8 15 34 35$7 34 $6$8$$$$$$
34$35 7 8$7 34$33$35$$$$$$
35$36 37 5 7 9 10 14 15$35$33 34$36 37$$$$$$
59$$$$58$6$$$$$
10$$8$6 8 9$11 14 17$$$$$$
8$9 10 14 15 35 36 37$8$6 7$10 15$$$$$$
9$$8 35$6 8$10 15$$$$$$
36$$8 35$33 35$37$$$$$$
37$$9 35$6 8$10 15$$$$$$
38$$$33$40$$$$$$
39$$$33$52$$$$$$
40$$$37 38 69$41 45 46 50$$$$$$
41$47 48 50 51 70 71 72 74$41$40$47 48$$$$$$
46$47 49 45$45$40$47 48 49 70$$$$$$
45$49 45 46$45$40$49$$$$$$
47$48 45 46 49$41$41 45$48 49$$$$$$
48$47 49 45 46 70 71 72 74$41$41 46 47 50 51$0$$$$$$
49$47 49 45 46$45$45 46 47$0$$$$$$
50$51 41 48$41$40$70 51 48$$$$$$
51$41 48 50 51 71 72 74 70$41$40 50 75$48$$$$$$
52$$$49$37 39$53 54 55 56$$$$$
53$56$53$52$56$$$$$$
54$56 27 28 29$54 27$52 27$56$$$$$$
55$56 28 29$55$52 28$56$$$$$$
56$53 54 55 27 28 29$53 54 55 27 28$52 53 54 55$0$$$$$$
11$$$10$26$$$$$$
12$$$6 24 66$13 16$$$$$$
13$15$13$12$14 15$$$$$$
14$8 9 10 15 14 35 36 37$8 35$10 13$15$sleep node$$$$$
15$8 9 10 13 14 15 35 36 37$8 35 13$8 9 13 14$16$$$$$$
16$$$12 15$0$$$$$$
17$$$$29 64 10$19 23 24$$$$$
19$24$19$17$24$$$$$$
23$23 24 25$$17$24$$$$$$
24$19 23 24 25$19$17 19 23$12 25$$$$$$
25$23 24 25$$24$65$$$$$$
26$$$11$27 28 29$$$$$$
27$29 54 56$27 54$26$29$$$$$$
28$29 55 56$28 55$26$29 55$$$$$$
29$27 28 29 54 55 56$27 28 54 55$26 27 28$17 62$$$$$$
62$$$29$63 65$pointcut vertex$$$$$
63$$$62$64$$$$$$ startingadvice vertex
64$$$63$17$$$$$$
65$$$25 62$66$$$$$$ startingadvice vertex
66$$$65$12$$$$$$
67$$$33$68 70$poincut vertex$$$$$
68$$$67$69$$$$$$ startingadvice vertex
69$$$68$40$$$$$$
70$71 72 74 41 48 50 70 51$41$46 50 67$71 75 f1_in$$1$f1_in$$$ startingadvice vertex
71$70 71 72 74 41 48 50 51$41$70$72 74$$$$$$
72$70 71 72 74 41 48 50 51$41$f1_in$0$$$$$$
74$70 71 72 74 41 48 50 51$41$71 f1_in$0$$$$$$
75$$$70$51$$$$$$

The algorithm is as follows:

import java.util.*;
class DynamicSlice 
{
String var_name;
int par[];
DynamicSlice(int n)
{
par=new int[n+1];   //no of nodes is=n
}
}
class Algo extends Input
{
    int zc=n+1;
DynamicSlice dn[][]=new DynamicSlice[zc][vn];
int rec_def[];
Algo() throws Exception
{}
public void init()
{ 
rec_def =new int[vn];
for(int i=1;i<n+1;i++)
for(int j=0;j<vn;j++)
dn[i][j]=new DynamicSlice(n);
                                //set Dynamic slice is creATED
for(int i=1;i<n+1;i++)
for(int j=0;j<vn;j++)
{
dn[i][j].var_name=var_nam[j];
}
}
//variable name is assigned to each position 

public int varat(String x) 
    {
    for(int i=0;i<vn;i++)
        if(x.equals(var_nam[i]))return(i);
return 0;
    }   // knowing the position of var in vaiable list
public void a2(int nodeno)
{
for(int l=0; l<node[nodeno].usevar.length;l++)
{
int index = varat(node[nodeno].usevar[l]);
for(int i=1;i<n+1;i++){
int k=dn[nodeno][index].par[i];
if(k!=0)
if(node[k].marked=true)
{
dn[nodeno][index].par[k]=1;                
for(int j=1;j<=n;j++)
{
dn[nodeno][index].par[j]=(dn[k][index].par[j]==1)?1:0;     
}
}
}
}
}
public void call2a()
{
for(int i=1;i<=n;i++)
a2(node[i].node_no);
}
                /* 2 A over*/
                /* 2B starts */
public void call2b()
{
for(int i=1;i<=n;i++)
{
for(int j=0;j<node[i].defvar.length;j++)
    {
    int index = varat(node[i].defvar[j]);            //index of def var in varnam list
    dn[i][index].par[i]=1;                        //dynamic slice updated
    rec_def[index]=i;
    node[rec_def[index]].marked=false;
    }
    node[i].marked=true;
}
}

/* 2 C and 2 B over */

/* rest start*/
public void other()
{
for(int i=1;i<n+1;i++)
{
if(node[i].node_type.equals("pointcut"))
{
node[i].marked=true;
for(int j=0;j<node[i].actIn.length;j++)
node[node[i].actIn[j]].marked=true;
for(int j=0;j<node[i].actOut.length;j++)
node[node[i].actOut[j]].marked=true;
if(node[i].advice>0)                   //advice vertex is marked along with the formal in formal out
{
node[node[i].advice].marked=true;
for(int j=0;j<node[node[i].advice].actIn.length;j++)
node[node[node[i].advice].actIn[j]].marked=true;
for(int j=0;j<node[node[i].advice].actOut.length;j++)
node[node[node[i].advice].actOut[j]].marked=true;
}
}
if(node[i].node_type.equals("sleep"))
{
node[i].marked=true;
}
}
}


public void call3a()
{
System.out.println(" enter the var name and the  node no");
int sw,sq;
String arg;
Scanner scan=new Scanner(System.in);
arg=scan.next();
sw=scan.nextInt();
sq=varat(arg);                          //index no of arg
for(int i=0;i<n;i++)
{
if(dn[sw][sq].par[i]==1)
System.out.print(dn[sw][sq].par[i]+1);
}
}

public static void main(String arg[]) throws Exception
{
//Input input=new Input();

Algo alg=new Algo();
alg.init();
System.out.println("\n\n\n\n\\n\n\n");
alg.call2a();
alg.call2b();
alg.other();
while(true)
{
alg.call3a();
System.out.println(" want to exit then enter 0");
Scanner scan=new Scanner(System.in);
int i=scan.nextInt();
if(i==0)break;
}
}/*end of main*/




}
View Answers









Related Tutorials/Questions & Answers:
Problems in Stringtokenizer
Problems in Stringtokenizer  hi here is my code import java.util.... node[]; StringTokenizer str,str1; Input() throws Exception { FileReader df=new FileReader("Input.txt"); Scanner fr=new Scanner(df); str=new StringTokenizer
Problems in Stringtokenizer
Problems in Stringtokenizer  hi here is my code import java.util.... node[]; StringTokenizer str,str1; Input() throws Exception { FileReader df=new FileReader("Input.txt"); Scanner fr=new Scanner(df); str=new StringTokenizer
Advertisements
Problems in Stringtokenizer
Problems in Stringtokenizer  hi here is my code import java.util.... node[]; StringTokenizer str,str1; Input() throws Exception { FileReader df=new FileReader("Input.txt"); Scanner fr=new Scanner(df); str=new StringTokenizer
Java stringtokenizer
Java stringtokenizer  What is difference between string and stringtokenizer
Query on StringTokenizer
Query on StringTokenizer   Sir,I kept my some data in backend using ms-access. for Example my data is like this vijayawada is good city.india is my country.i am raja. when i retrieve this data from backend and keep
program using StringTokenizer
program using StringTokenizer  I want to know about StringTokenizer,so can you please explain it with an example
StringTokenizer not returning proper result
StringTokenizer not returning proper result  I have this code... System.out.print("Enter the stack integers side by side with a space in between: "); StringTokenizer st=new StringTokenizer(br.readLine()); int a[]=new int[9000
arraylist problems?
arraylist problems?   myprogram needs to ask the user for a file name. The file will contain a name on each line. Put each of the names into an ArrayList. After you have put all of the names into the ArrayList search through
Can iadd StringTokenizer into JLabel componenet
Can iadd StringTokenizer into JLabel componenet  l24="india.cricket.java.dotnet.oracle" String mn=l24; StringTokenizer mn1=new StringTokenizer(l24...(3,280,1580,600); nowon.setBackground(Color.cyan); sir i want to add StringTokenizer
ModuleNotFoundError: No module named 'problems'
ModuleNotFoundError: No module named 'problems'  Hi, My Python... 'problems' How to remove the ModuleNotFoundError: No module named 'problems... to install padas library. You can install problems python with following
Problems With Struts - Development process
Problems With Struts   Respected Sir , While Deploying Struts Application in Tomcat 5.0 ,using Forward Action.This can... resolve this problems. Thanks & Regards Akhtar
how to use stringtokenizer on table? and display in table format.
display result in row format  how to use stringtokenizer on table? and display in table format
What are the problems in AI?
What are the problems in AI?  Hi, I am beginner in Data Science... are the problems in AI? Try to provide me good examples or tutorials links so that I can learn the topic "What are the problems in AI?". Also tell me
problems regrading .properties files
problems regrading .properties files  According to my struts application my i ve to register particular data into the DB..It will succefully registerd according to my validation condition which m placed in the validate mathod
ModuleNotFoundError: No module named 'drf-problems'
ModuleNotFoundError: No module named 'drf-problems'  Hi, My Python... 'drf-problems' How to remove the ModuleNotFoundError: No module named 'drf-problems' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'postman_problems'
ModuleNotFoundError: No module named 'postman_problems'  Hi, My... named 'postman_problems' How to remove the ModuleNotFoundError: No module named 'postman_problems' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'practice-problems'
ModuleNotFoundError: No module named 'practice-problems'  Hi, My... named 'practice-problems' How to remove the ModuleNotFoundError: No module named 'practice-problems' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'drf-problems'
ModuleNotFoundError: No module named 'drf-problems'  Hi, My Python... 'drf-problems' How to remove the ModuleNotFoundError: No module named 'drf-problems' error? Thanks   Hi, In your python
how to use stringtokenizer on table? and display in table format.
how to use stringtokenizer on table? and display in table format.  table is retrieved from mysql database and each row contains data like(java,c,c++,.net
Breaking a string into words without using StringTokenizer
Breaking a string into words without using StringTokenizer  how can we Break a string into words without using StringTokenizer ??   The given code convert the string into words. import java.util.*; class StringExample
Problems connecting to a database. Java/SQLite
Problems connecting to a database. Java/SQLite  `print("try { con = DriverManager.getConnection("jdbc:sqlite:db/Freepark.sqlite"); } catch... on an SQL database but i am having problems connecting to it, I think the problem
Java: Some problems in given condition
Java: Some problems in given condition   SIR, I want to get the values from the table( database), if any one of the column of the table value is 0. Then one alert should b printed in application using Java. If(att.getdata1()==0
start debugging problems related to the JDBC API
start debugging problems related to the JDBC API  How do I start debugging problems related to the JDBC API
problems in parsing the xml with the special characters
problems in parsing the xml with the special characters  Hi, I have a problem, in while parsing the xml with special characters apstrophe('). I am getting the exception Caused by: javax.xml.transform.TransformerException
ModuleNotFoundError: No module named 'practice-problems-builder-ktraff'
ModuleNotFoundError: No module named 'practice-problems-builder-ktraff' ...: ModuleNotFoundError: No module named 'practice-problems-builder-ktraff' How to remove the ModuleNotFoundError: No module named 'practice-problems-builder-ktraff'
ModuleNotFoundError: No module named 'solve-some-problems'
ModuleNotFoundError: No module named 'solve-some-problems'  Hi, My... named 'solve-some-problems' How to remove the ModuleNotFoundError: No module named 'solve-some-problems' error? Thanks   Hi
ModuleNotFoundError: No module named 'solve-some-problems'
ModuleNotFoundError: No module named 'solve-some-problems'  Hi, My... named 'solve-some-problems' How to remove the ModuleNotFoundError: No module named 'solve-some-problems' error? Thanks   Hi
ModuleNotFoundError: No module named 'jutge-problems-toolkit'
ModuleNotFoundError: No module named 'jutge-problems-toolkit'  Hi...: No module named 'jutge-problems-toolkit' How to remove the ModuleNotFoundError: No module named 'jutge-problems-toolkit' error? Thanks   Hi
nsstring get value - algebra multiplication problems
nsstring get value - algebra multiplication problems  NSString Algebra multiplication problems How can i get value of X using algebra multiplication problems in nsstring? if i have two values.. 3 + 8 + X
Struts 1.2.9 (NB6.1) ? Problems with depend <html:select> and AJAX - Struts
Struts 1.2.9 (NB6.1) ? Problems with depend and AJAX  Hi I have 2 and one is depend to the other The 1st select I fill it of the DB with the help of the jstl :) but the 2nd will fill of the DB too but taking the 1st
Ask Programming Questions and Discuss your Problems
Ask Programming Questions and Discuss your Problems       Dear Users, Analyzing your plenty of problems... all sorts of Java related problems round the clock. Believe it. Roseindia has
how to use StringTokenizer to retrieve the class name, attributes name and methods name from the Java Source Code
how to use StringTokenizer to retrieve the class name, attributes name and methods name from the Java Source Code  hi, I have done a program whereby... { StringTokenizer st = new StringTokenizer( line, "; " ); while
JavaMail flagging problems - JavaMail
J2me AddCommands and Dialog problems
jAVA BEGINNER PROBLEMS
Java StringTokenizer
Java StringTokenizer In this tutorial we will discuss about String Tokenizer... string into token,  first create a object of the StringTokenizer class, pass the string and the delimited string you want. StringTokenizer str = new
Input and Output problems - Java Beginners
Software Design
Software Design       The process of solving problems and planning for a software solution is known as software design. In this process, first the purpose
Java Error
that describes the serious problems that a reasonable application should not try to catch
Categorizing Design Patterns
;  Patterns focus on different types of problems. Related... identify the minimal set of known problems that application architecture should... with JEE development) to solve the problems.     
Introduction to Design Pattern
used to solve common object-oriented design issues (problems). When you design... should know at least some popular solutions to the coding problems. These solutions
Design Pattern
issues (problems). When you design a problem, you should know some common
Ask Programming Questions Online
, the integrated programming problems are also increasing. There are countless numbers... to share and sort out your problems. We have a strong network of software
Ask EJB Questions online
Ask EJB Questions online       Whether are you a nascent programmer or proficient Enterprise JavaBeans developer, you might have faced several critical problems
JS-Sorcerer: JavaScript Development Tool
JS-Sorcerer: JavaScript Development Tool       JavaScript Reporter finds problems... productivity by quickly locating and reporting problems in JavaScript code
Stay Safe Through a Home Security Mobile Application
security system will protect a home from invaders and other dangerous problems... any problems. A home security mobile application is one that can involve
Lint4j Eclipse Plugin
Lint4j Eclipse Plugin         Eclipse is the perfect environment for using Lint4j. Problems can be reported as soon as the source is saved, and the Eclipse problem
Protocols
-in solves these problems. With the Protocols plug-in, grouping is manifested both
Iteration
a set of values to solve real-world problems.  The for StatementADS
Wi-Fi Security for Public Networks
Wi-Fi Security for Public Networks       Introduction Wi-Fi hotspots present a unique set of security problems, quite different from the security issues involved in home and office

Ads