SlideShare a Scribd company logo
Keep getting a null pointer exception for some odd reason
im creating the variable and the object but it still isnt working
My code is below please help
package classes;
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
import java.io.*;
import java.util.*;
import java.text.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class NewClass4
{
private class Node
{
private String text;
private int Hit;
private int Miss;
private Node next;
public Node(String text, int Hit, int Miss, Node next)
{
this.text=text;
this.Hit=Hit;
this.Miss=Miss;
this.next=next;
}
public void incrementHit()
{
this.Hit = this.Hit+1;
}
public void incrementMiss()
{
this.Miss = this.Miss+1;
}
public String getText()
{
return this.text;
}
public int getHit()
{
return this.Hit;
}
public int getMiss()
{
return this.Miss;
}
}//end of node
private class LL
{
public Node head;
public LL()
{
head=null;
}
public void insert(String text2, boolean isHit)
{
System.out.println("entered insert method");
Node temp=this.head;
System.out.println("sent temp node to head");
while((temp!=null) && (!temp.text.equals(text2)) )
{
temp=temp.next;
}
if(temp==null)
{
// we did not find the string
if(isHit)
{
this.head=new Node(text2,1, 0, this.head );
}
else
{
this.head=new Node(text2,0, 1, this.head );
}
}
else
{
if(isHit)
{
temp.incrementHit();
}
else
{
temp.incrementMiss();
}
}
}//end of insert
public void printList()
{
Node temp=this.head;
while(temp!=null)
{
int Hit=temp.getHit();
int Miss=temp.getMiss();
double sucRate=Hit*100/(Hit+Miss);
System.out.println(temp.getText() + " " + sucRate);
}
}
}// end of LL
private static LL myLL;
public NewClass4()
{
this.myLL = new LL();
}
public static void main(String[] args)
{
SimpleDateFormat sdf = new
SimpleDateFormat("dd/MMM/yyyy:HH:mm:ss",Locale.ENGLISH);
String myString = null;
Pattern a = Pattern.compile("[0-9]{2}/?[A-Za-z]{3,4}/?[0-9]{4}[.,-:]{1}[0-9.,-
:]{1,}s+");
Pattern d= Pattern.compile("s+/+[0-9.]{3}/+[A-Za-z]{1,}/+[A-Za-z.,-:%]{1,}");
Pattern f= Pattern.compile("s+[0-9]{3}s+");
String newLine;
try {
File file = new File("myFile.txt");
FileReader fileReader = new FileReader(file);
BufferedReader bufferedReader = new BufferedReader(fileReader);
String line;
while ((line = bufferedReader.readLine()) != null)
{
myString = line;
System.out.println(myString);
Matcher m1 = a.matcher(myString);
Matcher m2 = d.matcher(myString);
Matcher m3 = f.matcher(myString);
if (m1.find() && m2.find()&& m3.find())
try {
Date parsedDate = sdf.parse(m1.group());
SimpleDateFormat print = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm");
int responseCode = Integer.parseInt(m3.group().trim());
System.out.println(print.format(parsedDate)+ " "+m2.group()+" "+responseCode);
newLine = print.format(parsedDate)+ " "+m2.group();
// decide true or false
if (responseCode >= 500 )
{
if (NewClass4.myLL == null)
{
System.out.println("Link List is empty");
}
NewClass4.myLL.insert(newLine, false);
}
else
{
NewClass4.myLL.insert(newLine, true);
}
} // end of second try
catch (ParseException e)
{
e.printStackTrace();
}
}// end of while
fileReader.close();
//System.out.println("Contents of file:");
}//end of first try
catch (IOException e)
{
e.printStackTrace();
}
//Classes.myLL.printList();
}// end of main
}// end of Classes
Solution
package classes;
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
import java.io.*;
import java.util.*;
import java.text.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class NewClass4 {
private class Node {
private String text;
private int Hit;
private int Miss;
private Node next;
public Node(String text, int Hit, int Miss, Node next) {
this.text = text;
this.Hit = Hit;
this.Miss = Miss;
this.next = next;
}
public void incrementHit() {
this.Hit = this.Hit + 1;
}
public void incrementMiss() {
this.Miss = this.Miss + 1;
}
public String getText() {
return this.text;
}
public int getHit() {
return this.Hit;
}
public int getMiss() {
return this.Miss;
}
}// end of node
private class LL {
public Node head;
public LL() {
head = null;
}
public void insert(String text2, boolean isHit) {
System.out.println("entered insert method");
Node temp = this.head;
System.out.println("sent temp node to head");
while ((temp != null) && (!temp.text.equals(text2))) {
temp = temp.next;
}
if (temp == null) {
// we did not find the string
if (isHit) {
this.head = new Node(text2, 1, 0, this.head);
} else {
this.head = new Node(text2, 0, 1, this.head);
}
} else {
if (isHit) {
temp.incrementHit();
} else {
temp.incrementMiss();
}
}
}// end of insert
public void printList() {
Node temp = this.head;
while (temp != null) {
int Hit = temp.getHit();
int Miss = temp.getMiss();
double sucRate = Hit * 100 / (Hit + Miss);
System.out.println(temp.getText() + " " + sucRate);
}
}
}// end of LL
private static LL myLL;
public NewClass4() {
this.myLL = new LL();
}
public static void main(String[] args) {
SimpleDateFormat sdf = new SimpleDateFormat("dd/MMM/yyyy:HH:mm:ss",
Locale.ENGLISH);
String myString = null;
Pattern a = Pattern
.compile("[0-9]{2}/?[A-Za-z]{3,4}/?[0-9]{4}[.,-:]{1}[0-9.,-:]{1,}s+");
Pattern d = Pattern
.compile("s+/+[0-9.]{3}/+[A-Za-z]{1,}/+[A-Za-z.,-:%]{1,}");
Pattern f = Pattern.compile("s+[0-9]{3}s+");
String newLine;
try {
File file = new File("myFile.txt");
FileReader fileReader = new FileReader(file);
BufferedReader bufferedReader = new BufferedReader(fileReader);
String line;
while ((line = bufferedReader.readLine()) != null) {
myString = line;
System.out.println(myString);
Matcher m1 = a.matcher(myString);
Matcher m2 = d.matcher(myString);
Matcher m3 = f.matcher(myString);
if (m1.find() && m2.find() && m3.find())
try {
Date parsedDate = sdf.parse(m1.group());
SimpleDateFormat print = new SimpleDateFormat(
"yyyy-MM-dd'T'HH:mm");
int responseCode = Integer.parseInt(m3.group().trim());
System.out.println(print.format(parsedDate) + " "
+ m2.group() + " " + responseCode);
newLine = print.format(parsedDate) + " " + m2.group();
// decide true or false
if (responseCode >= 500) {
if (NewClass4.myLL == null) {
System.out.println("Link List is empty");
}
NewClass4.myLL.insert(newLine, false);
} else {
NewClass4.myLL.insert(newLine, true);
}
} // end of second try
catch (ParseException e) {
e.printStackTrace();
}
}// end of while
fileReader.close();
// System.out.println("Contents of file:");
}// end of first try
catch (IOException e) {
e.printStackTrace();
}
// Classes.myLL.printList();
}// end of main
}// end of Classes
myFile.txt
2011-06-14T04:12
2013-06-14T04:12
2012-06-14T04:12
Note: Please make sure the path of the file is in the project location, i think that is the problem

