Operating system: Window10
1. During the JUnit test of ShopServiceTest, an error message is reported:addShopImg error:null
as follows:
Solution: Modify the configuration information of PathUtil.java.
Check whether the two separators ofprivate static String separator=System. getProperty ("file. separator")
are consistent and spelled correctly.
As long as the two separators are consistent and spelled correctly, there will be no null error message
2. The win10 system pops up:addShopImg error: character to be escaped is missing
as follows:
Solution: Modify the configuration information of PathUtil.java.
Change all separator
in replaceAll to Matcher quoteReplacement(separator)
Finally, the completely correct PathUtil.java source code is attached:
package com.imooc.o2o.util;
import java.util.regex.Matcher;
public class PathUtil {
private static String separator = System.getProperty("file.separator");
public static String getImgBasePath() {
String os = System.getProperty("os.name");
String basePath = "";
if (os.toLowerCase().startsWith("win")) {
basePath = "E:/Work/o2o/image";
} else {
basePath = "/home/Work/o2o/image";
}
basePath = basePath.replaceAll("/", Matcher.quoteReplacement(separator));
return basePath;
}
public static String getShopImagePath(long shopId) {
String imagePath = "upload/item/shop/" + shopId + "/";
return imagePath.replaceAll("/", Matcher.quoteReplacement(separator));
}
}
Read More:
- I/O error while reading input message; nested exception is java.io.IOException: Stream closed
- Uncaught SyntaxError: Unexpected token o in JSON at position 1 [How to Solve]
- [Solved] O2oa compile error: Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin
- o.s.boot.SpringApplication, Error creating bean with name ‘paymentImpl‘, xml Configuration file error
- [Solved] AndroidStudio libcrypto.a(armcap.o):armcap.c:function OPENSSL_cpuid_setup: error: undefined referen
- [Solved] spingboot Error: I/O error on POST request for “9411/api/v2/spans“: connect timed out
- IDEA Error: ERROR 16720 —[ restartMain] o.a.coyote. http11.Http119Protocol: Failed to sta
- [Solved] ERROR o.s.s.s.TaskUtils$LoggingErrorHandler – Unexpected error occurred in scheduled task.
- [Solved] Spring boot Run Error: o.s.b.d.LoggingFailureAnalysisReporter ERROR;
- Jmeter Error: ERROR o.a.j.JMeter: Uncaught exception in thread Thread[AWT-EventQueue-0,6,main]
- Jjwt error: ERROR 9856 — [nio-8083-exec-2] o.a.c.c. [. [. [. [/]. [dispatch server]
- [Solved] weblogic12c start the project error: BeanFactoryAware is missing
- Mapper.xml Error: Error setting non null for parameter #3 with JdbcType null.
- [Solved] Javaweb Error: inStream parameter is null
- [Solved] java.sql.SQLException: Unsupported character encoding ‘utf-8
- JNI ERROR (2354): JNI connection is NULL [How to Solve]
- Java learning unreported exception java.io.IOException ; must be caught or declared to be thrown
- Mongodb java version 3.X, prompt “XXX (an encryption algorithm) is not available” when there is a user name and password
- [Solved] ‘build.plugins.plugin.version‘ for org.springframework.boot:spring-boot-maven-plugin is missing.
- Dubbo failed to register and consumer null pointer exception