Tag Archives: java

Centos7 View java-v Error [How to Solve]

[root@localhost ~]# java -v
Unrecognized option: -v
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.

jdk1. 7 view the version number through java -V and java --version,
and jdk1 8 you have to check the version number through java -version

JAVA package Run Error: Java hotspot (TM) 64 bit server VI warning: Info: OST; The ‘eror’ page file is too small to complete the operation

Run the jar package

Error content: Java hotspot (TM) 64 bit server VI warning: Info: OST; comn it_ memary(Ox10000085800,130023424,0) failed; The ‘eror’ page file is too small to complete the operation. (Dos error 7errno=1455)

Cause: because the memory of the configured JVM is too small or the size is not set

Solution: modify run configurations before packaging in eclipse

Right-click the code and click “run as” -> “Run configurations”, fill in the following values in “VM arguments:” in the arguments parameter.

-Xms64m -Xmx128m

Note: the memory setting can be modified according to the actual situation of the project. If the memory allocation is small, when the applied memory is greater than the set memory (Tomcat maximum memory – Xmx), full GC (STW) will be triggered. When performing full GC, there will be a jam. The memory allocation of each project can be allocated according to the frequency of use of the project

[Solved] Weblogic error: java.lang.NoClassDefFoundError: Could not initialize class sun.awt.X11G

Error message: Java.lang.NoClassDefFoundError: Could not initialize class sun.awt.X11G

After looking at the background, locate the error code as follows

//Save a thumbnail image locally
BufferedImagesrc=ImageIO.read(file2);
FilelocalDir=newFile(GlobalConstants.SAVE_PATH+GlobalConstants.SMALL_IMAGE_SAVE_PATH);
if(!localDir.exists()){
    localDir.mkdirs();
}
//The following code starts reporting errors
BufferedImageoutImg=newBufferedImage(60,60,BufferedImage.TYPE_INT_RGB);
outImg.getGraphics().drawImage(src,0,0,60,60,null);

Solution:

Open the setDomainEnv.sh configuration file under the weblogic domain service bin

Add parameters in the following positions:

JAVA_OPTIONS="${JAVA_OPTIONS} -Djava.awt.headless=true " ​
export JAVA_OPTIONS

[Solved] JAVA Beginners’ Error: Exception in thread “main“ java.io.FileNotFoundException

0x00 overview

During the practice in the Java IO flow chapter, an error was found when running the code, saying that the file path is incorrect.

0x01 solution

Error code

package FileDemo2;

import java.io.File;
import java.io.IOException;

public class FileDemo2 {
    public static void main(String[] args) throws IOException {
        // Requirement 1:Create a file java.txt in the C:\Users\119k\IdeaProjects\d17\FileDemo2\ directory
        File f1 = new File("C:\\Users\\119k\\IdeaProjects\\d17\\FileDemo2\\java.txt");
        System.out.println(f1.createNewFile());
        System.out.println("--------------");


        // Requirement 2:Create a directory in the C:\Users\119k\IdeaProjects\d17\FileDemo2\ directory
        File f2 = new File("C:\\Users\\119k\\IdeaProjects\\d17\\FileDemo2\\JavaSE\\");
        System.out.println(f2.mkdir());
        System.out.println("--------------");

        // Requirement 3:Create a multi-level directory in the C:\Users\119k\IdeaProjects\d17\FileDemo2\ directory \JavaSE\JavaEE\
        File f3 = new File("C:\\Users\\119k\\IdeaProjects\\d17\\FileDemo2\\JavaSE\\JavaEE\\");
        System.out.println(f3.mkdirs());
        System.out.println("--------------");

        // Requirement 4:Create a file javaSE.txt in the C:\Users\119k\IdeaProjects\d17\FileDemo2\ directory
        File f4 = new File("C:\\Users\\119k\\IdeaProjects\\d17\\FileDemo2\\javaSE.txt");
        System.out.println(f4.createNewFile());
        System.out.println("--------------");
    }
}

For the revised code, add \src

package FileDemo2;

import java.io.File;
import java.io.IOException;

public class FileDemo2 {
    public static void main(String[] args) throws IOException {
        // Requirement 1:Create a file java.txt in the C:\Users\119k\IdeaProjects\d17\FileDemo2\ directory
        File f1 = new File("C:\\Users\\119k\\IdeaProjects\\d17\\src\\FileDemo2\\java.txt");
        System.out.println(f1.createNewFile());
        System.out.println("--------------");


        // Requirement 2:Create a directory in the C:\Users\119k\IdeaProjects\d17\FileDemo2\ directory
        File f2 = new File("C:\\Users\\119k\\IdeaProjects\\d17\\src\\FileDemo2\\JavaSE\\");
        System.out.println(f2.mkdir());
        System.out.println("--------------");

        // Requirement 3:Create a multi-level directory in the C:\Users\119k\IdeaProjects\d17\FileDemo2\ directory \JavaSE\JavaEE\
        File f3 = new File("C:\\Users\\119k\\IdeaProjects\\d17\\src\\FileDemo2\\JavaSE\\JavaEE\\");
        System.out.println(f3.mkdirs());
        System.out.println("--------------");

        // Requirement 4:Create a file javaSE.txt in the C:\Users\119k\IdeaProjects\d17\FileDemo2\ directory
        File f4 = new File("C:\\Users\\119k\\IdeaProjects\\d17\\src\\FileDemo2\\javaSE.txt");
        System.out.println(f4.createNewFile());
        System.out.println("--------------");
    }
}

