We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Precondition on FieldHyperlink.setAddress

Aspose.Words Java 19.2 Evaluation Version (on OSX)

What is the (apparently undocumented) precondition on FieldHyperlink.setAddress?

            String url = "https://www.google.com";
            FieldHyperlink hyperlink = new FieldHyperlink();
            hyperlink.setAddress(url); // This line throws a NullPointerException
            // hyperlink.setTarget(url); switching it for this throws same


Thanks for your inquiry. Please use DocumentBuilder.InsertField method as shown below to avoid the exception and get the desired output.

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
String url = "https://www.google.com";
FieldHyperlink hyperlink = (FieldHyperlink)builder.insertField(FieldType.FIELD_HYPERLINK, true);