applet troubles (wanna try C/C++)

Started by
44 comments, last by alexxzius 16 years, 9 months ago
like omg it took me 30 min to log in! Is this site running on dial-up?

Anyways, my problem is not code related. Im sure my code works. In the zip file are the code source, the class file, the html page, and players.txt file. So what i need is instructions like this:

>> echo Main-Class: tennis1 > manifest.txt
>> jar cvfm tennis.jar manifest.txt tennis1.class players.txt
>> keytool ... <br>…<br>and ways to change my html (if i need to) <br><br>which are SPECIFIC to my game. Thats like 10 lines max, and no philosophy.<br><br>Im following several tutorials &#111;n how to sign applets and none of them are working. Im not even sure that my computer can execute jars. [posted this before]. So far i been unable to find a valid jar. So i need a valid .jar executable to see if i can run it. If i cant, ill go hang myself and be off yo back.
Advertisement
Quote:
Anyways, my problem is not code related. Im sure my code works.

Famous last words.

Quote:
Im following several tutorials on how to sign applets and none of them are working.

Which tutorials? Which parts don't work? If you cannot identify the problem, the problem will not get solved. We can't read your mind. Learning to clearly diagnose and then communicate problems is crucial to becoming a good software developer -- now is an excellent time to start practicing.

Identify for us the tutorial you're using, identify what you've done, and identify what has failed, with what error messages, et cetera. The more information you give us, the more information we can give you back. Assuming anybody is still around who feels like you deserve their time, given your attitude.
Quote:Original post by DevFred
Java is pass by value.


From a language semantics point of view, Java uses reference semantics for all objects, and value semantics for some basic types.

Quote:Original post by alexxzius
is it to much to ask?


Yes, it is. It seems pretty obvious that the answers you receive do not help you. The problem, however, does not come from the answer being incorrect or wrong. The actual problems are that 1° you don't know how to ask for help and 2° you don't know how to use the provided answers. This may seem a little harsh, but you must realize that until you are able to ask questions and receive answers correctly, you don't have much to gain from a public forum. I just hope you have the maturity to realize that I'm trying to help you.

I would consider this to be mandatory reading. The two essential points with which you should start would be:
  • To describe what you've already done, what you expected to happen, and what happened instead. Precisely, in detail, and with technically accurate vocabulary. You consistently failed to tell us what you did (which tutorials you followed, what commands you ran), and you consistently failed to describe precisely the symptoms (what exceptions you received, how your results differred from the tutorials). Ideally, if you want a solid answer, you should copy-paste the relevant error messages or even provide debugger screenshots.
  • Keep to the point. Your original post contains three lines asking for help with Allegro, and six lines rambling about C versus Java, when it should have contained ten lines asking for help with allegro and Dev-C++ and perhaps a final "thank you".


Here is an example of what your first post should have looked like:
Quote:Hello, I am trying to use Allegro with Dev-C++. I have googled for install instruction and found this tutorial. The configuration steps ran without errors, but once I tried to compile the example program, Dev-C++ gave me the following error:
thefile.c:1:21: allegro.h: No such file or directory


I tried googling for this error, but could not find a helpful link (although this one came quite close, but none of the suggested solutions changed the error message).

I am using Dev-C++ version 4.9.8 on Windows XP SP2 and downloaded the latest Allegro libraries.


Here is an example of what your last post should have looked like (of course, since you didn't tell us what the problem was, I've invented an error):
Quote:Hello, I have built a jar file from a java applet, which needs to access a file on the user's hard drive. However, the code for reading the file throws the following exception when run:
java.security.AccessControlException: access denied (java.io.FilePermission)


After some googling, I've found this tutorial, which tells me that I should sign an applet and then give it permissions to read specified file. However, after following the tutorial to the Sign the JAR File step, I've found that the jarsigner command is not recognized by my system—I get the typical "command not found: jarsigner error on the command prompt.

I'm running a standard Windows XP SP2 install with the latest and fully updated JVM from Sun, and I've just downloaded and installed. Thank you for your help!
Quote:
Anyways, my problem is not code related. Im sure my code works.

More then 80% of the time, no matter how much you say it is not, its
the code being the problem.
i know its not code related (trust me). Plus i know my code shouldnt work cause APPLETS CANT WRITE FILES, which im trying to do.
I have a problem with this tutorial:
http://java.sun.com/developer/onlineTraining/Programming/JDCBook/signed.html
1. Does it do what i need it to do?
2. Is it that complex?
3. I got lost after step 6: Import Certificate as a Trusted Certificate.
My idea is that people who would play my game would not generaly have JDK and not know how to do all the command line stuff.
The tutorial does not specify how to use the keytool utility to make the policy file; even if i make the policyfile, it cant just sit there next to the html and other files, i figure u gotta tell the applet which policy-file to use;
keystore "/home/ray/raystore"; - what is this? does it mean the player would have to create a derictory on his computer specified by the path? Im completely lost.

Another one: http://www.captain.at/programming/java/

C:\Documents and Settings\Java\jdk6\bin>keytool -genkey -keyalg rsa -alias appletkey
Enter keystore password:
What is your first and last name?
[Unknown]: john doee
What is the name of your organizational unit?
[Unknown]: brooklyn college
What is the name of your organization?
[Unknown]: bc
What is the name of your City or Locality?
[Unknown]: brooklyn
What is the name of your State or Province?
[Unknown]: new york
What is the two-letter country code for this unit?
[Unknown]: NY
Is CN=john doee, OU=brooklyn college, O=bc, L=brooklyn, ST=new york, C=NY correc
t?
[no]: yes