The absolute path of the file needs to be obtained in the IDE. Here, copy-absoulte path is used to find that there is more \\src in the file path

[Solved] Java EE file upload Error: web.xml error

Javaee file upload
Web.xml error
The error content is as follows:

cvc-id.3: A field of identity constraint ‘web-common-servlet-name-uniqueness’ matched element ‘web-app’, but this element
does not have a simple type.

Solution:

xsi:schemaLocation=”http://java.sun.com/xml/ns/javaee
Change the ‘java’ to uppercase

[Solved] JAVA Error: Error running ‘ModuleEmptyApplication’: Command line is too long. Shorten command line for ModuleEmptyApplication or also for Spring Boot default configuration.

Found in the project folder.idea/workspace.xml
<component name=”PropertiesComponent”>

</component>
Then add in it:
<property name=”dynamic.classpath” value=”true” />

[Solved] JAVA Error: org.springframework.beans.factory.BeanCreationException

1. Error type

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.cache.interceptor.CacheInterceptor#0'
: Cannot resolve reference to bean 'cacheManager' while setting bean property 'cacheManager';
 nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'cacheManager' available

Screenshot of error type:

2. Error reason

There are many reasons for such problems. I can only talk about the reasons for the above mistakes

The problem is   In the applicationcontext.xml configuration file under the Resources folder

As shown in the figure above, one of the mistakes that beginners are prone to make

3. Solution

Change

xmlns:mvc="http://www.springframework.org/schema/cache"

to

xmlns:mvc="http://www.springframework.org/schema/mvc"

I hope I can help you!

JAVA: scanner Read File encoding Error noSuchElementException

I need to demonstrate to customers locally importing data from postgresql into elasticsearch. I wrote a program read3.java in idea. There is no problem reading the file content with scanner.

But this read3.java is only used to convert the json file exported by the table into a valid json file that can be imported into es, and does not add the dependency that needs to be downloaded, but I have to do it in the idea every time I run it.

So I directly found the target path of read3.java and copied it to the desktop.

Compile a .class file with javac directly on the desktop and then start running.

Every time there is an error, that is

Exception in thread “main” java.util.NoSuchElementException
at java.util.Scanner.throwFor(Scanner.java:862)
at java.util.Scanner.next(Scanner.java:1371)

……

Then I reopened the notepad and created an abc.json file, saved the encoding format as “utf-8”, and then used read3 to read the file, and the read out was garbled.

So I thought that there is a problem with the encoding of the characters read by the scanner. When creating the scanner, specify the encoding, that is, Scanner sc=new Scanner(new FIle(“xxx”),”utf-8″));

Then use notepad++ to open the file that needs to be read, and find that the file encoding is utf-8 bom, so I converted the encoding format to utf-8 and re-run. The problem is solved.

[Solved] Java compilation error: unmapped character encoding GBK

Today, a helloworld.java source file is created by using the Echo instruction of the windows command line. The following errors are reported when compiling into a bytecode file:

Cause and solution: when javac compiles the source file, it needs to decode the source file. By default, the character encoding of the operating system is used for decoding. The simplified version of win11 uses GBK, so pay attention to whether GBK is used when encoding the source file. If there is only English, the encoding method of the source file is only compatible with ASCII code. Or you can change the character encoding during decoding through the command parameters of javac.

JAVA Error: MalformedURLException: unknow protocol: f

Question:

Java use URL reading file interpretation error MalformedURLException

1. Malformedurlexception: unknown protocol: F is reported when using URL object to parse the file. It’s quite confusing. Check the URL class source code

It is found that the parameter prefix needs to be “Protocol”, because the parameter I transmitted is a file under a disk. Of course, the drive letter here is not a protocol, so I decided to add it in front

File:///, the whole becomes   file:/// F://test.txt

because   “file:///” Is a standard general document protocol

2. Here is a knowledge point, that is, the HTTP protocol we usually know. The general path is http://10.0.0.1:port/xxx/xxx ,

Why is the File Protocol   ///, The difference is that the file path has no host, that is, the host IP, so it is directly omitted here