Exception in thread "main" java.lang.IllegalStateException: ??

Hello Experts,

I need your assistance about the following error:
Exception in thread "main" java.lang.IllegalStateException: No match found
      at java.util.regex.Matcher.group(Matcher.java:461)
      at Parse.<init>(Parse.java:75)
      at Parse.main(Parse.java:26)


Thanks in advance for any help !
//PARSE CLASS:
 
import java.io.BufferedReader;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.text.DateFormat;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Date;
import java.util.Locale;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
 
public class Parse {
 
	ArrayList <Customer> custlist = new ArrayList <Customer>();
 
 
	public static void main(String[] args) throws java.io.IOException, NumberFormatException, ParseException {
 
		new Parse();
	}
 
	public Parse() throws ParseException, NumberFormatException, IOException
	{
		String line = null;
		BufferedReader in = new BufferedReader(new FileReader("Customers.txt"));
		Pattern namePattern = Pattern.compile("Name: (.*)");
		Pattern customerNoPattern = Pattern.compile("Customer no: (.*)");
		Pattern postCodePattern = Pattern.compile("Post code: (.*)");
		DecimalFormat nf = new DecimalFormat("ddd");
		DateFormat df = DateFormat.getDateInstance();
		line = null;
		while (null != (line = in.readLine())) {
 
			String name = null;
			Matcher nameMatcher = namePattern.matcher(line);
			if (nameMatcher.matches()){
				name = nameMatcher.group(1);
			}
 
			String customerNumber = null;
			double customerNo = 0;
			Matcher customerNoMatcher = customerNoPattern.matcher(line);
			if (customerNoMatcher.matches()){
				customerNumber = customerNoMatcher.group(1);
				customerNo = Double.parseDouble(customerNumber);
 
			}
 
 
			String postCode=null;;
			Matcher postCodeMatcher = postCodePattern.matcher(line);
			if (postCodeMatcher.matches()){
				postCode = postCodeMatcher.group(1);
			}
 
			String telephone = null;
			int telephoneNo = 0;
			Pattern telephoneNoPattern = Pattern.compile("Telephone no: (.*)");
			Matcher telephoneNoMatcher = telephoneNoPattern.matcher(line);
			if (telephoneNoMatcher.matches()){
				telephone = telephoneNoMatcher.group(1);
				telephoneNo = Integer.parseInt(telephone);
			}
 
			String lastdate = null;
			Pattern lastModifiedPattern = Pattern.compile("Last modified: (.*)");
			Matcher lastModifiedMatcher = lastModifiedPattern.matcher(line);
			lastdate = lastModifiedMatcher.group(1);
			Date lastModified = df.parse(lastdate);
 
			Customer s = new Customer(name, customerNo, postCode, telephoneNo, lastModified);
			custlist.add( s);
		}
 
	}
 
 
	void fmtDateNumber(Locale loc) throws IOException
	{
		FileWriter fw;
		fw = null;
		try {
			fw = new FileWriter("Customers" + loc.getDisplayCountry() + ".txt");
		} catch (final IOException ioe) {
			System.out.println("Error");
		}
		final NumberFormat numfmt = NumberFormat.getNumberInstance(loc);
		final DateFormat datafmt = DateFormat.getDateTimeInstance(DateFormat.DEFAULT, DateFormat.DEFAULT, loc);
		for (final Customer c: custlist) {
			fw.write("Name: " + c.getName()+"\n");
			fw.write("Customer no: " + numfmt.format(c.getCustomerNo())+"\n");
			fw.write("Post code: " + c.getPostCode()+"\n");
			fw.write("Telephone no: " + c.getTelephoneNo()+"\n");
			fw.write("Last modified: " + datafmt.format(c.getLastModified())+"\n");
		}
		try {
			fw.close();
		} catch (final IOException ioe) {
			System.out.println("Error");
		}
	}
 
