Questions tagged «java»

Java是一种流行的高级编程语言。如果您在使用或理解语言本身时遇到问题,请使用此标签。这个标签很少单独使用,最常与[spring],[spring-boot],[jakarta-ee],[android],[javafx],[gradle]和[maven]结合使用。

13
如何使用OKHTTP发出发布请求?
我读了一些将jsons发布到服务器的示例。 有人说: OkHttp是Java提供的HttpUrlConnection接口的实现。它提供用于编写​​内容的输入流,并且不知道(或不在乎)该内容是什么格式。 现在,我想用名称和密码的参数对URL进行常规发布。 这意味着我需要自己将名称和值对编码为流?
91 java  okhttp 


9
如何在Java中使用值创建日期对象
我需要一个日期对象作为日期2014-02-11。我不能像这样直接创建它, Date myDate = new Date(2014, 02, 11); 所以我在做如下 Calendar myCalendar = new GregorianCalendar(2014, 2, 11); Date myDate = myCalendar.getTime(); 有什么简单的方法可以在Java中创建日期对象?
91 java  date 

8
合并一个Observables列表,直到所有完成为止
TL; DR 如何转换Task.whenAll(List<Task>)成RxJava? 我现有的代码使用Bolts构建了一系列异步任务,并等待所有这些任务完成后再执行其他步骤。本质上,按照Bolts站点上的示例,它会构建aList<Task>并返回一个列表,当列表中的所有任务Task完成时,将其标记为已完成。 我正在寻找替换方法Bolts,RxJava并且我假设这种方法可以构建异步任务列表(大小未知)并将它们全部包装为一个Observable,但是我不知道如何做。 我试着看merge,zip,concat等...但不能去工作的List<Observable>,我会被建立,因为他们似乎都面向工作的只有两个Observables,如果我理解正确的文档在一个时间。 我正在尝试学习RxJava,但仍然很陌生,因此,如果这是一个明显的问题或在文档中的某个地方进行了说明,请原谅我;我尝试搜寻。任何帮助将非常感激。

12
Android-防止在旋转时重新加载WebView
旋转屏幕时,WebView会重新加载整个页面。我无法使用此功能,因为我的某些内容包含动态/随机材料。当前,屏幕旋转时会从loadUrl()方法重新加载原始URL。 知道我的代码有什么问题吗? MainActivity.java package com.mark.myapp; import android.app.Activity; import android.os.Bundle; import android.util.Log; import android.view.KeyEvent; import android.view.Menu; import android.webkit.WebView; import android.webkit.WebViewClient; public class MainActivity extends Activity { WebView web; String webURL = "http://www.google.co.uk/"; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); if (savedInstanceState != null) ((WebView)findViewById(R.id.web)).restoreState(savedInstanceState); web = (WebView) findViewById(R.id.web); web.getSettings().setJavaScriptEnabled(true); web.loadUrl(webURL); …


8
Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击
我使用了明确的等待,并发出警告: org.openqa.selenium.WebDriverException:元素在点(36,72)处不可单击。其他元素将获得点击:...命令持续时间或超时:393毫秒 如果我使用Thread.sleep(2000)我不会收到任何警告。 @Test(dataProvider = "menuData") public void Main(String btnMenu, String TitleResultPage, String Text) throws InterruptedException { WebDriverWait wait = new WebDriverWait(driver, 10); driver.findElement(By.id("navigationPageButton")).click(); try { wait.until(ExpectedConditions.elementToBeClickable(By.cssSelector(btnMenu))); } catch (Exception e) { System.out.println("Oh"); } driver.findElement(By.cssSelector(btnMenu)).click(); Assert.assertEquals(driver.findElement(By.cssSelector(TitleResultPage)).getText(), Text); }

