Trying to import an audio file in my java application: misplaced construct(s) -
i have followed tutorial on importing wav file application. not know if have placed file url in right place :
public class audioapp extends japplet { public class sound // holds 1 audio file { private audioclip song; // sound player private url songpath; // sound path sound(string filename) { try { songpath = new url(getcodebase(g:\uni\programming\rolling assignements\week0\programming week21),filename); // sound url song = applet.newaudioclip(songpath); // load sound } catch(exception e){} // satisfy catch } public void playsound() { song.loop(); // play } } }
the error is:
"multiple markers @ line - syntax error on token(s), misplaced construct(s) - syntax error on tokens, delete these tokens"
where place url, want play specific workplace folder , not usb stick, put name of file instead of whole path. have tried both don't work.
any help?
thanks
sorry not noticing @ first glance..
- first: url needs string constructor argument, not have done (notice double quotes around argument. also, see getcodebase() function )
second: seem inexperienced, wise memorize
\
character, backslash used escape characters, in cases, when used in string constants, has escaped, doubling up.songpath = new url(getcodebase("g:\\uni\\programming\\rolling assignements\\week0\\programming week21"),filename);
even better use file.separator
static field...
also, having empty "satisfy catch" block in there, if colleague, i'd hit heavy object, while shouting obscenities @ you. use e.printstacktrace()
, or proper logging framework. teachers won't hit this, can give bad marks...
Comments
Post a Comment