Ich habe Java studiert und ich wollte eine Anwendung erstellen, die andere Anwendungen wie Terminal auf dem Mac öffnen wird.RunTime Execute On Mac
Ich habe mehrfach versagt, es zur Arbeit zu bringen, und ich bin an dieser Stelle ein wenig verwirrt.
Hier ist mein Code
package pac;
import java.awt.Desktop;
import java.io.File;
import java.io.IOException;
import javax.swing.*;
public class VnET extends JFrame {
public VnET() {
JFrame frame = new JFrame("Frame");
//Optional: What happens when the frame closes?
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// Create components and put them in the frame.
frame.setTitle("VnET");
// Size the frame.
frame.setSize(500, 250);;
// Show it.
frame.setVisible(true);
//centers window
frame.setLocationRelativeTo(null);
}
public static void main(String args[]) {
SwingUtilities.invokeLater(new Runnable(){
public void run() {
new VnET();
Runtime r = Runtime.getRuntime();
Process p = null;
try {
p = r.exec("Terminal");
p.waitFor();
} catch (Exception e) {
System.out.println("Error executing terminal");
}
System.out.println("Terminal returned"+ p.exitValue());
}
});
}
}
Und das ist das Konsolenprotokoll
Error executing terminal
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at pac.VnET$1.run(VnET.java:43)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:311)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:756)
at java.awt.EventQueue.access$500(EventQueue.java:97)
at java.awt.EventQueue$3.run(EventQueue.java:709)
at java.awt.EventQueue$3.run(EventQueue.java:703)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:726)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)
Mögliche Duplikate von [Was ist eine NullPointerException, und wie behebe ich es?] (Http://stackoverflow.com/questions/218384/what-is-a-nullpointerexception-and-how-do-i-fix -it) –
Ist "Terminal" ein gültiger Befehl auf Mac? Wenn nicht 'p' wäre null. Mit printStackTrace() im catch-Block erhalten Sie eine bessere Vorstellung davon, was falsch ist. – sreejit
Welche Linie ist Linie 43 auf VnET? – Frakcool