Win a copy of Zero to AI - A non-technical, hype-free guide to prospering in the AI era this week in the Artificial Intelligence and Machine Learning forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Paul Clapham
  • Bear Bibeault
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Jj Roberts
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • salvin francis
  • Scott Selikoff
  • fred rosenberger

java SWT application giving error while executing jar file

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI all,

I had created one SWT(java) application using net beans IDE. As i set all the jar files which is required to run this application. its running in development platform. but when i build this application in net beans and try to execute the jar file its giving error.



C:\Documents and Settings\Asif>java -jar "C:\Documents and Settings\Asif\My Documents\NetBeansProjects\JavaApplicatio\dist\JavaApplication2.jar"

following is the error.


Exception in thread "main" java.lang.NoClassDefFoundError: org/eclipse/swt/events/MouseListener at java.lang.ClassLoader.defineClass1(Native Method) at java.lang.ClassLoader.defineClass(Unknown Source) at java.security.SecureClassLoader.defineClass(Unknown Source) at java.net.URLClassLoader.defineClass(Unknown Source) at java.net.URLClassLoader.access$000(Unknown Source) at java.net.URLClassLoader$1.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at java.lang.ClassLoader.loadClassInternal(Unknown Source) at javaapplication2.DragAndDropExample.main(DragAndDropExample.java:23) Caused by: java.lang.ClassNotFoundException: org.eclipse.swt.events.MouseListener at java.net.URLClassLoader$1.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at java.lang.ClassLoader.loadClassInternal(Unknown Source) ... 13 more


And Here is the Source code.

its having two files.

1) DragAndDropExample.java




package javaapplication2;

public class DragAndDropExample {
public static void main(String[] args) {
NewClass ob=new NewClass();
ob.getthatworkdone();
}
}


2) NewClass.java



package javaapplication2;





import java.awt.Font;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import javax.swing.JPanel;
import javax.swing.JTextField;
import org.eclipse.swt.SWT;
import org.eclipse.swt.dnd.*;
import org.eclipse.swt.events.MouseAdapter;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.TreeAdapter;
import org.eclipse.swt.events.TreeEvent;
import org.eclipse.swt.events.TreeListener;
import org.eclipse.swt.graphics.FontData;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.graphics.RGB;
import org.eclipse.swt.widgets.*;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.TreeEditor;
import org.eclipse.swt.events.FocusAdapter;
import org.eclipse.swt.events.FocusEvent;
import org.eclipse.swt.graphics.RGB;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.widgets.Tree;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.FontData;
import org.eclipse.swt.graphics.RGB;

//import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.FontDialog;
//import org.eclipse.swt.events.MouseListener;
import org.eclipse.swt.events.*;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;

import org.eclipse.swt.widgets.TreeItem;


public class NewClass implements org.eclipse.swt.events.MouseListener

