When I run my below code I get the below error, but it worked before and I am not sure what Eclipse got and is not good anymore
Error: Unable to initialize main class src.convolution
Caused by: java.lang.NoClassDefFoundError: org/opencv/core/Mat
package src;
import org.opencv.core.Core;
import org.opencv.core.CvType;
import org.opencv.core.Mat;
import org.opencv.imgcodecs.Imgcodecs;
import org.opencv.imgproc.Imgproc;
public class convolution {
public static void main( String[] args ) {
try {
int kernelSize = 9;
System.loadLibrary( Core.NATIVE_LIBRARY_NAME );
Mat source = Imgcodecs.imread("C:/Users/B & B/Desktop/ProcIMG/grayscale.jpg", Imgcodecs.IMREAD_GRAYSCALE);
Mat destination = new Mat(source.rows(),source.cols(),source.type());
Mat kernel = new Mat(kernelSize,kernelSize, CvType.CV_32F){
{
put(0,0,-3);
put(0,1,-3);
put(0,2,-3);
put(1,0-3);
put(1,1,0);
put(1,2,-3);
put(2,0,5);
put(2,1,5);
put(2,2,5);
}
};
Imgproc.filter2D(source, destination, -1, kernel);
Imgcodecs.imwrite("C:/Users/B & B/Desktop/ProcIMG/output.jpg", destination);
} catch (Exception e) {
System.out.println("Error: " + e.getMessage());
}
}
}
It could be .classpath issue. Try following steps
Delete Project from Eclipse don't delete content from disk.
remove .classpath and .project files
re-import project in Eclipse
I have the same problem, maybe you have already found your answer but as it is the first result of my web research I want to offer a solution to the others :
Just add the opencv_xxx.jar to the project classpath as external class. and it will work fine. (in Menu project -> properties -> java build path -> libraries tab -> classpath-> add external class folder button)
Hope it help many of you
Related
Hi Guys I am having an File inside src/main/resources/CustomersDetails.txt but i am getting an java.io.FileNotFoundException. But the Url is not null and my if condition is true but my eclipse throws me the following error: Why it is looking on target and in my target folder i have only the jar and my file is also present on the target folder Any ideas?
java.io.FileNotFoundException: C:\Users\Balachander%20K\eclipse-workspace\JavaLearning\target\classes\CustomersDetails.txt (The system cannot find the path specified)
at java.io.FileInputStream.open0(Native Method)
at java.io.FileInputStream.open(FileInputStream.java:195)
at java.io.FileInputStream.<init>(FileInputStream.java:138)
at java.io.FileReader.<init>(FileReader.java:72)
at com.syncfusion.Persons.main(Persons.java:22)
My Program:
package com.syncfusion;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import org.apache.commons.io.FileUtils;
public class Persons {
public static void main(String[] args) {
Persons person = new Persons();
try {
File file = person.getFileNameFromResources("CustomersDetails.txt");
FileReader fileReader = new FileReader(file);
BufferedReader bufferedReader = new BufferedReader(fileReader);
String line=bufferedReader.readLine();
while(line!=null) {
System.out.println(line);
line=bufferedReader.readLine();
}
} catch (IOException e) {
e.printStackTrace();
}
}
private File getFileNameFromResources(String fileName) {
ClassLoader loader = getClass().getClassLoader();
URL url = loader.getResource(fileName);
if(url!=null) {
System.out.println("File Found");
return new File(url.getFile());
}
System.out.println("File Not Found");
return null;
}
}
I tried to duplicate your program with Maven and running it with Eclipse, I got it to work!
Did you import your Maven project correctly?
When I import the Maven project into Eclipse, it will generate the target folder and place it in the correct path (target\classes\CustomerDetails.txt).
My second guess is that you probably added the txt file after importing the project into eclipse? In this way, it might not get compiled correctly?
You can either delete the project in eclipse (don't delete contents on disk) and delete the "target" folder, then import it again.
Or you can compile your mvn from the terminal,
mvn compile
mvn package
go back to your eclipse (right click --> refresh your project).
I'm new to java.
I am trying to use Java Advanced Imaging to read an Image file as explained in here http://www.oracle.com/technetwork/java/iio-141084.html
import java.awt.image.RenderedImage;
import javax.media.jai.JAI;
public class ImageGetterJAI {
public static void main(String[] args)
{
//image source
String imagedir = "C:\\Users\\Emre\\Desktop\\Image\\Grass.tif";
//get the image
RenderedImage image = JAI.create("imageload", imagedir);
}
}
But I get JAI cannot be resolved error. Am I doing a fundamental mistake.
Screenshot of the project is below, hope this helps.
I am beginner in java.
I want run native application from applet.
I found Run App In Every Browser
Java Code
import com.ms.security.*;
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import java.io.* ;
import java.util.*;
import netscape.security.PrivilegeManager;
public class RunApp extends Applet implements ActionListener {
TextArea ta = new TextArea (25, 80);
Button startbutton = new Button("Start Application") ;
private static String execommand = "C:\\windows\\notepad.exe" ;
private String osname;
public void init() {
try {
if (Class.forName("com.ms.security.PolicyEngine") != null) { // required for IE
PolicyEngine.assertPermission(PermissionID.SYSTEM);
}
}
catch (Throwable cnfe) {
}
this.setBackground(Color.white) ;
startbutton.addActionListener(this) ;
add(startbutton) ;
startbutton.setBackground(Color.red) ;
try{
PrivilegeManager.enablePrivilege("UniversalExecAccess") ; // required for NN
}
catch(Exception cnfe) {
System.out.println("netscape.security.PrivilegeManager class not found") ;
}
osname = System.getProperty("os.name"); // if NT, Win2000 or WinXP, adjust path
if(osname.equals("Windows NT") || osname.equals("Windows 2000")|| osname.equals("Windows XP"))
execommand = "C:\\winnt\\notepad.exe" ;
}
public void actionPerformed(ActionEvent e) {
if( (e.getActionCommand()).equals("Start Application")) {
try{
PrivilegeManager.enablePrivilege("UniversalExecAccess") ; // required for NN
}
catch(Exception cnfe) {
System.out.println("netscape.security.PrivilegeManager class not found") ;
}
try {
Process proc = Runtime.getRuntime().exec(execommand) ;
}
catch(IOException ieo) {
System.out.println("Problem starting " + execommand) ;
}
// System.out.println("execommand: " + execommand) ;
}
}
}
But when run it say error:package com.ms.security does not exit!
I does not any folder with ms or security name .
I should create folder with ms and then security in root file or should import library ms.security .
where is com.ms.security or netscape.security.PrivilegeManager?
how can download it?i search for download this package but i does not found anythings
I use eclipse for write code.
This package does not exist any more. The tutorial you point to dates from 2002. You can look at this javaranch post: http://www.coderanch.com/t/375470/java/java/Location-Jar-ms-security, and at the Microsoft documentation (https://msdn.microsoft.com/en-us/library/aa242534(v=vs.60).aspx). So basically your code would have worked 13 years ago, but with Microsoft not supporting their own JVM any more it's obsolete. Sorry!
You need to download that jar having this package ,com.ms.security. And b4 compiling your java class set that jar in your classpath from command prompt.
set classpath=%classpath%;path_of_your_jar;
This package is not existed anymore. Microsoft is not supporting their own JVM anymore. You should try to learn java applet in the new way, such as http://www.tutorialspoint.com/java/java_applet_basics.htm.
The import statement import com.ms.security.*; requires you to have a folder com, with a subfolder ms, with a subfolder security, which contains the needed files.
I think you are missing some files for your application.
I recommend reading this post, for the use of imports: https://stackoverflow.com/a/12620773/3234981
Please check your jar file which contain the respective package are present in the classpath or not. If not, push them to classpath and re-compile the same class on a new command line.
Happy Learning.
I've got an issue with my .jar file. It runs fine in Eclipse but as soon as I export it, it won't open. I've checked the manifest file and it looks like it's okay.
I've tried exporting it as a runnable jar, as well as just using the jar builder. Nothing worked.
I've tried to run it in command prompt and it says it can't access the jar file... I've searched around a while on here and haven't found an answer yet.
I'm not sure what I'm doing wrong. The only thing I can think of is I'm not getting my images correctly.
I'm using .png files for the program's sprites and here's an example of how I get them for my program.
This code begins the building of a level from a .png file.
public class SpawnLevel extends Level{
public SpawnLevel(String path) {
super(path);
}
protected void loadLevel(String path){
try{
System.out.println("classpath is: " + System.getProperty("java.class.path"));
BufferedImage image = ImageIO.read(SpawnLevel.class.getResource(path));
int w = width = image.getWidth();
int h = height= image.getHeight();
tiles = new int[w*h];
image.getRGB(0,0,w,h,tiles,0,w);
}catch(IOException e){
e.printStackTrace();
System.out.println("EXEPTION FOUND!!! Could not load the level file!");
}
}
protected void generateLevel(){
System.out.println("Tiles: " + tiles[0]);
}
}
I've made one other .jar before for another program and didn't have a problem. Any help would be greatly appreciated.
If it helps, I used this code to display the resource folder path information.
System.out.println("classpath is: " + System.getProperty("java.class.path"));
Here's what my current path for my resources folder looks like. Before I export it from eclipse.
classpath is: C:\Users\name\workspace\Rpg_Game\bin;C:\Users\name\workspace\Rpg_Game\res
After I export to .jar
classpath is: 2ndGameTest.jar
If your images are in your resources package in the src The path you should be using for getResource() is something like
class.getResource("/resources/levels/level1.png")
UPDATE with test program
import java.awt.Image;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
public class TestImage {
public static void main(String[] args) throws IOException {
Image image = ImageIO.read(TestImage.class.getResource("/resources/images/image.png"));
ImageIcon icon = new ImageIcon(image);
JLabel label = new JLabel(icon);
JOptionPane.showMessageDialog(null, label);
}
}
I created a report from my NetBeans GUI and It was working fine, but all of a sudden the compiler showing error now.
package dreportsample;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import net.sf.dynamicreports.examples.Templates;
import net.sf.dynamicreports.report.builder.style.StyleBuilder;
import net.sf.dynamicreports.report.constant.HorizontalAlignment;
import net.sf.dynamicreports.report.datasource.DRDataSource;
import net.sf.dynamicreports.report.exception.DRException;
import net.sf.jasperreports.engine.JRDataSource;
/**
* #author Ricardo Mariaca (dynamicreports#gmail.com)
*/
public class DReportSample {
public DReportSample() {
build();
}
private void build() {
StyleBuilder boldStyle = stl.style().bold();
StyleBuilder boldCenteredStyle = stl.style(boldStyle).setHorizontalAlignment
(HorizontalAlignment.CENTER).setFontSize(15);
StyleBuilder footerLeft = stl.style().setHorizontalAlignment
(HorizontalAlignment.LEFT) ;
StyleBuilder footerRight = stl.style().setHorizontalAlignment
(HorizontalAlignment.RIGHT) ;
//BufferedImage img = new BufferedImage(1200,1200,BufferedImage.TYPE_INT_RGB);
BufferedImage img = null;
try {
// img = ImageIO.read(new File("D:/Hysteresis.png"));
img = ImageIO.read(new File("D:/Hysteresis.png"));
} catch (IOException e) {
}
BufferedImage logo = null;
try {
// img = ImageIO.read(new File("D:/Hysteresis.png"));
logo = ImageIO.read(new File("D:/Logo.jpg"));
} catch (IOException e) {
}
try {
report()//create new report design
// .setColumnTitleStyle(boldStyle)
// .setColumnStyle(boldStyle)
.highlightDetailEvenRows()
.columns(//add columns
col.column(null,"Col_1", type.stringType()),
col.column(null,"Col_2", type.stringType())
)
.summary(
cmp.verticalList()
.add(cmp.text("\n\nHYSTERISIS PLOT").setStyle(boldStyle))
.add(cmp.text("A brief description of what this plot signifies "
+ "which means that change in are related to"
+ " pain relief and subsequently"
+ "should be encouraged \n\n\n\n"))
// .add(cmp.image(getClass().getResourceAsStream
// ("D:/Hysteresis.png")).setFixedDimension(300, 300))
.add(cmp.image(img).setFixedDimension(400, 300))
.add(cmp.text("ANALYSIS\n\n\n").setStyle(boldStyle))
.add(cmp.text("REMARKS\n\n\n\n").setStyle(boldStyle))
.add(cmp.text("Doctor Signature").setStyle(boldStyle))
)
.title(
cmp.horizontalList()
.add(
cmp.image(logo).setFixedDimension(70, 70),
cmp.verticalList()
.add(
cmp.text("Address Line 1").setStyle(boldCenteredStyle),
cmp.text("Address Line 2").setStyle(boldCenteredStyle),
cmp.text("Address Line 3").setStyle(boldCenteredStyle))
)
.newRow()
.add(cmp.filler().setStyle(stl.style().setTopBorder(stl.pen2Point())).setFixedHeight(10))
)//shows report title
// .pageFooter(cmp.pageXofY())//shows number of page at page footer
.pageFooter(
Templates.footerComponent,
//cmp.text("Emsol Software Solution \t\t\t\t\t\t\t\t"
// + " copyright: gauravbvelelx#gmail.com")
cmp.horizontalList()
.add(cmp.text("Emsol Software Solution").setStyle(footerLeft),
cmp.text("copyright: gauravbvelex#gmail.com").setStyle(footerRight))
)
.setDataSource(createDataSource())//set datasource
.show();//create and show report
} catch (DRException e) {
e.printStackTrace();
}
}
private JRDataSource createDataSource() {
DRDataSource dataSource = new DRDataSource("Col_1", "Col_2");
dataSource.add("Name","Sample");
dataSource.add("Age","26");
dataSource.add("Sex","Female");
dataSource.add("Weight","53 Kg");
dataSource.add("BMI","20");
dataSource.add("Massage Duration (Mins)","4.5");
dataSource.add("RPM","26");
dataSource.add("Doctor Attended","Doctor");
dataSource.add("Date","22-Feb-2013");
return dataSource;
}
public static void main(String[] args) {
new DReportSample();
}
}
This code worked fine just few hours back. But now it is suddenly showing error:
Screen shot attached
Same kind of error it is showing at report() and other parts as well. Basically it is not able to recognize various classes and fields of dynamic reports library though the library has been imported successfully, though few hours back it was working well.
The way I am using dynamic reports is by adding the libraries as below:
1) Downloaded dynamicreports-3.1.0-project-with-dependencies
2) Unzipped
3) In my Netbeans Project
Libraries -> Add Jar/folder -> Selecting all files from dynamicreports-3.1.0-project-with-dependencies\dynamicreports-3.1.0\lib
Libraries -> Add Jar/folder -> Selecting all files from dynamicreports-3.1.0-project-with-dependencies\dynamicreports-3.1.0\dist
It worked fine, but then then I changed the name of the folder where I saved dynamicreports-3.1.0-project-with-dependencies, due to which It gave me Reference Error for added libraries. So I again rechanged it to previous name, but since then I am getting the error shown.
I have tried everything, building new project and following the steps mentioned or re downloading new dynamicreports-3.1.0-project-with-dependencies and again following the steps. But nothing seems to work, its frustrating as I was so close to complete my project.
Can anyone help please.
Thanks
Ok.. resolved it..
Below line got deleted causing the errors:
import static net.sf.dynamicreports.report.builder.DynamicReports.*;