任务:
给定一个m
包含整个非负数的二维数组,我们将"路径"定义为相邻单元的集合(对角线步骤不算作邻居)从开始到row == 0 && col == 0
结束row == m.length - 1 && col == m[0].length - 1
.
"路径" 的成本是"路径"的每个单元中的值的总和.
例:
数组中的两个可能路径:
路径1(虚线)的成本:8 + 4 + 2 + 8 + 9 + 9 + 7 + 5 = 52;
路径2的成本(实线):8 + 6 + 3 + 8 + 9 + 4 + 1 + 2 + 1 + 7 + 6 + 5 = 60
去做: …
我得到SpringBootServletInitializer cannot be resolved to a type
据我理解,这是一个依赖问题。
虽然我很喜欢编写Java代码,但这是我的第一个应用程序使用maven
,spring-boot
自然我一无所知。
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>
<artifactId>univers-web</artifactId>
<packaging>war</packaging>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.3.6.RELEASE</version>
</parent>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
</dependency>
<dependency>
<groupId>com.vaadin</groupId>
<artifactId>vaadin-spring-boot-starter</artifactId>
<version>2.0.1</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<executable>true</executable>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
</plugins>
</build>
</project>
Run Code Online (Sandbox Code Playgroud)
SpringBootApplication.java:
package com.thebyteguru.launcher;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.context.web.SpringBootServletInitializer;
public …
Run Code Online (Sandbox Code Playgroud) 以下代码呈现JButton
无文本:
public abstract class Test {
public static void main(String... args) {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException e) {
e.printStackTrace();
}
SwingUtilities.invokeLater(() -> {
JFrame frame = new JFrame();
JPanel panel = new JPanel();
String text = "Invisible";
JButton button = new JButton(text); // blank button rendered ???
System.out.println(button.getText()); // prints Invisible
button.setAction(new AbstractAction() {
@Override
public void actionPerformed(ActionEvent arg0) {
// do nothing
}
});
System.out.println(button.getText()); // prints null ??? …
Run Code Online (Sandbox Code Playgroud) 如何使用 Python 模块的路径仅导入特定类?
我需要使用文件路径从 Python 文件导入特定的类。我无法控制该文件,它完全在我的包之外。
文件.py:
class Wanted(metaclass=MyMeta):
...
class Unwanted(metaclass=MyMeta):
...
Run Code Online (Sandbox Code Playgroud)
元类实现与这里无关。不过,我要指出的是,它是我的包的一部分,我可以完全控制它。
导入示例:
spec = importlib.util.spec_from_file_location(name='Wanted', location="path_to_module/mudule.py")
module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(module)
Run Code Online (Sandbox Code Playgroud)
这有效,并且Wanted
被导入。问题是这Unwanted
也是进口的。事实上,只要给定任何name
字符串值(包括空字符串),Wanted
和Unwanted
都会从模块中导入。
这与之前的示例具有相同的效果,其中Wanted
和Unwanted
均被导入:
importlib.util.spec_from_file_location(name='random string', location="path_to_module/mudule.py")
Run Code Online (Sandbox Code Playgroud)
我不是在寻找使用 ; 的特定解决importlib
方案 任何合理的方式都可以。我将指出,在导入该类时,我不需要使用该类,我只需要进行导入,我的元类将处理其余的事情。
我正在编写一个简单的游戏并尝试播放声音,但是当我创建它抛出的Media对象时,我无法让它工作IllegalArgumentException
.我不是一个Java编码器,任何帮助将不胜感激.这是一个示例代码:
import javafx.scene.media.Media;
import javafx.scene.media.MediaPlayer;
public class Main{
public static void main(String[] args) {
Media pick = new Media("put.mp3"); //throws here
MediaPlayer player = new MediaPlayer(pick);
player.play();
}
}
Run Code Online (Sandbox Code Playgroud)
显然"put.mp3"存在并位于正确的目录中,我使用以下方法检查路径: System.out.println(System.getProperty("user.dir"));
我在这做错了什么?
如何填充感兴趣的网格单元中可用的垂直和水平空间?
例如:
JTextArea file1 = new JTextArea();
file1.setBorder(BorderFactory.createLineBorder(Color.black));
c = new GridBagConstraints();
c.gridx = 0;
c.gridy = 1;
c.weightx = 1.0 / ELEMENTS_IN_WIDTH;
c.weighty = 0.9;
c.insets = new Insets(PAD, PAD, PAD, PAD);
c.fill = GridBagConstraints.VERTICAL;
mainPanel.add(file1, c);
Run Code Online (Sandbox Code Playgroud)
这会垂直填充单元格,但不会水平填充单元格。
c.fill = GridBagConstraints.HORIZONTAL
显然在该值后面添加VERTICAL
只会覆盖该值c.fill
OR
喜欢它们c.fill = GridBagConstraints.HORIZONTAL | GridBagConstraints.VERTICAL
也没有效果。