JMS Simple code in Sun tutorial
I run a simple code (http://java.sun.com/j2ee/1.4/docs/tutorial/doc/JMS4.html) fine in j2sdkee , but fail to use in Openjms/ JBoss.
try {
connectionFactory = (ConnectionFactory) jndiContext.lookup("QueueConnectionFactory");
} catch (Exception e) {
System.out.println("JNDI API lookup failed: " + e.toString());
return;
What's wrong of the above code? Why do I can the following error in Openjms / Jboss?
JNDI API lookup failed: javax.naming.CommunicationException: Can't find
OpenJMS by default defines the following: (QueueConnectionFactory is not defined by default!)
queueName = "queue1"
queueConnectionFactoryName = "JmsQueueConnectionFactory"
The creation of the initial context could be done like this
Hashtable env = new Hashtable ();
env.put(Context.PROVIDER_URL,
"rmi://localhost:1099/JndiServer");
env.put(Context.INITIAL_CONTEXT_FACTORY,
"org.exolab.jms.jndi.rmi.RmiJndiInitialContextFactory");
jndiContext = new InitialContext (env);
Similar modifications are needed for JBoss
Similar Messages
-
hi this is code from sun's swing tutorial (http://java.sun.com/docs/books/tutorial/uiswing/learn/example1.html )
import javax.swing.*;
public class HelloWorldSwing
private static void createAndShowGUI() // why it is private ??
JFrame.setDefaultLookAndFeelDecorated(true);
JFrame frame = new JFrame("HelloWorldSwing");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JLabel label = new JLabel("Hello World");
frame.getContentPane().add(label);
frame.pack();
frame.setVisible(true);
public static void main(String[] args) {
javax.swing.SwingUtilities.invokeLater(new Runnable() // what does this snippet doing ?
public void run()
createAndShowGUI();
}i have question on this code. i have put my question in the comment . in the tutorial they are advising to " Be thread safe ...what it means ?
can anybody explain my questions ( commentation + bold letter) ?
thanksi have seen swing codes which dont use threads
like above . does it mean they are not safe ?
what do you mean by safe ? ...does it mean program
can crash at any time if i dont include that
snippet ? will you be explicit in a simpler way.It is extremely unlikely that doing the following is unsafe:
//in main thread:
frame.pack();
frame.setVisible(true); //unsafe?But there's no guarantee! And by unsafe, the authors mean that undefined behavior can result --
your GUI could do anything it wanted! That being said, it's extremely unlikely that anything bad
would result in this example -- it's too simple. I do remember someone posting once that they
finally tracked an intermittent bug in their app to just this!
What I do, if I'm being safe/paranoid is call a utility method I've written, instead of calling setVisible
in the above code:
public static void postVisible(final JFrame f, final boolean state) {
Runnable r = new Runnable() {
public void run() {
f.setVisible(state);
SwingUtilities.invokeLater(r);
}Problem solved!
>
second question was why the method was private
static......why not public static ?(if you really
want to make it static !!)1. Since they never instantiate HelloWorldSwing, the method had better be static.
2. Methods should have the most restrictive scope possible. Since this is the "main" class
that launches its own GUI, no other class needs to see createAndShowGUI, so it is private. -
Hi all,
this is my simple code that plays a video from a specifed location.
* To change this template, choose Tools | Templates
* and open the template in the editor.
package javaapplication1;
* @author rohan
import com.sun.media.util.ContentType;
import javax.media.*;
import javax.media.Manager;
import java.io.*;
import java.net.URL;
import javax.media.bean.playerbean.MediaPlayer;
import java.awt.*;
import java.net.ProtocolException;
import javax.swing.*;
public class Main extends JFrame{
* @param args the command line arguments
public Main()
try
Manager.setHint( Manager.LIGHTWEIGHT_RENDERER, true );
Container cont=getContentPane();
cont.setLayout(new FlowLayout());
String myUrl=new String("C:\\Users\\rohan\\Softwares\\Jmf and jain sip\\Fig21_06_07\\bailey.mpg");
System.out.println("myUrl====="+myUrl);
MediaLocator myurls =new MediaLocator(myUrl);
Player myplayer=Manager.createRealizedPlayer(myurls);
System.out.println("Rohan");
Component video = myplayer.getVisualComponent();
cont.add(video);
setDefaultCloseOperation(EXIT_ON_CLOSE);
myplayer.start();
catch(Exception e)
System.out.println("Exception====="+e);
public static void main(String[] args) {
// TODO code application logic here
// JFrame fr=new JFrame("hello");
Main obj=new Main();
obj.setBounds(300, 300 , 300, 300);
obj.setVisible(true);
Problem here is i get this exception
"Exception=====javax.media.NoPlayerException: Cannot find a Player for :C:\Users\rohan\Softwares\Jmf and jain sip\Fig21_06_07\bailey.mpg
Can u plz tel me where do i make changes ,so that i can run this simple app. Plz help me...so that i can go further(plz this is my first jmf app.)
thanks.Change your file path like +"file:/C:/delta.mpg"+.
Hope this will help you to fix your issue.
Cheers,
ARIF -
Annotations - error in Sun Tutorial?
In the Q&E section of The Sun Tutorial on Annotataions (http://java.sun.com/docs/books/tutorial/java/javaOO/QandE/annotations-answers.html), it says,
Question 2: Compile this program:
interface Closable {
void close();
class File implements Closable {
@Override
public void close() {
//... close this file...
What happens? Can you explain why?
Answer 2: The compiler generates an error complaining that File.close doesn't override any method from its superclass. This is because it is not overriding Closable.close, it is implementing it!
But...
I get no errors (or any other messages) and File.class and Closeable.class files are created.
Is the tutorial wrong? Or something else?
How would you change the sample code to get the answer the tutorial gives?
Thank you.
see also http://java.sun.com/docs/books/tutorial/java/javaOO/QandE/annotations-questions.htmlC:\Documents and Settings\ejp\Tests\src\OverridesTest.java:23: method does not override a method from its superclass
Is that the code you actually compiled? -
Many times on here i have been told that its bad to have more than 1 JFrame in 1 application. I am working on my stuff and i am trying to look at other applications to help me. I came across the suns tutorial relating to Dukes Bakery, which is swing and JDBC. Nearly every class in this tutorial extends a JFrame. I just wanted to get more information on why it is bad to extend more than 1 JFrame and why would they do this in this tutorial.
cheersnick2price wrote:
Many times on here i have been told that its bad to have more than 1 JFrame in 1 application. I've never seen this as bad, but extending a JFrame may be.
I am working on my stuff and i am trying to look at other applications to help me. I came across the suns tutorial relating to Dukes Bakery, which is swing and JDBC. Nearly every class in this tutorial extends a JFrame. I just wanted to get more information on why it is bad to extend more than 1 JFrame and why would they do this in this tutorial.
cheersIf you are using a JFrame as your base for a GUI form, then extending the JFrame itself is considered "bad practice" as you are mixing GUI and coding/program/business logic usually to do so. In cases of building GUI's keep your display and your program code separate. With good designed GUI's you will usually not have to extend your JFrame class, possibly with the exception of Graphics/animations. -
What's wrong with this simple code?
What's wrong with this simple code? Complier points out that
1. a '{' is expected at line6;
2. Statement expected at the line which PI is declared;
3. Type expected at "System.out.println("Demostrating PI");"
However, I can't figure out them. Please help. Thanks.
Here is the code:
import java.util.*;
public class DebugTwo3
// This class demonstrates some math methods
public static void main(String args[])
public static final double PI = 3.14159;
double radius = 2.00;
double area;
double roundArea;
System.out.println("Demonstrating PI");
area = PI * radius * radius;
System.out.println("area is " + area);
roundArea = Math.round(area);
System.out.println("Rounded area is " + roundArea);Change your code to this:
import java.util.*;
public class DebugTwo3
public static final double PI = 3.14159;
public static void main(String args[])
double radius = 2.00;
double area;
double roundArea;
System.out.println("Demonstrating PI");
area = PI * radius * radius;
System.out.println("area is " + area);
roundArea = Math.round(area);
System.out.println("Rounded area is " + roundArea);
Klint -
Convert simple code from as2 to as3
Hello, i am looking for some help here for something simple (i think)
var txt:String = link1;
btn.onRelease = function():Void {
if( sample_id )
getURL("http://www.website.com/registration?partner_id=" + sample_id + "sampleURLCode", "_blank");
else
getURL("http://www.website.com/registration?sampleURLCode", "_blank");
Is there a way to make this simple code into AS3?Hi, Apparantly that's because the 'link1' and 'sample_id' variables are not within the scope of the code you posted above, Perhaps you have defined them outside on a different frame or class. You can either define them with the same code like:
var sample_id:Number=1234; //Use your own variable type and value here
var link1:String = "your string or link URL here";
var txt:String = link1;
btn.addEventListener(MouseEvent.CLICK, gotoURL);
function gotoURL(e:MouseEvent)
if( sample_id )
navigateToURL(new URLRequest("http://www.website.com/registration?sample_id=" + sample_id + "sampleURLCode"),"_blank");
else
navigateToURL(new URLRequest("http://www.website.com/registration?sampleURLCode"),"_blank");
Or you can put a direct reference to your existing variable like (If your variables are defined on root/frame 1) :
var link1:String = "your string or link URL here";
var txt:String = MovieClip(this.root).link1;
btn.addEventListener(MouseEvent.CLICK, gotoURL);
function gotoURL(e:MouseEvent)
if( MovieClip(this.root).sample_id )
navigateToURL(new URLRequest("http://www.website.com/registration?sample_id=" + sample_id + "sampleURLCode"),"_blank");
else
navigateToURL(new URLRequest("http://www.website.com/registration?sampleURLCode"),"_blank");
try that, or you can share your .fla !
cheers -
Simple code to send ALV display as XLS attachment to SAP inbox
Hi All,
Simple code to send ALV display as XLS attachment to SAP inbox.
Also i need to send only 200 records per attachement. So in this case i need send multiple attachment per mail
Thanks,
LokeshThe following code is used to send the internal table which u pass fo the ALV display to be send as excel sheet attachment
Internal table is it_attach[]
ld_email = po_email.
ld_mtitle = 'Email From Z377_EMAIL_XLS'.
ld_format = 'XLS'.
ld_attdescription = 'filename'.
ld_attfilename = 'Allot'.
ld_sender_address = ' '.
ld_sender_address_type = ' '.
* Fill the document data.
w_doc_data-doc_size = 1.
* Populate the subject/generic message attributes
w_doc_data-obj_langu = sy-langu.
w_doc_data-obj_name = 'SAPRPT'.
w_doc_data-obj_descr = ld_mtitle .
w_doc_data-sensitivty = 'F'.
* Fill the document data and get size of attachment
CLEAR w_doc_data.
READ TABLE it_attach INDEX w_cnt.
w_doc_data-doc_size =
( w_cnt - 1 ) * 255 + STRLEN( it_attach ).
w_doc_data-obj_langu = sy-langu.
w_doc_data-obj_name = 'SAPRPT'.
w_doc_data-obj_descr = ld_mtitle.
w_doc_data-sensitivty = 'F'.
CLEAR t_attachment.
REFRESH t_attachment.
t_attachment[] = it_attach[].
* Describe the body of the message
CLEAR t_packing_list.
REFRESH t_packing_list.
t_packing_list-transf_bin = space.
t_packing_list-head_start = 1.
t_packing_list-head_num = 0.
t_packing_list-body_start = 1.
DESCRIBE TABLE li_content LINES t_packing_list-body_num.
t_packing_list-doc_type = 'RAW'.
APPEND t_packing_list.
* Create attachment notification
t_packing_list-transf_bin = 'X'.
t_packing_list-head_start = 1.
t_packing_list-head_num = 1.
t_packing_list-body_start = 1.
DESCRIBE TABLE t_attachment LINES t_packing_list-body_num.
t_packing_list-doc_type = ld_format.
t_packing_list-obj_descr = ld_attdescription.
t_packing_list-obj_name = ld_attfilename.
t_packing_list-doc_size = t_packing_list-body_num * 255.
APPEND t_packing_list.
* Add the recipients email address
CLEAR t_receivers.
REFRESH t_receivers.
t_receivers-receiver = ld_email.
t_receivers-rec_type = 'U'.
t_receivers-com_type = 'INT'.
t_receivers-notif_del = 'X'.
t_receivers-notif_ndel = 'X'.
APPEND t_receivers.
CALL FUNCTION 'SO_DOCUMENT_SEND_API1'
EXPORTING
document_data = w_doc_data
put_in_outbox = 'X'
sender_address = ld_sender_address
sender_address_type = ld_sender_address_type
commit_work = 'X'
*IMPORTING
*sent_to_all = w_sent_all
TABLES
packing_list = t_packing_list
contents_bin = t_attachment
contents_txt = li_content
receivers = t_receivers
EXCEPTIONS
too_many_receivers = 1
document_not_sent = 2
document_type_not_exist = 3
operation_no_authorization = 4
parameter_error = 5
x_error = 6
enqueue_error = 7
OTHERS = 8. -
Anyone have Simple Code to Play an .Flv file on a Website?
Hi,
Can someone please tell me how to make a web page play a .flv file.
Simple, basic code would do.
I have an .flv file uploaded on my website.
How do I get the Flash Player to play the file when someone visits the page?
Again, all I'm looking for is simple code.
Thanks,
Joeadd an flvplayback component to your swf. give it an instance name (say flv). then use:
flv.contentPath="yourflv.flv"; // for as2
flv.source="yourflv.flv"; // for as3 -
Hi,
I am new to JMS and am trying to learn the technology. When I tried to run the JMS sample codes available at http://www.oracle.com/technology/sample_code/tech/java/jms/index.html, I got the following error:
[java] javax.naming.NoInitialContextException: Cannot instantiate class: co
m.evermind.server.rmi.RMIInitialContextFactory [Root exception is java.lang.Clas
sNotFoundException: com.evermind.server.rmi.RMIInitialContextFactory]
Please help me solve the problem. I find that, the downloaded code does not contain the class mentioned in the error message. Also, I do not see how the code is interacting with the OC4J server. It would be great if anyone could clarify.hi adith,
the problem you are facing can be removed by adding oc4jclient.jar as libraray.
But after that i am facing following error.
Exception in thread "main" java.lang.NoClassDefFoundError: javax/management/j2ee/statistics/JMSEndpointStats
at com.evermind.server.jms.EvermindSession.createProducer(EvermindSession.java:311)
at warid.com.jms.JMSProducerConsumer.performMessagingOperations(JMSProducerConsumer.java:80)
at warid.com.jms.JMSProducerConsumer.main(JMSProducerConsumer.java:42)
Regards -
Ask for help( simple code but wired error )!
The post I sent just now has some mistakes. This post is correct. My simple code is as follows:
import java.io.*;
import java.net.*;
public class count {
float dclient = (float)3.333;
float dlan = (float)0.01884;
float drouter = (float)0.00115;
float doutlink = (float)0.04185;
float dinternet = (float)1.2615;
float dinlink = (float)3.18129;
float client1 = 0;
float lan1 = 0;
float router1 = 0;
float outlink1 = 0;
float internet1 = 0;
float inlink1 = 0;
float client2 = 0;
float lan2 = 0;
float router2 = 0;
float outlink2 = 0;
float internet2 = 0;
float inlink2 = 0;
float x = 0;
float z = (float)3.333;
public static void main(String[] args) {
for (int n=1; n<16; ++n)
client1 = dclient;
lan1 = dlan * (1+lan2);
router1 = drouter;
outlink1 = doutlink * (1+outlink2);
internet1 = dinternet;
inlink1 = dinlink * (1+inlink2);
x = n / (z + client1 + lan1 + router1 + outlink1 + internet1 + inlink1);
client2 = x * client1;
lan2 = x * lan1;
rounter2 = x * rounter1;
outlink2 = x * outlink1;
internet2 = x * internet1;
inlink2 = x * inlink1;
System.out.println(client1 + " " +
lan1 + " " +
rounter1 + " " +
outlink1 + " " +
internet1+ " " +
inlink1+ " **** " +
x + " **** " +
client2 + " " +
lan2 + " " +
rounter2 + " " +
outlink2 + " " +
internet2+ " " +
inlink2 + " ********************end of n = " + n + "************************"
The compiling error is:
count.java:43: Can't make a static reference to nonstatic variable dclient in class count.
client1 = dclient;
^
1 error
What is wrong with it? Many thanks!import java.io.*;
import java.net.*;
public class count
public static float dclient = (float)3.333;
public static float dlan = (float)0.01884;
public static float drouter = (float)0.00115;
public static float doutlink = (float)0.04185;
public static float dinternet = (float)1.2615;
public static float dinlink = (float)3.18129;
public static float client1 = 0;
public static float lan1 = 0;
public static float router1 = 0;
public static float outlink1 = 0;
public static float internet1 = 0;
public static float inlink1 = 0;
public static float client2 = 0;
public static float lan2 = 0;
public static float router2 = 0;
public static float outlink2 = 0;
public static float internet2 = 0;
public static float inlink2 = 0;
public static float x = 0;
public static float z = (float)3.333;
public static void main(String[] args)
for (int n=1; n<16; ++n)
client1 = dclient;
lan1 = dlan * (1+lan2);
router1 = drouter;
outlink1 = doutlink * (1+outlink2);
internet1 = dinternet;
inlink1 = dinlink * (1+inlink2);
x = n / (z + client1 + lan1 + router1 + outlink1 + internet1 + inlink1);
client2 = x * client1;
lan2 = x * lan1;
router2 = x * router1;
outlink2 = x * outlink1;
internet2 = x * internet1;
inlink2 = x * inlink1;
System.out.println(client1 + " " + lan1 + " " router1 " " outlink1 " " internet1 " " inlink1 " **** " + x + " **** " +
client2 + " " +
lan2 + " " +
router2 + " " +
outlink2 + " " +
internet2+ " " +
inlink2 + " ********************end of n = " + n + "************************" -
Data Binding: Simple code does not work.
hi... the following simple code is used to display the ename field for a record selected in scott.emp on the console. the code is placed in an event handler. it is as follows:
DCBindingContainer bindings = ctx.getBindingContainer();
DCControlBinding binding = bindings.findCtrlBinding("ename");
String Name = (binding != null) ? binding.toString() : "";
System.out.println(Name);
is the code above correct????
if so, why it does not work???
thanks for every help in advance & best regards.Hi,
please check the UIModel.xml file for the page if the binding name is "name". The code you have is the same code we published in our QBE workshop and it works there. The only difference is the name of the control binding. So please check if the binding name exists. (e.g. it could be ename1 instead of ename)
Frank -
What's the simple code for this?
Hello, I know it is a very simple code but what is the code if I want to have different properties for headings and such in different id's. For example I want ID "sidebar"'s headings to be aligned in the center but I want ID "main-body"'s headings to be aligned to the left. How would I go about doing that?
Thanks!CSS:
body {
text-align:left;
#sidebar h1,
#sidebar h2,
#sidebar h3,
#sidebar h4 {text-align:center}
/**re-usable classes**/
.center {text-align:center}
.right {text-align:right}
HTML:
<div id="main_body">
<h1>This is left aligned by default</h1>
<h2 class="right">This is right aligned by virtue of the class .right.</h2>
</div>
Nancy O. -
Hello Everyone, I am learning XML and I'm trying to make a simple code that will display three different messages on a separate line. I already have the code but there is something that does not let it work. Please if somebody can take a quick look at the code and tell me what should I do in order to get it working. Thanks in advance
This is my simplerequestdata.xml
{<root>
<message1>This</message1>
<message2>Technology</message2>
<message3>Is confusing</message3>
</root>}
This is my xmlrequest.html code
{<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script type="text/javascript">
var req=null;
function xhr(){
try
{ // Firefox, Opera 8.0+, Safari
req=new XMLHttpRequest();
catch (e)
// Internet Explorer
try
req=new ActiveXObject("Msxml2.XMLHTTP");
catch (e)
req=new ActiveXObject("Microsoft.XMLHTTP");
return req;
function getData(){
req = new xhr();
req.open("get","simpleRequestData.xml");
req.send(null);
if(req.readyState==4){
if(req.status==200){
var doc = req.responseXML;
var msgNodes = doc.documentElement.getElementsByTagName('message');
var msgDiv = document.getElementById("message");
var msg = document.createElement("message");
msg.innerHTML = msgNodes[0].firstChild.nodeValue + "<br />" + msgNodes[1].firstChild.nodeValue + '
' + msgNodes[2].firstChild.nodeValue;
msgDiv.innerHTML = '';
msgDiv.appendChild(msg);
</script>
<style>
#message{color:red;}
message{display:block;color:green;}
</style>
</head>
<body>
<form>
<input type="button" onclick="getData()" value="Get Message"/>
<div id="message">Message Goes Here</div>
</form>
</body>
</html>
}That looks like Javascript to me. This forum is about Java and XML, not Javascript and XML. However the error is pretty obvious:
var msgNodes = doc.documentElement.getElementsByTagName('message');You don't have any elements named "message" in that XML document. You have an element named "message1" and an element named "message2" and an element named "message3", but no "message" elements. So you get a list of zero elements there. You need to rewrite your DOM-handling code to reflect the actual input. -
How to sort a list of strings, without methods and stuff just simple code?
Hi
How to sort a list of strings, without methods and stuff just simple code?
Thanks in adavance!!Without methods? How are you going to all the sort code? What is the point of code?
Collections.sort(List) will sort strings or anything that implements the Comparable interface, or you can use the sort method that takes a Comparator implemenation.
If you want "just code", you could either get the Collections class souce and follow it to the code. But otherwise, there isn't one set of code. There are various sorting algorithms with advantages and disadvantages. Maybe you'd be better off searching for sorting algorithms and if you understand them, it should be simple to write Java implementations of them.
Maybe you are looking for
-
I am recording stuff on garageband and i need to hear other tracks as I'm playing, but I have to play them through external earphones so that the they don't overlap onto the one I'm creating. The wire for my earphones has an external microphone attac
-
All three buttons used to have a color associated with them. Red (furthest left), Yellow (middle) and Green (right). Red shut down Firefox, Yellow hid Firefox from the screen and Green refreshed or enlarged the screen. Not only is the middle button n
-
Data Authorization for info-objects
Dear Experts, We have designed a query in costing displaying the plan and actual costs by cost center. Our requirement is that that users shoul be able to see only those cost centers in the query which are relevant to them? How can I acheive this wit
-
How to validate File extension.
Hi all, Can anyone suggest me any Function Module to validate a file extension while selecting the Filename at popup window. thanx Rakesh
-
Add Value Help doesnu00B4t work - Visual Composer
Hello I am trying to use "Add Value Help" in a variable form, but when I execute "Deploy" appears the following error: Error in compiling swf for Flex 2 application. Consult log file for details For details i have entered in System Management \ Monit