Tag Archives: java

[Solved] Java read excel file unable to recognize ole stream error

Error:

jxl.read.biff.BiffException: Unable to recognize OLE stream
at jxl.read.biff.CompoundFile.<init>(CompoundFile.java:116)
at jxl.read.biff.File.<init>(File.java:127)
at jxl.Workbook.getWorkbook(Workbook.java:268)
at jxl.Workbook.getWorkbook(Workbook.java:253)
at test1.main(test1.java:25)

Solution: No expenditure to read excel 2007 files (*.xlsx). Only excel 2003 (*.xls) is supported.

Troubleshooting of last block incomplete in decryption error in wechat applet Java

Open source software supply chain lighting plan, waiting for you>>>

I encountered this problem to solve two days, the result pit miserable

It turned out to be an encrypted data problem. When the applet returned, it encoded the URL… With a bunch of them

So you have to decode the URL, and then decode Base64… Small procedures, you pit it

Java error: No enclosing instance of type E is accessible. Must qualify the allocation with an enclosing

 

public class Close {
	public static void main(String[] args){
		try{
		
			Resource res = new Resource();//This compilation prompts an error
			res.dosome();
			
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	 class Resource implements AutoCloseable{
		void dosome(){
			System.out.println("Do something");
		}
		public void close() throws Exception{
			System.out.println("Resources are closed");
		}
	}
}

Error content: no enclosing instance of type close is accessible. Must qualify the allocation with an enclosing instance of type close (e.g. X.New a() where x is an instance of close)

that is, if there is no accessible instance of inner class E, an appropriate instance of inner class E must be assigned (such as X.New a (), X must be an instance of E.) looking at this prompt, I wonder why I have instantiated this class with new

It turns out that the internal class I wrote is dynamic, that is, it starts with public class. The main program is public static class main. In Java, static methods in a class cannot directly call dynamic methods. Only if an internal class is modified to a static class, then the member variable and member method of the class can be invoked in a static class. Therefore, without making other changes, the simplest solution is to change the public class to public static class.

An error was reported when Java connected to SQL server. Sqljdbc could not be found_ auth.dll

Geeks, please accept the hero post of 2021 Microsoft x Intel hacking contest>>>

Recently, I am studying Java connection to sqlserver2008. But I always report an error: failed to load the sqljdbc_ auth.dll cause : no sqljdbc_ auth in java.library.path。

Environment: Windows 7 + Tomcat + JDK1.8 + Maven.
after a search, it is found that the domestic Baidu result is to add sqljdbc to java.library.path_ Auth.dll file. Or put it under system 32 stackoverflow problem:( http://stackoverflow.com/questions/15844875/jdbc-intellij-failed-to-load-the-sqljdbc-auth-dll )
Microsoft note 1: https://msdn.microsoft.com/zh-cn/library/gg558122.aspx )
Microsoft note 2: https://msdn.microsoft.com/zh-cn/library/ms378428.aspx# China (Simplified Chinese))
according to the above explanation, I used the following connection string and it passed
jdbc:sqlserver ://192.168.1.10:1433; DatabaseName=master; authenticationScheme=JavaKerberos;

Thoughts:

The people of our country don’t really understand. There are just a few words of copy and paste everywhere. It leads to a very poor understanding of the problem. It seems that English needs special attention in the future

Java call opencv face recognition error insufficient out of memory

Opencv is a cross platform computer vision library based on BSD license (open source), which can run on Linux, windows and Mac OS operating systems. It is lightweight and efficient, which is composed of a series of C functions and a small number of C + + classes. It also provides the interfaces of Java, python, ruby, MATLAB and other languages, and realizes many general algorithms in image processing and computer vision

When opencv is called with Java JNI, it is OK to recognize a single picture. When there are a lot of pictures, an error will be reported

OpenCV Error: Insufficient memory (Failed to allocate 411068927 bytes) in cv::OutOfMemoryError, file opencv\modules\core\src\alloc.cpp, line 52 OpenCV Error:

​
        System.out.println("\nRunning Template Matching");

        Mat img = Highgui.imread(inFile);
        Mat templ = Highgui.imread(templateFile);

        ///Create the result matrix
        int result_cols = img.cols() - templ.cols() + 1;
        int result_rows = img.rows() - templ.rows() + 1;
        Mat result = new Mat(result_rows, result_cols, CvType.CV_64FC1);

        ///Do the Matching and Normalize
        Imgproc.matchTemplate(img, templ, result, match_method);
        Core.normalize(result, result, 0, 1, Core.NORM_MINMAX, -1, new Mat());

        ///Localizing the best match with minMaxLoc
        MinMaxLocResult mmr = Core.minMaxLoc(result);

        Point matchLoc;
        if (match_method == Imgproc.TM_SQDIFF || match_method == Imgproc.TM_SQDIFF_NORMED) {
            matchLoc = mmr.minLoc;
        } else {
            matchLoc = mmr.maxLoc;
        }
        
        
        ///Show me what you got
        Core.rectangle(img, matchLoc, new Point(matchLoc.x + templ.cols(),
                matchLoc.y + templ.rows()), new Scalar(0, 255, 0));

        // Save the visualized detection.
        System.out.println("Writing "+ outFile);
        Highgui.imwrite(outFile, img);

​

JNI calls native’s C + + method because of memory overflow, but it didn’t release the object. Display call:

img.release();

templ.release();
result.release();

Solve it. C + + is the trouble of actively releasing referenced objects

Java system. Currenttimemillis() and system. Nanotime

Nanosecond

NS (nanosecond): nanosecond,

Time unit. One billionth of a second is equal to the minus ninth power of 10. Commonly used as

A unit of memory read-write speed. The smaller the number in front of it, the faster it is.

1 nanosecond = 1000

Picosecond

1 ns = 0.001

Microsecond

1 ns = 0.00000 1

millisecond

1 nanosecond = 0.00000 0001 seconds

What is the difference between system. Currenttimemillis() and system. Nanotime() in Java

In Java, system. Nanotime() returns nanoseconds, and nanotime may return any time, or even negative numbers… According to the API, the main purpose of nanotime is to measure a period of time, such as the time for a code execution, the time for database connection, the time for network access, etc. In addition, nanotime provides nanosecond precision, but the actual value may not be accurate to nanosecond

But in general, these two functions are used for different purposes

The MS returned by system. Currenttimemillis() in Java is actually the number of MS since 0:00 on January 1, 1970. Date() is actually equivalent to date (system. Currenttimemillis()); Because the date class also constructs a date (long date) to calculate the millisecond difference between long seconds and January 1, 1970

The solution of the import javax.servlet cannot be resolved in Java

The import javax.servlet cannot be resolved solution appears  

The method provided on the Internet is, in Eclipse, right-click the project, select Build Path->configure build path->Libraries->Add External JARs, find the decompression path of tomcat on your computer, and select “servlet-api” under the lib folder .jar”, add and click “OK”

Description Resource Path Location Type Java compiler level does not match the version of the insta

Right-click Properties-“Project Facets on the project, and select the corresponding version in the Java drop-down list on the opened Project Facets page.
It may be java1.6 changed to java6 or something

 

 

Could not find HttpServlet

 

 

JAVA ERROR: The public type *** must be defined in its own file***

The problem of the public type C must be defined in its own file occurs because the defined Java class is inconsistent with the file name 1. Change the file name to the same name as the public class
2. Change the class name to the same file name
3. When a subclass inherits a parent class, it does not need to modify it with public again

Type safety: unchecked cast from object to

First of all, the Java language lab is type safe. We usually encounter this problem when the object is converted to the target type

This transformation is not safe. This problem is generally believed to be caused by the use of JDK1.5 or 1.6 generics

Request. Getattribute (“* *”) gets a type that defaults to object. When you convert them to list & lt***> When

The compiler thinks that there may be errors, so it prompts that this type is safe

But how to remove this warning?The following is a common way to remove the warning (but the danger has not been removed)

1: Method to add @ suppresswarnings (“unchecked”)

2: Eclipse’s window – > Preferences-> Java-> Compiler-> Errors/Warning-> In generic types, unchecked generic type operation is set to ignore

3: Eclipse’s window – > Preferences-> Java-> Compiler sets compiler compliance level to less than 1.5