{
public int count=0;
TreeItem itemSecond;
Shell shell;
public Display display ;
Text newtext;
Tree tree1;
// Point point;
static StringBuilder fulltext=new StringBuilder();
Text displaytext;
JPanel panel;
int countofresult=0;
public NewClass()
{


}



public void getthatworkdone()
{

try
{
display = new Display();
shell = new Shell(display,SWT.RESIZE | SWT.TITLE | SWT.CLOSE | SWT.MAX | SWT.MIN);
panel=new JPanel();


// shell.setLayout(new FillLayout());
shell.setText("Drag and Drop");
shell.setSize(100,100);
shell.setLocation(0,0);

Button b1 = new Button(shell, SWT.BOTTOM | SWT.BORDER);
b1.setLocation(0,400);
b1.setSize(100,40);
b1.setText("Result");
b1.setVisible(true);
final Tree tree = new Tree(shell, SWT.BORDER);

TreeItem item1 = new TreeItem(tree, SWT.NONE);

newtext= new Text(shell, SWT.H_SCROLL | SWT.BORDER | SWT.V_SCROLL);
newtext.setLocation(100,400);
newtext.setSize(890,265);
newtext.setText("");



FontDialog fd = new FontDialog(shell, SWT.NONE);
// fd.setText("Select Font");
fd.setRGB(new RGB(80,0,200));

FontData defaultFont = new FontData("Courier",12,SWT.BOLD);
fd.setFontData(defaultFont);

// FontData newFont = fd.open();
// if(newFont==null)
// return;

tree.setFont(new org.eclipse.swt.graphics.Font(display, defaultFont));
tree.setForeground(new Color(display, fd.getRGB()));

fd.setRGB(new RGB(0,0,100));
FontData defaultFont1 = new FontData("Courier",11,SWT.BOLD);








//tree.setBackground(4);
tree.setRedraw(true);
tree.setSize(200,400);
item1.setText("CCXML_LOAD");
TreeItem item2 = new TreeItem(tree, SWT.NONE);
item2.setText("createcall");

TreeItem item3 = new TreeItem(tree, SWT.NONE);
item3.setText("transition");
TreeItem item5 = new TreeItem(item3, SWT.NONE);
item5.setText("Connectoin.Failed");
TreeItem item8 = new TreeItem(tree, SWT.NONE);
item8.setText("If");
TreeItem item9 = new TreeItem(tree, SWT.NONE);
item9.setText("transition");
TreeItem item10 = new TreeItem(tree, SWT.NONE);
item10.setText("dialogStart");
TreeItem item11 = new TreeItem(tree, SWT.NONE);
item11.setText("send");
TreeItem item12 = new TreeItem(tree, SWT.NONE);
item11.setText("BLANK");

DragSource ds = new DragSource(tree, DND.DROP_MOVE);
ds.setTransfer(new Transfer[] { TextTransfer.getInstance() });
ds.addDragListener(new DragSourceAdapter() {
public void dragSetData(DragSourceEvent event) {
event.data = tree.getSelection()[0].getText();
System.out.println("select data item" + tree.getSelection()[0].getText());
}
});


tree1 = new Tree(shell, SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL | SWT.BORDER);
tree1.addMouseListener(this);

tree1.setLocation(200,0);
tree1.setSize(790,400);
tree1.setFont(new org.eclipse.swt.graphics.Font(display, defaultFont1));
tree1.setForeground(new Color(display, fd.getRGB()));



final TreeEditor editor = new TreeEditor(tree1);
editor.horizontalAlignment = SWT.LEFT;
editor.grabHorizontal = true;



// new code to implement drag within window ****************** Start
Transfer[] types = new Transfer[] { TextTransfer.getInstance() };
int operations = DND.DROP_MOVE | DND.DROP_COPY | DND.DROP_LINK;

final DragSource source = new DragSource(tree1, operations);
source.setTransfer(new Transfer[] { TextTransfer.getInstance() });
final TreeItem[] dragSourceItem = new TreeItem[1];
source.addDragListener(new DragSourceListener() {
public void dragStart(DragSourceEvent event) {
TreeItem[] selection;
if(tree == event.getSource())
{
System.out.println("hi from the main");
selection = tree.getSelection();
}
else
{
System.out.println("hi from the same");
selection = tree1.getSelection();
System.out.print("value of selection is " + selection);
}

System.out.println("in New dragh");
if (selection.length > 0 && selection[0].getItemCount() == 0) {
event.doit = true;
System.out.println("yeah successfull" + selection[0].getText());
dragSourceItem[0] = selection[0];
} else {
System.out.println("Some thing wrong yaar");
event.doit = false;
}
};


public void dragSetData(DragSourceEvent event) {
event.data = dragSourceItem[0].getText();
System.out.println("in drag set Data event");
}
public void dragFinished(DragSourceEvent event) {
System.out.println("in drag finsihed event");
// if (event.detail == DND.DROP_MOVE)
// dragSourceItem[0].dispose();
// dragSourceItem[0] = null;
}



});


DropTarget targetnew = new DropTarget(tree1, operations);
targetnew.setTransfer(types);
targetnew.addDropListener(new DropTargetAdapter() {
public void dragOver(DropTargetEvent event) {
System.out.println("lets check this once");
event.feedback = DND.FEEDBACK_EXPAND | DND.FEEDBACK_SCROLL;
if (event.item != null) {
TreeItem item = (TreeItem) event.item;
Point pt = display.map(null, tree1, event.x, event.y);
Rectangle bounds = item.getBounds();
if (pt.y < bounds.y + bounds.height / 3) {
event.feedback |= DND.FEEDBACK_INSERT_BEFORE;
} else if (pt.y > bounds.y + 2 * bounds.height / 3) {
event.feedback |= DND.FEEDBACK_INSERT_AFTER;
} else {
event.feedback |= DND.FEEDBACK_SELECT;
}
}
}

public void drop(DropTargetEvent event) {
// updating with required data ok

String a1 = (String) event.data;
String text="";
System.out.println("target placing data is here");


String lff = Text.DELIMITER;

if(a1.equalsIgnoreCase("CCXML_LOAD"))
{
text="<transition state=\"CCXML_LOADING\"/>";
}
else if(a1.equalsIgnoreCase("if"))
{
text="<if cond=\"abc==xzy\">";
}
else if(a1.equalsIgnoreCase("createcall"))
{
text = "<createcall dest=\"'tel:+1'+phonenum\" callerid=\"'9192318253'\" timeout=\"'60000ms'\" voxeo-cpa-runtime=\"'7000'\" voxeo-cpa-maxtime=\"'3000'\" voxeo-cpa-maxsilence=\"'800'\" voxeo-cpa-maskevent=\"'human,machine'\" voxeo-cpa-maskstop=\"''\" connectionid=\"myOutboundConnectionID\"/>\"";
}
else if(a1.equalsIgnoreCase("transition"))
{
text="<transition event=\" \" state=\" \">\"";
}

else if(a1.equalsIgnoreCase("dialogStart"))
{
text="<dialogstart src=\"'*.xml'\" dialogid=\" \" namelist=\" \"/>";
}
else if(a1.equalsIgnoreCase("send"))
{
text="<send name=\"'http.get'\" target=\"'http://122.166.9.46/VoxeoTest/Default.aspx'\" namelist=\" \" targettype=\"'basichttp'\"/>";
}
else if(a1.equalsIgnoreCase("BLANK"))
{
text=" ";
}
else
{
text= a1;
}







if (event.data == null) {
event.detail = DND.DROP_NONE;
return;
}

if (event.item == null) {
TreeItem item = new TreeItem(tree1, SWT.NONE | SWT.MULTI );
item.setText(text);
} else {
TreeItem item = (TreeItem) event.item;
Point pt = display.map(null, tree1, event.x, event.y);
Rectangle bounds = item.getBounds();
TreeItem parent = item.getParentItem();
if (parent != null) {
TreeItem[] items = parent.getItems();
int index = 0;
for (int i = 0; i < items.length; i++) {
if (items[i] == item) {
index = i;
break;
}
}
if (pt.y < bounds.y + bounds.height / 3) {
System.out.println("Situation one");
TreeItem newItem = new TreeItem(parent, SWT.NONE,
index);
newItem.setText(text);
} else if (pt.y > bounds.y + 2 * bounds.height / 3) {
TreeItem newItem = new TreeItem(parent, SWT.NONE,
index + 1);
System.out.println("Situation two");
newItem.setText(text);
} else {
TreeItem newItem = new TreeItem(item, SWT.NONE);
newItem.setText(text);
}

} else {
System.out.println("Situation three");
TreeItem[] items = tree1.getItems();
int index = 0;
for (int i = 0; i < items.length; i++) {
if (items[i] == item) {
index = i;
break;
}
}
if (pt.y < bounds.y + bounds.height / 3) {
TreeItem newItem = new TreeItem(tree1, SWT.NONE,
index);
System.out.println("Situation four");
newItem.setText(text);
} else if (pt.y > bounds.y + 2 * bounds.height / 3) {
TreeItem newItem = new TreeItem(tree1, SWT.NONE,
index + 1);
newItem.setText(text);
} else {
System.out.println("Situation five");
TreeItem newItem = new TreeItem(item, SWT.NONE);
newItem.setText(text);
}
}

}
}







});
// new code to implement drag within window ****************** End

b1.addListener(SWT.Selection, new Listener() {
public void handleEvent(Event e) {
// System.out.println(getEventName(e.type));
switch (e.type) {
case SWT.Selection:

// StringBuilder fulltext=new StringBuilder();
int rows = tree1.getItemCount();
int rowss= tree1.getColumnCount();
int i=0;
String xy=new String(" ");
StringBuilder ab=new StringBuilder(xy);
fulltext=ab;
newtext.setText(" ");

String lf = Text.DELIMITER;
while(i<rows)
{
TreeItem abcdefg= (TreeItem) (tree1.getItem(i));

//fulltext.append(abcdefg.getText());
traverse(abcdefg);

// System.out.println("hi");




//fulltext.append(lf);

i++;
}



//newtext.update();

newtext.setText(fulltext.toString());
countofresult+=1;
System.out.print("total result attempt is " + countofresult);
// shell.pack();
// shell.open();

break;
}
}
});






shell.setSize(1000, 700);
shell.open();
while (!shell.isDisposed())
{

if (!display.readAndDispatch())
{
display.sleep();

}
}

}
catch(Exception expr)
{
}



}

public void mouseDoubleClick(MouseEvent e) {
// Nothing to do
try
{
final TreeEditor editor = new TreeEditor(tree1);
editor.horizontalAlignment = SWT.LEFT;
editor.grabHorizontal = true;

final TreeItem item3 = tree1.getSelection()[0];

final Text text = new Text(tree1, SWT.NONE);


text.setText(item3.getText());
text.setFocus();



FontDialog fd1 = new FontDialog(shell, SWT.NONE);
fd1.setRGB(new RGB(0,0,200));
FontData defaultFont2 = new FontData("Courier",11,SWT.BOLD);
fd1.setFontData(defaultFont2);
text.setFont(new org.eclipse.swt.graphics.Font(display, defaultFont2));
text.setForeground(new Color(display, fd1.getRGB()));
text.addFocusListener(new FocusAdapter() {
public void focusLost(FocusEvent event) {
item3.setText(text.getText());
text.dispose();

}});
editor.setEditor(text, item3);
}
catch(Exception exp)
{

}
}


//code start for deleting a perticular node

//code end for deleting a perticular node

public void mouseUp(MouseEvent e) {
// Nothing to do
}
public void mouseDown(MouseEvent event) {

try
{
final Point point = new Point(event.x, event.y);
final TreeItem item = tree1.getItem(point);
if (item == null)
return;




tree1.addKeyListener(new org.eclipse.swt.events.KeyAdapter()
{
public void keyPressed( org.eclipse.swt.events.KeyEvent event2) {


if (event2.keyCode == 127)
{
item.dispose();

}

}
});
}
catch(Exception ex)
{

}
}

static void traverse(TreeItem item) {
try
{
String string = item.getText();

TreeItem temp = item.getParentItem();
String lf = Text.DELIMITER;
String abcxyz="";
while (temp != null) {

abcxyz=abcxyz + " ";
temp = temp.getParentItem();

}
fulltext.append(lf);
fulltext.append(abcxyz + string);


TreeItem[] items = item.getItems();

for (int i = 0; i < items.length; i++) {
System.out.println("to check its loop condition");
traverse(items[i]);

}

}
catch (Exception ex)
{

}
}

}



Please help me to run this application using jar file.

Thanks in advance..

Thanks!
Asif

 
Rancher
Posts: 43016
76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I suspect that even if you used code tags -and you absolutely should do that- this would still be too much code to ask anyone to go through and try to understand.

This always a red flag, though - you must do proper error handling:


catch(Exception ex)
{
}



C:\Documents and Settings\Asif>java -jar "C:\Documents and Settings\Asif\My Documents\NetBeansProjects\JavaApplicatio\dist\JavaApplication2.jar"


Does this jar file contain the MouseListener class that's missing? If not, then you need to add that to your classpath.
 
All of the following truths are shameless lies. But what about this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic