此问题的后续问题: Swing 字体名称不匹配?(制作字体选择器,并尝试在 JComboBox 中显示默认系统字体)
看来有逻辑字体和物理字体。逻辑字体有:Serif、SansSerif、Monospaced、Dialog 和 DialogInput。
这些字体是动态的,它们各自的物理字体(它们在程序执行期间表示的字体)是在程序加载时决定的。
我需要访问这些逻辑字体的物理字体。
我的第一个想法是尝试加载这些文件: http://download.oracle.com/javase/6/docs/technotes/guides/intl/fontconfig.html#loading
通过使用这样的东西: http ://www.rgagnon.com/javadetails/java-0434.html
public static Properties load(String propsName) throws Exception {
Properties props = new Properties();
URL url = ClassLoader.getSystemResource(propsName);
props.load(url.openStream());
return props;
}
Run Code Online (Sandbox Code Playgroud)
然后从这些属性文件中获取物理字体。
但是,当我尝试使用第一个文件中的名称加载属性时,我刚刚收到 NullPointerExceptions(未找到它们,但我已检查并实际上在我的系统上找到了它们)。我不知道为什么我会得到这个,但无论如何,我不禁想一定有一种更简单的方法来做到这一点?
slf4j api 中存在类 org.slf4j.impl.StaticLoggerBinder、org.slf4j.impl.StaticMarkerBinder、org.slf4j.impl.StaticMDCBinder。但是到具体记录器的每个绑定都应该包含相同的类。
例如:
java类加载器如何替代它?这里不应该是一个例外吗?
这是我的代码:
package biz.tugay.deleteNow;
/* User: koray@tugay.biz Date: 19/12/15 Time: 12:57 */
import com.sun.org.apache.xml.internal.dtm.ref.DTMNodeList;
import org.xml.sax.InputSource;
import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathExpressionException;
import javax.xml.xpath.XPathFactory;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
public class TestClass {
public static void main(String[] args) throws XPathExpressionException, FileNotFoundException {
XPath xpath = XPathFactory.newInstance().newXPath();
String expression = "/library/catalog/book";
InputSource inputSource = new InputSource();
inputSource.setCharacterStream(new FileReader(new File("/Users/koraytugay/Desktop/widgets.xml")));
Object evaluate = xpath.evaluate(expression, inputSource, XPathConstants.NODESET);
DTMNodeList dtmNodeList = (DTMNodeList) evaluate;
System.out.println(dtmNodeList.getLength());
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的 pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion> …Run Code Online (Sandbox Code Playgroud) 我正在尝试构建一个登录注册 Web 应用程序,它本质上是让用户在数据库上注册,然后允许他们登录。我已经编写了所有代码,并且正在尝试将我的程序连接到我的数据库。这是我收到的错误:
Exception
javax.servlet.ServletException: Servlet execution threw an exception
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
Root Cause
java.lang.NoClassDefFoundError: java/sql/Driver
Run Code Online (Sandbox Code Playgroud)
我已将所有 Postgres、Tomcat 和 SQL 连接器/驱动程序 jar 添加到我classpath和我的WEB-INF/lib文件夹中。我不太确定还能做什么。我尝试使用另一个类进行测试,并且能够连接到我的数据库。我还仔细检查了我的连接 URL。怎么了?
谢谢!
我正在 Laravel 中编写代码。当我尝试使用表单中的文件发布帖子时,它将引发以下异常:
收到错误'PHP消息:PHP致命错误:未捕获ErrorException:包括(/var/www/vhosts/web2/httpdocs/vendor/composer/../../app/Exceptions/Handler.php):无法打开流: /var/www/vhosts/web2/httpdocs/vendor/composer/ClassLoader.php:444\nStack trace:\n#0 中没有此类文件或目录
。。。n#5 /var/www/vhosts/web2/httpdocs/vendor/laravel/framework/src/Illuminate/Container/Container.php(803): ReflectionClass->__construct('App\...', 引用: (隐藏)
添加.blade.php:
@include('flash::message')
<form class="form-horizontal" enctype="multipart/form-data" action="{{action('SheetController@add')}}" method="post">
@csrf
<div class="form-group">
<label class="col-md-4 control-label" for="icao">ICAO</label>
<div class="form-group col-md-4">
<input placeholder="i.e. SAAC" class="form-control input-md" id="icao" name="icao" type="text" required />
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label" for="fir">FIR</label>
<div class="col-md-4">
<select id="fir" name="fir" class="form-control input-md" required>
<option value="SAEF">Ezeiza</option>
<option value="SACF">Córdoba</option>
<option value="SAMF">Mendoza</option>
<option value="SAVF">Comodoro Rivadavia</option>
<option value="SARR">Resistencia</option>
</select>
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label" for="version">Version</label>
<div class="form-group col-md-4">
<input …Run Code Online (Sandbox Code Playgroud) 为了使我的问题更清楚,请考虑以下用例:
假设有一个包允许在给定平台上进行一组操作,例如在 Windows 上编辑注册表的类。这个包在其他平台上不存在,因为在其他操作系统上没有等效的操作。
为了简单起见,考虑
窗口/Registry.java
package windows;
public class Registry {
static Registry instance = null;
static{
System.out.println("print from static block");
}
private Registry() {
System.out.println("Registry instance created!");
}
public static synchronized Registry getInstance() {
if (null == instance) {
instance = new Registry();
}
return instance;
}
public void foo() {
System.out.println("foo called.");
}
}
Run Code Online (Sandbox Code Playgroud)
以及我将有条件使用注册表的类:main/Main.java
package main;
import windows.Registry;
public class Main {
public static void test1(boolean onWindows) {
if (onWindows) {
Registry instance = Registry.getInstance();
System.out.println("We …Run Code Online (Sandbox Code Playgroud) 我有一堂有两种方法的课程。
在 中method1(),我创建了一个local record名为Abc. 这local record仅适用于method1()因为它是在(这里是根据 Java 的规则)中定义的。method1()
在 中method2(),我创建了一个local interface名为ABC. 请注意,这里存在大小写差异。该local record被命名了Abc,但这个local interface被命名了ABC。
这是班级。
//package ..... //commenting out package information, as I sincerely doubt that is the cause
/** There seems to be a class loader error when running the below method in main(). */
public class ClassLoaderIssue
{
/** Method …Run Code Online (Sandbox Code Playgroud) 在Grails中使用自定义hamcrest匹配器时遇到问题.使用我的匹配器运行测试失败:
java.lang.NoSuchMethodError: org.hamcrest.Matcher.describeMismatch(Ljava/lang/Object;Lorg/hamcrest/Description;)V
Run Code Online (Sandbox Code Playgroud)
经过一些谷歌搜索后,似乎这是由加载的库的顺序引起的:JUnit和Hamcrest.我在BuildConfig.groovy中添加了以下依赖项:
dependencies {
test 'org.hamcrest:hamcrest-all:1.3'
}
Run Code Online (Sandbox Code Playgroud)
根据我能够找到的指令,可以通过确保在JUnit之前加载hamcrest类来解决这个问题.我不知道如何在Grails中实现这一点,或者如何以任何其他方式解决这个问题.
使用Grails 2.2.1
我有一个war文件打包在耳中并部署.这是结构:
EAR
-WAR
--input.txt
--META-INF
--WEB-INF
---classes
(and so on)
Run Code Online (Sandbox Code Playgroud)
我试图从WEB-INF/classes文件夹中的一个类(比如abc.xyz.Myclass)读取input.txt.这是我尝试过的:
this.getClass().getClassLoader().getResourceAsStream("../../input.txt");
Run Code Online (Sandbox Code Playgroud)
和
Thread.currentThread().getContextClassLoader().getResourceAsStream("../../input.txt");
Run Code Online (Sandbox Code Playgroud)
我通过附加调试器尝试了几个路径,如"../input.txt"或"/input.txt"或只是"input.txt".但每次我得到NULL作为返回值(意味着它无法找到该文件).
在战争中访问该文件的正确方法是什么,无论战争是单独部署还是包装在耳中?请帮忙.
我对OSGi中Java ClassLoader的用法有疑问.
我写了两个OSGi包,即服务器包和客户端包.
在服务器包中,我实现了BundleActivator,如:
public class Activator implements BundleActivator {
public void start(BundleContext context) {
System.out.println("[Server:Activator.java:26] " + Activator.class.getClassLoader());
context.registerService(HelloService.class, new HelloService(), null);
}
public void stop(BundleContext context) {
System.out.println("Stopping the bundle");
}
}
Run Code Online (Sandbox Code Playgroud)
在客户端捆绑中,我实现了BundleActivator,如:
public class Activator implements BundleActivator {
public void start(BundleContext context) {
ServiceReference<HelloService> ref = context.getServiceReference(HelloService.class);
HelloService service = context.getService(ref);
System.out.println("[Client:Activator.java:48] " + HelloService.class.getClassLoader());
System.out.println("[Client:Activator.java:49] " + Activator.class.getClassLoader());
}
public void stop(BundleContext context) {
System.out.println("Stopping the bundle");
}
}
Run Code Online (Sandbox Code Playgroud)
当我启动OSGi时,控制台输出:
[服务器:Activator.java:26] org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader@56b161a [osgi-server:1.0.0(id = 54)] [客户端:Activator.java:48] …
classloader ×10
java ×8
classpath ×1
exception ×1
fonts ×1
grails ×1
hamcrest ×1
handler ×1
identifier ×1
jdbc ×1
junit ×1
karaf ×1
laravel ×1
load ×1
local-class ×1
matcher ×1
maven ×1
osgi ×1
osgi-bundle ×1
php ×1
postgresql ×1
slf4j ×1
swing ×1
war ×1
xpath ×1