Intellj recognizing .wav files as plain text - intellij-idea

https://i.stack.imgur.com/2IIvj.png
So I'm trying play a sound everytime a letter is typed on screen. The code is definately correct since I copied it from a reliable source online. The only problem is I keep getting the (The system cannot find the path specified) error. Intellij recognizes .wav files as plain text for some reason. Is there a fix to this? Im I doing something wrong? Nothing I searched for works. Here is the code I use :
private class SoundEffect{
Clip clip;
public void setFile(String path) {
try {
File file = new File(path);
AudioInputStream sound = AudioSystem.getAudioInputStream(file);
clip = AudioSystem.getClip();
clip.open(sound);
} catch (UnsupportedAudioFileException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (LineUnavailableException e) {
e.printStackTrace();
}
}
public void play(){
clip.setFramePosition(0);
clip.start();
}
}
I am getting the error when I use the setFile method.

Related

How can ı delete the history in the allure testng but not in the terminal, we can use code

ı want to delete my data test history in the allure testng but not in the terminal, ı want to use some functions or any annotation in my java code
Try this:
public void deleteDirectory(String directoryPath) throws IOException {
Path path = Paths.get(directoryPath);
try (Stream<Path> walk = Files.walk(path)) {
walk
.sorted(Comparator.reverseOrder())
.forEach(this::deleteTargetDirectory);
}
}
private void deleteTargetDirectory(Path path) {
try {
Files.delete(path);
} catch (IOException e) {
System.err.printf("Unable to delete this path : %s%n%s", path, e);
}
}

How to locate config properties file when moving code to jenkins>

I am currently adding a config properties file to my test code. It works fine on my local machine but when I move it to Jenkins it fails. I think I know the problem but I am looking for the best solution. Here is my code:
public static void main(String [] args) throws IOException{
File file = new File("C:\\Users\\Test\\Regrassion_Framework\\src\\main\\java\\GUI\\config.properties");
FileInputStream fileInput = null;
try {
fileInput = new FileInputStream(file);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
Properties prop = new Properties();
//load properties file
try {
prop.load(fileInput);
} catch (IOException e) {
e.printStackTrace();
}
System.err.println(prop.getProperty("url"));
}
}
I think the problem is that I specify my config file locally. Should I edit this when I move my code to jenkins and how? Should I do this manually or can this be done an easier way without the chance of human error causing propblems
If this properties file is only used with this one project, you can package it with your test code. You can load the resource like this:
InputStream is = YourTestClassName.class.getClassLoader().getResourceAsStream("your/package/name/testFiles/config.properties")
If it's used in multiple projects, consider putting it in a shared directory or storing it in source control.

Plugin Development: Eclipse hangs when testing plugin

I am new to developing plugins, and was wondering what causes a test plugin to hang when started i.e. Eclipse is unresponsive.
I know that my code is working as I developed a voice recognition plugin to write to the screen what is said and when I open notepad everything I say is printed to notepad.
So I was wondering, am I missing something in the plugin life-cycle that causes the IDE to hang when my plugin is started?
package recognise.handlers;
public class SampleHandler extends AbstractHandler {
public SampleHandler() {
}
/**
* the command has been executed, so extract extract the needed information
* from the application context.
*/
public Object execute(ExecutionEvent event) throws ExecutionException {
boolean finish = false;
IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
MessageDialog.openInformation(
window.getShell(),
"Recognise",
"Starting Recognition");
TakeInput start = new TakeInput();
//Stage a = new Stage();
//SceneManager scene = new SceneManager();
try {
start.startVoiceRecognition(finish);
//scene.start(a);
} catch (IOException | AWTException e) {
e.printStackTrace();
}
return null;
}
}
Does the start.startVoiceRecognition() need to be threaded?
Thanks in advance and let me know if you would like to see my manifest/activator etc.
Conclusion
Added a job separate to the UI thread
/*
* Start a new job separate to the main thread so the UI will not
* become unresponsive when the plugin has started
*/
public void runVoiceRecognitionJob() {
Job job = new Job("Voice Recognition Job") {
#Override
protected IStatus run(IProgressMonitor monitor) {
TakeInput start = new TakeInput();
try {
start.startVoiceRecognition(true);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (AWTException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// use this to open a Shell in the UI thread
return Status.OK_STATUS;
}
};
job.setUser(true);
job.schedule();
}
As shown start.startVoiceRecognition() is running in the UI thread, and it will block the UI thread until it is finished and the app will be unresponsive during that time. So if it is doing a significant amount of work either use a Thread or use an Eclipse Job (which runs work in a background thread managed by Eclipse).
To unblock your UI you have to use Display thread.
/**
* the command has been executed, so extract extract the needed information
* from the application context.
*/
public Object execute(ExecutionEvent event) throws ExecutionException {
Display.getDefault().asyncExec(new Runnable() {
public void run() {
boolean finish = false;
IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
MessageDialog.openInformation(
window.getShell(),
"Recognise",
"Starting Recognition");
TakeInput start = new TakeInput();
//Stage a = new Stage();
//SceneManager scene = new SceneManager();
try {
start.startVoiceRecognition(finish);
//scene.start(a);
} catch (IOException | AWTException e) {
e.printStackTrace();
}
MessageDialog.openInformation(shell, "Your Popup ",
"Your job has finished.");
}
});
return null;
}
You can use Display.getDefault().asyncExec() as mentioned above, so your UI will be unblocked, while your non UI code will be executing.

Adding directory to classpath in IntelliJ 12

I know this has been addressed before here but this solution doesn't work for me, and I don't know why.
I follow the given steps, but at 5 there is no dialog that comes up. I am trying to add mp3plugin.jar to my dependencies, but after following this process, I still get an UnsupportedAudioFileException at runtime.
What am I doing wrong?
Here is a screencast of what I am doing: http://www.screenr.com/G70H
Here is the code that uses the audio file:
import javax.sound.sampled.*;
import java.io.File;
import java.io.IOException;
public class Sound {
private Clip clip;
public Sound (String in){
try{
File file = new File ("src/music/" + in + ".mp3");
//System.out.println(file.getAbsolutePath());
clip = AudioSystem.getClip();
AudioInputStream inputStream = AudioSystem.getAudioInputStream(file);
clip.open(inputStream);
} catch (IOException e){
e.printStackTrace();
} catch (LineUnavailableException e){
e.printStackTrace();
} catch (UnsupportedAudioFileException e){
e.printStackTrace();
}
}
public void stop(){
clip.stop();
}
public void loop(){
if (!clip.isActive()){
clip.setFramePosition(0);
clip.loop(Clip.LOOP_CONTINUOUSLY);
} else {
System.out.println("already playing..");
}
}
}
And in this runs it:
Sound sound = new Sound (in.readLine()); //from a bufferedreader
sound.loop();
I know this works because it works with .wav files.

Progress is not shown in Eclipse wizard window

I am developing an Eclipse plugin that creates a project in the current workspace. I want to show a progress bar in the wizard window (above the next - previous - finish buttons ) to represent the progress of creation. However, when the finish button is pressed, the progress bar is not shown. Below is my code.
#Override
WorkspaceModifyOperation op = new WorkspaceModifyOperation() {
#Override
protected void execute(IProgressMonitor monitor) throws CoreException,
InvocationTargetException, InterruptedException {
monitor.beginTask("Create *** Project", 100);
try {
ProjectUtil.createProject(monitor);
} catch (Exception e) {
} finally {
monitor.done();
}
monitor.done();
}
};
try {
getContainer().run(true, true, op);
} catch (InvocationTargetException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Inside the createProject(IProgressMonitor monitor) method of class ProjectUtil, I have monitor.worked(someWork) after each operation.
What am I missing?
Try to set setNeedsProgressMonitor(true); in the class, which extends Wizard. Hope this helps.