Okay, I've worked around this in a different way. I'll put everything in to help others out. Firstly I needed a workspace object which can be returned as follows:
static IWorkspace openWorkspace(String pathToFile)throws Exception
{
IWorkspaceFactory workspaceFactory = new FileGDBWorkspaceFactory();
return workspaceFactory.openFromFile(pathToFile, 0);
}
Following that it was table building time. I've adapted the following code from a C# snippet I found online. Instead of asking for an IWorkspace2 object this javised version asks for an IWorkspace object. There's not a lot of other differences apart from casting the workspace object later on in order to use the IWorkspace2 interface briefly and slight changes to the checkFields inputs.The IGeoprocessor bit is just me trying to find the current workspace of the user which can then obviously be passed to the method above.
public ITable createTable(IWorkspace workspace, String nameOfTable, IFields fields) throws Exception {
System.out.println("" + openWorkspace("C:\\GIS\\Test.gdb"));
/*
IGeoProcessor geop = new GeoProcessor();
String userWkSp = (String) geop.getEnvironmentValue("workspace");
System.out.println("user workpace = " + userWkSp);
*/
// create the behavior clasid for the featureclass
UID uid = new UID();
if (workspace == null) return null; // valid feature workspace not passed in as an argument to the method
IFeatureWorkspace featureWorkspace = (IFeatureWorkspace)workspace; // Explicit Cast
ITable table;
System.out.println("Got this far");
IWorkspace2 wkSp2 = (IWorkspace2) workspace;
if (wkSp2.isNameExists(esriDatasetType.esriDTTable, nameOfTable))
{
// table with that name already exists return that table
table = featureWorkspace.openTable(nameOfTable);
return table;
}
uid.setValue("esrigeodatabase.Object");
IObjectClassDescription objectClassDescription = new ObjectClassDescription();
// if a fields collection is not passed in then supply our own
if (fields == null)
{
// create the fields using the required fields method
fields = objectClassDescription.getRequiredFields();
IFieldsEdit fieldsEdit = (IFieldsEdit)fields; // Explicit Cast
IField field = new Field();
// create a user defined text field
IFieldEdit fieldEdit = (IFieldEdit)field; // Explicit Cast
// setup field properties
fieldEdit.setName("SampleField");
fieldEdit.setType(esriFieldType.esriFieldTypeString);
fieldEdit.setAliasName("Sample Field Column");
fieldEdit.setDefaultValue("test");
fieldEdit.setLength(100);
// add field to field collection
fieldsEdit.addField(field);
fields = (IFields)fieldsEdit; // Explicit Cast
}
// Use IFieldChecker to create a validated fields collection.
IFieldChecker fieldChecker = new FieldChecker();
IEnumFieldError enumFieldError[] = null;
IFields validatedFields[] = null;
fieldChecker.setValidateWorkspaceByRef((IWorkspace)workspace);
fieldChecker.validate(fields, enumFieldError, validatedFields);
// The enumFieldError enumerator can be inspected at this point to determine
// which fields were modified during validation.
// create and return the table
table = featureWorkspace.createTable(nameOfTable, fields, uid, uid, "");
return table;
}