	void fmtDateNumberBinary(Locale loc) throws IOException
	{
 
		FileOutputStream out = new FileOutputStream("Customers" + loc.getDisplayCountry() + ".dat");
		ObjectOutputStream s = new ObjectOutputStream(out);
 
		final NumberFormat numfmt = NumberFormat.getNumberInstance(loc);
		final DateFormat datafmt = DateFormat.getDateTimeInstance(DateFormat.DEFAULT, DateFormat.DEFAULT, loc);
		for (final Customer c: custlist) {
			s.writeObject("Name: " + c.getName()+"\n");
			s.writeObject("Customer no: " + numfmt.format(c.getCustomerNo())+"\n");
			s.writeObject("Post code: " + c.getPostCode()+"\n");
			s.writeObject("Telephone no: " + c.getTelephoneNo()+"\n");
			s.writeObject("Last modified: " + datafmt.format(c.getLastModified())+"\n");
 
			out.close();
			s.close();
		}
	}
 
 
 
 
	public void saveIndex()
	{
		ObjectOutputStream output;
 
		try
		{
			output = new ObjectOutputStream(new FileOutputStream( "Customers.index" ) );
			output.writeObject(custlist);
			output.close();
		}
		catch ( IOException ioException )
		{
			System.err.println( "Error opening file" );
		}
 
	}
 
 
 
}
 
 
 
 
 
 
 
import java.util.Date;
 
 
//CUSTOMER CLASS:
 
class Customer
{
 
 
	private String name;
	private double customerNo;
	private String postCode;
	private int telephoneNo;
	private Date lastModified;
	public Customer( String name,double customerNo, String postCode,int telephoneNo, Date lastModified)
	{
		this.name=name;
		this.customerNo=customerNo;
		this.postCode=postCode;
		this.telephoneNo=telephoneNo;
		this.lastModified=lastModified;
	}
 
 
	public String getName() {
		String name = null;
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public double getCustomerNo() {
		double customerNo = 0;
		return customerNo;
	}
	public void setCustomerNo(double customerNo) {
		this.customerNo = customerNo;
	}
	public String getPostCode() {
		String postCode = null;
		return postCode;
	}
	public void setPostCode(String postCode) {
		this.postCode = postCode;
	}
	public int getTelephoneNo() {
		int telephoneNo = 0;
		return telephoneNo;
	}
	public void setTelephoneNo(int telephoneNo) {
		this.telephoneNo = telephoneNo;
	}
	public Date getLastModified() {
		Date lastModified = null;
		return lastModified;
	}
	public void setLastModified(Date lastModified) {
		this.lastModified = lastModified;
	}
 
}

Open in new window

perdoname_Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

CEHJCommented:
You can't call group if there's no match. I've already posted code that does this for you in a much simpler way
0
ksivananthCommented:
you can check if there is a match before calling group,

matcher.find()
0
perdoname_Author Commented:
The point is that i cant use that code because it parses a country-specific version date only :s

But i cant understand why it returns the error it should be a match :S
Thats a part of the text file :

Name: Sarah Thomas
Customer no: 96,343
Post code: BA1 5BA
Telephone no: 0125-9423349
Last modified: Jun 12, 2006 10:50:00 AM GMT

0
Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

CEHJCommented:
>>The point is that i cant use that code because it parses a country-specific version date only :s

Not quite sure what you mean there, but the date parsing is of course changeable
0
cmalakarCommented:
You should have lastModifiedMatcher.matches() check for lastModifiedMatcher() too..

Because, as you read each line from the file.. you are trying to match the line, with each pattern..

Hence, when you read the first line.. "Name: Sarah Thomas", this will not match with the "Last modified" pattern..

and hence exception...

surround the following line.. with check as follows..

if(lastModifiedMatcher.matches())
{
   lastdate = lastModifiedMatcher.group(1);
}
 
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
CEHJCommented:
>>The point is that i cant use that code because it parses a country-specific version date only :s

As it happens, the date in your example is not parseable with a UK Locale, which i'm guessing is the one you're using
0
perdoname_Author Commented:
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.