我是第一次使用IntelliJ IDEA Community Edition并使用Maven来设置TDD环境.我试图测试的代码和我遇到的警告消息以及项目结构如下所示.
package miscellaneous;
import org.junit.Test;
import static org.junit.Assert.*;
public class TestHello {
// Methods to be tested.....
private int Add1Plus1(int i, int j) {
return (i + j);
}
@Test
public void testAdd1Plus1() throws Exception {
assertEquals(2, Add1Plus1(1, 1));
}
}
Run Code Online (Sandbox Code Playgroud)
Warning:java: source value 1.5 is obsolete and will be removed in a future release
Warning:java: target value 1.5 is obsolete …
Run Code Online (Sandbox Code Playgroud) 我使用 Java 8的功能还是滥用它?
请参阅下面的代码和说明,了解为什么选择它是这样的.
public interface Drawable {
public void compileProgram();
public Program getProgram();
default public boolean isTessellated() {
return false;
}
default public boolean isInstanced() {
return false;
}
default public int getInstancesCount() {
return 0;
}
public int getDataSize();
public FloatBuffer putData(final FloatBuffer dataBuffer);
public int getDataMode();
public boolean isShadowReceiver();
public boolean isShadowCaster(); //TODO use for AABB calculations
default public void drawDepthPass(final int offset, final Program depthNormalProgram, final Program depthTessellationProgram) {
Program depthProgram = (isTessellated()) …
Run Code Online (Sandbox Code Playgroud) 我在使用时遇到了一些问题
git clone
.这些文件是在我当地的git文件夹中下载的.运行命令
git checkout -f HEAD
给我-
'无法写入由于缺少磁盘空间而导致的新索引文件错误'.
我手动从我的计算机中删除了大文件,但仍然收到相同的错误.
Cloning into 'ffmpeg'...
remote: Counting objects: 7890, done.
remote: Compressing objects: 100% (4412/4412), done.
Receiving objects: 100% (7890/7890), 299.75 MiB | 24.19 MiB/s, done.
remote: Total 7890 (delta 3346), reused 7846 (delta 3317)
Resolving deltas: 100% (3346/3346), done.
Checking out files: 100% (7019/7019), done.
fatal: unable to write new index file
warning: Clone succeeded, but checkout failed.
You can inspect what was checked out with 'git status'
and …
Run Code Online (Sandbox Code Playgroud) 如何在thymeleaf中包含一个JavaScript变量来检查病情?
<div th:if="${myVariable == 5}">
//some code
</div>
Run Code Online (Sandbox Code Playgroud)
但它不起作用.
如何解决此错误:
[WARNING] Error injecting: com.google.appengine.devappserver.DevAppServerRunner
java.lang.NoClassDefFoundError: Lorg/sonatype/aether/RepositorySystem;
at java.lang.Class.getDeclaredFields0(Native Method)
at java.lang.Class.privateGetDeclaredFields(Class.java:2397)
at java.lang.Class.getDeclaredFields(Class.java:1806)
at com.google.inject.spi.InjectionPoint.getInjectionPoints(InjectionPoint.java:661)
at com.google.inject.spi.InjectionPoint.forInstanceMethodsAndFields(InjectionPoint.java:366)
at com.google.inject.internal.ConstructorBindingImpl.getInternalDependencies(ConstructorBindingImpl.java:165)
at com.google.inject.internal.InjectorImpl.getInternalDependencies(InjectorImpl.java:609)
at com.google.inject.internal.InjectorImpl.cleanup(InjectorImpl.java:565)
at com.google.inject.internal.InjectorImpl.initializeJitBinding(InjectorImpl.java:551)
at com.google.inject.internal.InjectorImpl.createJustInTimeBinding(InjectorImpl.java:865)
at com.google.inject.internal.InjectorImpl.createJustInTimeBindingRecursive(InjectorImpl.java:790)
at com.google.inject.internal.InjectorImpl.getJustInTimeBinding(InjectorImpl.java:278)
at com.google.inject.internal.InjectorImpl.getBindingOrThrow(InjectorImpl.java:210)
at com.google.inject.internal.InjectorImpl.getProviderOrThrow(InjectorImpl.java:986)
at com.google.inject.internal.InjectorImpl.getProvider(InjectorImpl.java:1019)
at com.google.inject.internal.InjectorImpl.getProvider(InjectorImpl.java:982)
at com.google.inject.internal.InjectorImpl.getInstance(InjectorImpl.java:1032)
at org.eclipse.sisu.space.AbstractDeferredClass.get(AbstractDeferredClass.java:48)
at com.google.inject.internal.ProviderInternalFactory.provision(ProviderInternalFactory.java:86)
at com.google.inject.internal.InternalFactoryToInitializableAdapter.provision(InternalFactoryToInitializableAdapter.java:55)
at com.google.inject.internal.ProviderInternalFactory$1.call(ProviderInternalFactory.java:70)
at com.google.inject.internal.ProvisionListenerStackCallback$Provision.provision(ProvisionListenerStackCallback.java:100)
at org.eclipse.sisu.plexus.PlexusLifecycleManager.onProvision(PlexusLifecycleManager.java:133)
at com.google.inject.internal.ProvisionListenerStackCallback$Provision.provision(ProvisionListenerStackCallback.java:109)
at com.google.inject.internal.ProvisionListenerStackCallback.provision(ProvisionListenerStackCallback.java:55)
at com.google.inject.internal.ProviderInternalFactory.circularGet(ProviderInternalFactory.java:68)
at com.google.inject.internal.InternalFactoryToInitializableAdapter.get(InternalFactoryToInitializableAdapter.java:47)
at com.google.inject.internal.InjectorImpl$2$1.call(InjectorImpl.java:997)
at com.google.inject.internal.InjectorImpl.callInContext(InjectorImpl.java:1047)
at com.google.inject.internal.InjectorImpl$2.get(InjectorImpl.java:993)
at com.google.inject.Scopes$1$1.get(Scopes.java:59)
at org.eclipse.sisu.inject.LazyBeanEntry.getValue(LazyBeanEntry.java:82)
at org.eclipse.sisu.plexus.LazyPlexusBean.getValue(LazyPlexusBean.java:51)
at org.codehaus.plexus.DefaultPlexusContainer.lookup(DefaultPlexusContainer.java:260)
at org.codehaus.plexus.DefaultPlexusContainer.lookup(DefaultPlexusContainer.java:252)
at org.apache.maven.plugin.internal.DefaultMavenPluginManager.getConfiguredMojo(DefaultMavenPluginManager.java:459) …
Run Code Online (Sandbox Code Playgroud) 考虑下面的抽象类MeasurementType
及其亚型Acceleration
和Density
:
public abstract class MeasurementType {
protected String name;
protected String[] units;
public MeasurementType() {}
public MeasurementType(String name) {
this.name = name;
}
protected void setName(String name) {
this.name = name;
}
protected String getName() {
return name;
}
protected void setUnits(String[] values) {
this.units = values;
}
}
public class Acceleration extends MeasurementType {
private String name;
public Acceleration () {
super();
}
public Acceleration(String name) {
super();
}
}
public class …
Run Code Online (Sandbox Code Playgroud) import java.io.*;
import java.util.Scanner;
public class Driver {
private int colorStrength;
private String color;
public static void main(String[] args) throws IOException {
String line, file = "strength.txt";
File openFile = new File(file);
Scanner inFile = new Scanner(openFile);
while (inFile.hasNext()) {
line = inFile.nextLine();
System.out.println(line);
}
inFile.close();
}
}
Run Code Online (Sandbox Code Playgroud)
这是我为一个类编写的程序的一小部分(我知道这两个私有属性尚未使用)但是当我尝试使用strength.txt文件运行它时,我收到以下错误:
Exception in thread "main" java.io.FileNotFoundException: strength.txt (The system cannot find the file specified)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(Unknown Source)
at java.util.Scanner.<init>(Unknown Source)
at Driver.main(Driver.java:14)
Run Code Online (Sandbox Code Playgroud)
如果有人用Eclipse可以帮我解决这个问题,我将不胜感激!
当我尝试implements
使用Intellij(社区版)创建一个包时,我得到了消息Not a valid package name
.这是因为使用了关键字吗?
出于调试目的,我试图Predicate
在Java 8中创建lambda表达式的字符串表示(特别是s,尽管对其他lambda表达式也很有趣).我的想法是这样的:
public class Whatever {
private static <T> String predicateToString(Predicate<T> predicate) {
String representation = ... // do magic
return representation;
}
public static void main(String[] args) {
System.out.println(Whatever.<Integer>predicateToString(i -> i % 2 == 0));
}
}
Run Code Online (Sandbox Code Playgroud)
输出将是i -> i % 2 == 0
(或逻辑等价的东西).这个toString()
方法似乎没有任何帮助,输出就是这样的com.something.Whatever$$Lambda$1/1919892312@5e91993f
(我想这是预期的,因为toString()
它没有被覆盖).
我不确定这样的事情是否可能,例如反射,到目前为止我当然无法找到任何东西.有任何想法吗?
我正在尝试将文本文件上传到我的Google云端硬盘帐户.无论如何,我总是遇到一个com.google.api.client.googleapis.json.GoogleJsonResponseException: 403 Forbidden
Exception in thread "main" com.google.api.client.googleapis.json.GoogleJsonResponseException: 403 Forbidden
{
"code" : 403,
"errors" : [ {
"domain" : "global",
"message" : "Forbidden",
"reason" : "forbidden"
} ],
"message" : "Forbidden"
}
at com.google.api.client.googleapis.json.GoogleJsonResponseException.from(GoogleJsonResponseException.java:145)
at com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest.newExceptionOnError(AbstractGoogleJsonClientRequest.java:113)
at com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest.newExceptionOnError(AbstractGoogleJsonClientRequest.java:40)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:423)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:343)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.execute(AbstractGoogleClientRequest.java:460)
at chatterjee.sandeep.javabase.miscellaneous.DriveCommandLine.main(DriveCommandLine.java:69)
Run Code Online (Sandbox Code Playgroud)
这是第69行 DriveCommandLine.java
File file = service.files().insert(body, mediaContent).execute();
Run Code Online (Sandbox Code Playgroud)
import com.google.api.client.googleapis.auth.oauth2.GoogleAuthorizationCodeFlow;
import com.google.api.client.googleapis.auth.oauth2.GoogleCredential;
import com.google.api.client.googleapis.auth.oauth2.GoogleTokenResponse;
import com.google.api.client.http.FileContent;
import com.google.api.client.http.HttpTransport;
import com.google.api.client.http.javanet.NetHttpTransport;
import com.google.api.client.json.JsonFactory;
import com.google.api.client.json.jackson2.JacksonFactory;
import com.google.api.services.drive.Drive;
import com.google.api.services.drive.DriveScopes;
import com.google.api.services.drive.model.File;
import …
Run Code Online (Sandbox Code Playgroud)