Sai Surya Sai Surya - 7 months ago 24
HTML Question

Syntax Error on token expected. Please help me with this

package com.html;


public class Link {

File htmlTemplateFile = new File("email-template.html");
String htmlString = FileUtils.readFileToString(htmlTemplateFile,"UTF-8");
String Requestor = "Eva Schaubs";
String Transaction_ID = "FD_20160817094502";
String TicketNumber1 ="0034317479";
String TicketNumber2 ="0034317480";
String Description1 ="Request for Desktop";
String Description2 ="Request for New Phone";
String Asset_Name1 ="Desktop PC";
String Asset_Name2 ="Phone";
String Classification1 ="PROCUREMENT_NEW";
String Classification2 ="NEW/CREATION";
String Group1 ="NAFTA_MBUSA_Asset_Mgm";
String Group2 ="NAFTA_DC_TELEPHONY";
String Status1 ="ACTIVE";
String Status2 ="ACTIVE";
htmlString = htmlString.replace("$Requestor", Requestor);
htmlString = htmlString.replace("$Transaction_ID", Transaction_ID);
htmlString = htmlString.replace("$TicketNumber1", TicketNumber1);
htmlString = htmlString.replace("$TicketNumber2", TicketNumber2);
htmlString = htmlString.replace("$Description1", Description1);
htmlString = htmlString.replace("$Description2", Description2);
htmlString = htmlString.replace("$Asset_Name1", Asset_Name1);
htmlString = htmlString.replace("$Asset_Name2", Asset_Name2);
htmlString = htmlString.replace("$Classification1", Classification1);
htmlString = htmlString.replace("$Classification2", Classification2);
htmlString = htmlString.replace("$Group1", Group1);
htmlString = htmlString.replace("$Group2", Group2);
htmlString = htmlString.replace("$Status1", Status1);
htmlString = htmlString.replace("$Status2", Status2);

File newHtmlFile = new File("path/new.html");
FileUtils.writeStringToFile(newHtmlFile, htmlString);


This throws an error.. asking for closing of token.. at line "String Status2"
I dont know what silly mistake I made.. But please help me.


Your problem is very simply:

If you want to have a sequence of statements directly within a class, you need a block around that, like:

class SomeClass {
  String someField;
    someField = "foo";
    someField = "ah, better make me bar";

But of course: this is would be very bad practice. Instead, you should have various methods that do such work; maybe one called "readHtmlTemplate()"; and another one "replacePatternsInHtml()" and so on.

Your style of coding is like one huge "no-go".