14
不能让杰克逊和龙目岛一起工作
我正在尝试结合杰克逊和龙目岛。这些是我的课程: package testelombok; import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; import lombok.AllArgsConstructor; import lombok.Value; import lombok.experimental.Wither; @Value @Wither @AllArgsConstructor(onConstructor=@__(@JsonCreator)) public class TestFoo { @JsonProperty("xoom") private String x; private int z; } package testelombok; import com.fasterxml.jackson.databind.ObjectMapper; import com.xebia.jacksonlombok.JacksonLombokAnnotationIntrospector; import java.io.IOException; public class TestLombok { public static void main(String[] args) throws IOException { TestFoo tf …

13
Java:静态初始化块什么时候有用?
static块内初始化之间有什么区别: public class staticTest { static String s; static int n; static double d; static { s = "I'm static"; n = 500; d = 4000.0001; } ... 以及单独的静态初始化: public class staticTest { static String s = "I'm static"; static int n = 500; static double d = 4000.0001; ....


17
即使file.exists(),file.canRead(),file.canWrite(),file.canExecute()都返回true,file.delete()也返回false
我正在尝试使用写入文件后删除文件FileOutputStream。这是我用来编写的代码: private void writeContent(File file, String fileContent) { FileOutputStream to; try { to = new FileOutputStream(file); to.write(fileContent.getBytes()); to.flush(); to.close(); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } 如图所示,我刷新并关闭了流,但是当我尝试删除时,file.delete()返回false。 我删除前检查,看看是否该文件存在,并且:file.exists(),file.canRead(),file.canWrite(),file.canExecute()一切回归真实。在调用这些方法之后,我尝试file.delete()返回false。 我做错了什么吗?

2
使用util模式自动连接列表会产生NoSuchBeanDefinitionException
我有一个要使用Spring util名称空间注入命名列表的bean, <util:list id="myList">但是Spring正在寻找String类型的bean的集合。我坏的测试是: @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration public class ListInjectionTest { @Autowired @Qualifier("myList") private List<String> stringList; @Test public void testNotNull() { TestCase.assertNotNull("stringList not null", stringList); } } 我的上下文是: <beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:util="http://www.springframework.org/schema/util" xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.5.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd"> <util:list id="myList"> <value>foo</value> <value>bar</value> </util:list> </beans> 但是我明白了 Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching …
90 java  spring 

30
Android Studio-未找到JVM安装
我在尝试启动时遇到问题 Android Studio 当我尝试在安装后启动它时,出现此错误: No JVM Installation found. Please install a 64 bit JDK. 我当前的系统规格: 操作系统:Windows 8.0 64 bit version 已安装JDK:JDK 1.8.0 我尝试过的 我尝试了在错误中报告的内容,并且在大多数解决方案中都尝试将JDK_HOME环境变量中的变量设置为我的JDK路径(64位版本),即C:\Program Files\Java\jdk1.8.0_05 *I also have tried rebooting system, just in case to test if the environment variable is not working without a restart 我已经看过这些解决方案并尝试过,但没有一个起作用,所以不要将其标记为以下任何一个的重复: Windows 7上的Android Studio安装失败,找不到JDK …

11
如何把窗户放到前面?
我们有一个Java应用程序,当远程控制机制激活该应用程序中的某些内容时,需要将其置于前台。 为了实现这一点,我们已经在该类的被调用方法中实现了该方法,该方法表示实现后我们应用程序的框架(扩展为JFrame): setVisible(true); toFront(); 在Windows XP下,此功能在首次调用时有效,第二次仅任务栏上的选项卡闪烁时,框架不再位于最前面。Win2k也是如此。在Vista上似乎工作正常。 你有什么想法?
90 java  windows  swing  awt 

11
Spring容器中的Singleton设计模式与Singleton bean
众所周知,默认情况下,我们在Spring容器中将bean作为单例,如果我们有一个基于Spring框架的Web应用程序,那么在这种情况下,我们真的需要实现Singleton设计模式来保存全局数据,而不仅仅是通过spring创建bean 。 如果我无法解释我实际上要问的问题,请忍受。

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.