eclipse plugin - how to format a code which is in string to java format -


i developing wizard page. in page converting file string , displaying in text box

but want display text in java format have tried below code

import org.eclipse.jdt.core.toolfactory; import org.eclipse.jdt.core.formatter.codeformatter; import org.eclipse.jface.text.badlocationexception; import org.eclipse.jface.text.document; import org.eclipse.jface.text.idocument; import org.eclipse.text.edits.malformedtreeexception; import org.eclipse.text.edits.textedit;     public class formattertest {         public static void main(string[] args) {             string code = pagehandlercontent; //the file im getting , saving in string             codeformatter codeformatter = toolfactory.createcodeformatter(null);             textedit textedit = codeformatter.format(codeformatter.k_compilation_unit, code, 0, code.length(), 0, null);             idocument doc = new document(code);             try {                 textedit.apply(doc);                 system.out.println(doc.get());             } catch (malformedtreeexception e) {                 e.printstacktrace();             } catch (badlocationexception e) {                 e.printstacktrace();             }         }     } 

but getting null pointer exception @ textedit.apply(doc) line

your codeformatter null

codeformatter codeformatter = toolfactory.createcodeformatter(null);

note: cant write comment


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -