JavaXPCOM and nsIAlertsService
Guy Rosen <[email protected]>
| Newsgroups | gmane.comp.mozilla.devel.java |
|---|---|
| Message-ID | <44SdnV9crPkkEDfZnZ2dnUVZ_s6dnZ2d__9666.13608547977$1152028224$gmane$org@mozilla.org> |
Hi all,
I'm trying to get my first application with JavaXPCOM running, and I'm
probably doing something very wrong. I wanted to take advantage of the
nsIAlertsService which I've used successfully from with Firefox
extensions and display a similar alert from within my Java app.
This uses xulrunner 1.8.0.1, Java 1.5.0.07. I get the following error
when running it:
Exception in thread "main" org.mozilla.xpcom.XPCOMException: The
function "showAlertNotification" returned an error condition (0x80004005)
at
org.mozilla.xpcom.internal.XPCOMJavaProxy.callXPCOMMethod(Native Method)
at
org.mozilla.xpcom.internal.XPCOMJavaProxy.invoke(XPCOMJavaProxy.java:140)
at $Proxy1.showAlertNotification(Unknown Source)
at TestAlert.main(TestAlert.java:13)
The Java code is below. Where did I go wrong?
Thanks!
--------->8----------
import org.mozilla.xpcom.*;
import java.io.*;
public class TestAlert {
public static void main(String[] args) throws Exception {
Mozilla mozilla = Mozilla.getInstance();
File here = new java.io.File(new
java.io.File("").getAbsolutePath());
LocationProvider l = new LocationProvider(here);
mozilla.initEmbedding(here, here, l);
nsIServiceManager sm = mozilla.getServiceManager();
nsIAlertsService alertService =
(nsIAlertsService)sm.getServiceByContractID("@mozilla.org/alerts-service;1",
nsIAlertsService.NS_IALERTSSERVICE_IID);
alertService.showAlertNotification("", "Title", "Text", false,
"", null);
}
}
class LocationProvider implements IAppFileLocProvider {
File libXULPath;
public LocationProvider(File aBinPath) throws FileNotFoundException {
libXULPath = aBinPath;
if (!libXULPath.exists() || !libXULPath.isDirectory())
throw new FileNotFoundException("libxul directory specified
is not valid: "
+
libXULPath.getAbsolutePath());
}
public File getFile(String aProp, boolean[] aPersistent) {
File file = null;
if (aProp.equals("GreD") || aProp.equals("GreComsD")) {
file = libXULPath;
if (aProp.equals("GreComsD")) {
file = new File(file, "components");
}
}
else if (aProp.equals("MozBinD") ||
aProp.equals("CurProcD") ||
aProp.equals("ComsD") ||
aProp.equals("ProfD"))
{
file = libXULPath;
if (aProp.equals("ComsD")) {
file = new File(file, "components");
}
}
return file;
}
public File[] getFiles(String aProp) {
File[] files = null;
if (aProp.equals("APluginsDL")) {
files = new File[1];
files[0] = new File(libXULPath, "plugins");
}
return files;
}
}