More Related Content

PDF
mainpublic class AssignmentThree {    public static void ma.pdf
PDF
Clean code
PDF
Creat Shape classes from scratch DETAILS You will create 3 shape cla.pdf
KEY
How to Start Test-Driven Development in Legacy Code
PDF
Step 1 The Pair Class Many times in writing software we come across p.pdf
PDF
Addressing Scenario
PDF
LECTURE 2 MORE TYPES, METHODS, CONDITIONALS.pdf
PPTX
Anti patterns
mainpublic class AssignmentThree {    public static void ma.pdf
Clean code
Creat Shape classes from scratch DETAILS You will create 3 shape cla.pdf
How to Start Test-Driven Development in Legacy Code
Step 1 The Pair Class Many times in writing software we come across p.pdf
Addressing Scenario
LECTURE 2 MORE TYPES, METHODS, CONDITIONALS.pdf
Anti patterns

Similar to Keep getting a null pointer exception for some odd reasonim creati.pdf (20)

PDF
Java VS Python
PDF
AnswerNote Provided code shows several bugs, hence I implemented.pdf
PDF
To write a program that implements the following C++ concepts 1. Dat.pdf
PDF
Modify HuffmanTree.java and HuffmanNode.java to allow the user to se.pdf
PPT
Whats new in_csharp4
PDF
OrderTest.javapublic class OrderTest {       Get an arra.pdf
PPT
Clean code _v2003
PDF
The purpose of this C++ programming project is to allow the student .pdf
DOCX
Table.java Huffman code frequency tableimport java.io.;im.docx
PPTX
A Details Overview How to Use Typescript Generic Type
PDF
Assignment is Page 349-350 #4 and #5 Use the Linked Lis.pdf
PPT
2012 JDays Bad Tests Good Tests
PDF
HELP IN JAVACreate a main method and use these input files to tes.pdf
DOCX
DS Code (CWH).docx
PPTX
R. herves. clean code (theme)2
PDF
TypeScript Introduction
PDF
JAVA OOP project; desperately need help asap im begging.Been stuck.pdf
PPT
06slide.ppt
PPTX
Java generics
DOCX
4.3 Hibernate example.docx
Java VS Python
AnswerNote Provided code shows several bugs, hence I implemented.pdf
To write a program that implements the following C++ concepts 1. Dat.pdf
Modify HuffmanTree.java and HuffmanNode.java to allow the user to se.pdf
Whats new in_csharp4
OrderTest.javapublic class OrderTest {       Get an arra.pdf
Clean code _v2003
The purpose of this C++ programming project is to allow the student .pdf
Table.java Huffman code frequency tableimport java.io.;im.docx
A Details Overview How to Use Typescript Generic Type
Assignment is Page 349-350 #4 and #5 Use the Linked Lis.pdf
2012 JDays Bad Tests Good Tests
HELP IN JAVACreate a main method and use these input files to tes.pdf
DS Code (CWH).docx
R. herves. clean code (theme)2
TypeScript Introduction
JAVA OOP project; desperately need help asap im begging.Been stuck.pdf
06slide.ppt
Java generics
4.3 Hibernate example.docx
Ad

More from AroraRajinder1 (20)

PDF
In class, we talked about all sorts of experiments. I would like to s.pdf
PDF
Jane Lee was employed as a secretary at Burton Trucking. She was fire.pdf
PDF
If a function F) performs the following operations, what knd of cohe.pdf
PDF
How would a subculture appear if a colony containing both S. Marce.pdf
PDF
Hint Assume the binary tree is properly balanced (the depth of the .pdf
PDF
essay question Explain how everyday life changes for slaves after e.pdf
PDF
Detection versus recognition ... Investigate Face++ at Feel free to.pdf
PDF
Dent disease is a rare disorder of the kidney in which reabsorption o.pdf
PDF
DEFINE maternal determinant (3-4 sentences).SolutionMaternal .pdf
PDF
Consider a partial function.For every unmapped element in its doma.pdf
PDF
Compare and Contrast hollow core fibers for high power delivery an.pdf
PDF
Can we create an object of type Interface Explain your answer.So.pdf
PDF
Cancel QuestionSolutionSince Descriptive statistics uses the d.pdf
PDF
According to the cladogram, what derived trait is shared by primates .pdf
PDF
A male Flagus fly with the Barkus phenotype is crossed with a female.pdf
PDF
2015Matthew and Michael Goode (cousins) decide to form a partners.pdf
PDF
1. Jose is a Latino client who presents with occupational difficulti.pdf
PDF
You have a small business customer who wants to use a voice over IP .pdf
PDF
Why can some microbial species grow and survive in extreme environ.pdf
PDF
Which prokaryotic group maps most closely to the chlorophyll of plan.pdf
In class, we talked about all sorts of experiments. I would like to s.pdf
Jane Lee was employed as a secretary at Burton Trucking. She was fire.pdf
If a function F) performs the following operations, what knd of cohe.pdf
How would a subculture appear if a colony containing both S. Marce.pdf
Hint Assume the binary tree is properly balanced (the depth of the .pdf
essay question Explain how everyday life changes for slaves after e.pdf
Detection versus recognition ... Investigate Face++ at Feel free to.pdf
Dent disease is a rare disorder of the kidney in which reabsorption o.pdf
DEFINE maternal determinant (3-4 sentences).SolutionMaternal .pdf
Consider a partial function.For every unmapped element in its doma.pdf
Compare and Contrast hollow core fibers for high power delivery an.pdf
Can we create an object of type Interface Explain your answer.So.pdf
Cancel QuestionSolutionSince Descriptive statistics uses the d.pdf
According to the cladogram, what derived trait is shared by primates .pdf
A male Flagus fly with the Barkus phenotype is crossed with a female.pdf
2015Matthew and Michael Goode (cousins) decide to form a partners.pdf
1. Jose is a Latino client who presents with occupational difficulti.pdf
You have a small business customer who wants to use a voice over IP .pdf
Why can some microbial species grow and survive in extreme environ.pdf
Which prokaryotic group maps most closely to the chlorophyll of plan.pdf
Ad

Recently uploaded (20)

PDF
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PDF
Computing-Curriculum for Schools in Ghana
PDF
01-Introduction-to-Information-Management.pdf
PPTX
Pharma ospi slides which help in ospi learning
PPTX
Cell Types and Its function , kingdom of life
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PDF
O7-L3 Supply Chain Operations - ICLT Program
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PDF
Module 4: Burden of Disease Tutorial Slides S2 2025
PDF
Anesthesia in Laparoscopic Surgery in India
PDF
Microbial disease of the cardiovascular and lymphatic systems
PPTX
PPH.pptx obstetrics and gynecology in nursing
PPTX
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
PPTX
Institutional Correction lecture only . . .
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PPTX
master seminar digital applications in india
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
Supply Chain Operations Speaking Notes -ICLT Program
102 student loan defaulters named and shamed – Is someone you know on the list?
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
Computing-Curriculum for Schools in Ghana
01-Introduction-to-Information-Management.pdf
Pharma ospi slides which help in ospi learning
Cell Types and Its function , kingdom of life
O5-L3 Freight Transport Ops (International) V1.pdf
O7-L3 Supply Chain Operations - ICLT Program
STATICS OF THE RIGID BODIES Hibbelers.pdf
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
Module 4: Burden of Disease Tutorial Slides S2 2025
Anesthesia in Laparoscopic Surgery in India
Microbial disease of the cardiovascular and lymphatic systems
PPH.pptx obstetrics and gynecology in nursing
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
Institutional Correction lecture only . . .
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
master seminar digital applications in india

Keep getting a null pointer exception for some odd reasonim creati.pdf

  • 1. Keep getting a null pointer exception for some odd reason im creating the variable and the object but it still isnt working My code is below please help package classes; /* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ import java.io.*; import java.util.*; import java.text.*; import java.util.regex.Matcher; import java.util.regex.Pattern; public class NewClass4 { private class Node { private String text; private int Hit; private int Miss; private Node next; public Node(String text, int Hit, int Miss, Node next) { this.text=text; this.Hit=Hit; this.Miss=Miss; this.next=next; } public void incrementHit() { this.Hit = this.Hit+1; } public void incrementMiss()
  • 2. { this.Miss = this.Miss+1; } public String getText() { return this.text; } public int getHit() { return this.Hit; } public int getMiss() { return this.Miss; } }//end of node private class LL { public Node head; public LL() { head=null; } public void insert(String text2, boolean isHit) { System.out.println("entered insert method"); Node temp=this.head; System.out.println("sent temp node to head"); while((temp!=null) && (!temp.text.equals(text2)) ) { temp=temp.next; } if(temp==null) { // we did not find the string if(isHit)
  • 3. { this.head=new Node(text2,1, 0, this.head ); } else { this.head=new Node(text2,0, 1, this.head ); } } else { if(isHit) { temp.incrementHit(); } else { temp.incrementMiss(); } } }//end of insert public void printList() { Node temp=this.head; while(temp!=null) { int Hit=temp.getHit(); int Miss=temp.getMiss(); double sucRate=Hit*100/(Hit+Miss); System.out.println(temp.getText() + " " + sucRate); } } }// end of LL private static LL myLL; public NewClass4()
  • 4. { this.myLL = new LL(); } public static void main(String[] args) { SimpleDateFormat sdf = new SimpleDateFormat("dd/MMM/yyyy:HH:mm:ss",Locale.ENGLISH); String myString = null; Pattern a = Pattern.compile("[0-9]{2}/?[A-Za-z]{3,4}/?[0-9]{4}[.,-:]{1}[0-9.,- :]{1,}s+"); Pattern d= Pattern.compile("s+/+[0-9.]{3}/+[A-Za-z]{1,}/+[A-Za-z.,-:%]{1,}"); Pattern f= Pattern.compile("s+[0-9]{3}s+"); String newLine; try { File file = new File("myFile.txt"); FileReader fileReader = new FileReader(file); BufferedReader bufferedReader = new BufferedReader(fileReader); String line; while ((line = bufferedReader.readLine()) != null) { myString = line; System.out.println(myString); Matcher m1 = a.matcher(myString); Matcher m2 = d.matcher(myString); Matcher m3 = f.matcher(myString); if (m1.find() && m2.find()&& m3.find()) try { Date parsedDate = sdf.parse(m1.group()); SimpleDateFormat print = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm"); int responseCode = Integer.parseInt(m3.group().trim()); System.out.println(print.format(parsedDate)+ " "+m2.group()+" "+responseCode); newLine = print.format(parsedDate)+ " "+m2.group(); // decide true or false if (responseCode >= 500 ) {
  • 5. if (NewClass4.myLL == null) { System.out.println("Link List is empty"); } NewClass4.myLL.insert(newLine, false); } else { NewClass4.myLL.insert(newLine, true); } } // end of second try catch (ParseException e) { e.printStackTrace(); } }// end of while fileReader.close(); //System.out.println("Contents of file:"); }//end of first try catch (IOException e) { e.printStackTrace(); } //Classes.myLL.printList(); }// end of main }// end of Classes Solution package classes; /* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */
  • 6. import java.io.*; import java.util.*; import java.text.*; import java.util.regex.Matcher; import java.util.regex.Pattern; public class NewClass4 { private class Node { private String text; private int Hit; private int Miss; private Node next; public Node(String text, int Hit, int Miss, Node next) { this.text = text; this.Hit = Hit; this.Miss = Miss; this.next = next; } public void incrementHit() { this.Hit = this.Hit + 1; } public void incrementMiss() { this.Miss = this.Miss + 1; } public String getText() { return this.text; } public int getHit() { return this.Hit; } public int getMiss() { return this.Miss; } }// end of node private class LL { public Node head; public LL() {
  • 7. head = null; } public void insert(String text2, boolean isHit) { System.out.println("entered insert method"); Node temp = this.head; System.out.println("sent temp node to head"); while ((temp != null) && (!temp.text.equals(text2))) { temp = temp.next; } if (temp == null) { // we did not find the string if (isHit) { this.head = new Node(text2, 1, 0, this.head); } else { this.head = new Node(text2, 0, 1, this.head); } } else { if (isHit) { temp.incrementHit(); } else { temp.incrementMiss(); } } }// end of insert public void printList() { Node temp = this.head; while (temp != null) { int Hit = temp.getHit(); int Miss = temp.getMiss(); double sucRate = Hit * 100 / (Hit + Miss); System.out.println(temp.getText() + " " + sucRate); } } }// end of LL private static LL myLL; public NewClass4() {
  • 8. this.myLL = new LL(); } public static void main(String[] args) { SimpleDateFormat sdf = new SimpleDateFormat("dd/MMM/yyyy:HH:mm:ss", Locale.ENGLISH); String myString = null; Pattern a = Pattern .compile("[0-9]{2}/?[A-Za-z]{3,4}/?[0-9]{4}[.,-:]{1}[0-9.,-:]{1,}s+"); Pattern d = Pattern .compile("s+/+[0-9.]{3}/+[A-Za-z]{1,}/+[A-Za-z.,-:%]{1,}"); Pattern f = Pattern.compile("s+[0-9]{3}s+"); String newLine; try { File file = new File("myFile.txt"); FileReader fileReader = new FileReader(file); BufferedReader bufferedReader = new BufferedReader(fileReader); String line; while ((line = bufferedReader.readLine()) != null) { myString = line; System.out.println(myString); Matcher m1 = a.matcher(myString); Matcher m2 = d.matcher(myString); Matcher m3 = f.matcher(myString); if (m1.find() && m2.find() && m3.find()) try { Date parsedDate = sdf.parse(m1.group()); SimpleDateFormat print = new SimpleDateFormat( "yyyy-MM-dd'T'HH:mm"); int responseCode = Integer.parseInt(m3.group().trim()); System.out.println(print.format(parsedDate) + " " + m2.group() + " " + responseCode); newLine = print.format(parsedDate) + " " + m2.group(); // decide true or false if (responseCode >= 500) { if (NewClass4.myLL == null) { System.out.println("Link List is empty");
  • 9. } NewClass4.myLL.insert(newLine, false); } else { NewClass4.myLL.insert(newLine, true); } } // end of second try catch (ParseException e) { e.printStackTrace(); } }// end of while fileReader.close(); // System.out.println("Contents of file:"); }// end of first try catch (IOException e) { e.printStackTrace(); } // Classes.myLL.printList(); }// end of main }// end of Classes myFile.txt 2011-06-14T04:12 2013-06-14T04:12 2012-06-14T04:12 Note: Please make sure the path of the file is in the project location, i think that is the problem