Enter key password for <appletkey>
(RETURN if same as keystore password):
Re-enter new password:

C:\Documents and Settings\Java\jdk6\bin>keytool -export -alias appletkey -file mycert.crt
Enter keystore password:
Certificate stored in file <mycert.crt>

C:\Documents and Settings\Java\jdk6\bin>jar cvmf manifest.txt Tennis.jar Tennis\tennis1.class Tennis\players.txt
added manifest
adding: Tennis/tennis1.class(in = 27843) (out= 14027)(deflated 49%)
adding: Tennis/players.txt(in = 125) (out= 96)(deflated 23%)

C:\Documents and Settings\Java\jdk6\bin>jarsigner Tennis.jar appletkey
Enter Passphrase for keystore:

Warning:
The signer certificate will expire within six months.

C:\Documents and Settings\Java\jdk6\bin>

so i opens my applet and the x is displayed.

CONSOLE:

load: class tennis1.class not found.
java.lang.ClassNotFoundException: tennis1.class
at sun.applet.AppletClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.applet.AppletClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.applet.AppletClassLoader.loadCode(Unknown Source)
at sun.applet.AppletPanel.createApplet(Unknown Source)
at sun.plugin.AppletViewer.createApplet(Unknown Source)
at sun.applet.AppletPanel.runLoader(Unknown Source)
at sun.applet.AppletPanel.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.io.FileNotFoundException: C:\Documents and Settings\Java\jdk6\bin\Tennis\JAR\tennis1\class.class (The system cannot find the path specified)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(Unknown Source)
at java.io.FileInputStream.<init>(Unknown Source)
at sun.net.www.protocol.file.FileURLConnection.connect(Unknown Source)
at sun.net.www.protocol.file.FileURLConnection.getInputStream(Unknown Source)
at sun.applet.AppletClassLoader.getBytes(Unknown Source)
at sun.applet.AppletClassLoader.access$100(Unknown Source)
at sun.applet.AppletClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
... 10 more

Here is my manifest.txt file:
Main-Class: tennis1

My applet:
<html>
<body>
<p align = center>
<applet code = "tennis1.class"
archive="Tennis.jar" width=1000 height=600>

</applet>
</body>
</html>

U dont have to put all the class and text files next to yo jar, do u? I did and the applet loaded, but i got this exception:

Exception in thread "AWT-EventQueue-2" java.security.AccessControlException: access denied (java.io.FilePermission players.txt write)
at java.security.AccessControlContext.checkPermission(Unknown Source)
at java.security.AccessController.checkPermission(Unknown Source)
at java.lang.SecurityManager.checkPermission(Unknown Source)
at java.lang.SecurityManager.checkWrite(Unknown Source)
at java.io.FileOutputStream.<init>(Unknown Source)
at java.io.FileOutputStream.<init>(Unknown Source)
at tennis1.keyDown(tennis1.java:571)
at java.awt.Component.handleEvent(Unknown Source)
at java.awt.Component.postEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.KeyboardFocusManager.redispatchEvent(Unknown Source)
at java.awt.DefaultKeyboardFocusManager.dispatchKeyEvent(Unknown Source)
at java.awt.DefaultKeyboardFocusManager.preDispatchKeyEvent(Unknown Source)
at java.awt.DefaultKeyboardFocusManager.typeAheadAssertions(Unknown Source)
at java.awt.DefaultKeyboardFocusManager.dispatchEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)


and dont tell me i cant do that, i know i cant, im just showing u this.
Caused by: java.io.FileNotFoundException: C:\Documents and Settings\Java\jdk6\bin\Tennis\JAR\tennis1\class.class

code = "tennis1.class" tells the applet to load a class named class found in package tennis1, and that no such class exists in your JAR. Perhaps you meant to load a class named tennis1 in the global package instead?
Ok, i changed my html code to

<html>
<body>
<p align = center>
<applet code = "Tennis\tennis1"
archive="Tennis.jar" width=1000 height=600>
</applet>
</body>
</html>

(My Tennis.jar file has a derectory "Tennis" with a file "tennis1.class")
Now the web-page displays the security warning message. I click "Run" and the applet does not load

java.lang.NoClassDefFoundError: Tennis/tennis1 (wrong name: tennis1)
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 sun.applet.AppletClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.applet.AppletClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.applet.AppletClassLoader.loadCode(Unknown Source)
at sun.applet.AppletPanel.createApplet(Unknown Source)
at sun.plugin.AppletViewer.createApplet(Unknown Source)
at sun.applet.AppletPanel.runLoader(Unknown Source)
at sun.applet.AppletPanel.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)

anymore ideas?
Package structure must mirror directory structure. Since the file for the tennis1 class is in directory Tennis, the class itself must be made part of the Tennis package, using the package directive at the top of that file.
ok, i done it. Now there are no exceptions. But the file is not written. ;(


try{
PrintStream file=new PrintStream(new FileOutputStream(new File("file.txt")));
file.println("hello file");
file.close();
} catch(IOException exp){}
[\code]

Where is the file "supposed to be" written? Inside the jar or in the same directory as the jar?
Please, do not be affraid of the "Post Reply" button, it dont bite.

anyways, the file appears on my desktop ( Java is funny lol ).
I tried using "/file.txt", "//file.txt", "\file.txt", "\\file.txt" and just about every combination of backslashes and forwardslashes . . . sometimes the file gets written on the desktop, sometimes it doesnt get written at all, and no exceptions are thrown in either case. I want the file to be written inside my jar.

Thanx for replying.

This topic is closed to new replies.

Advertisement