Questions tagged «java»

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

2
使用毕加索将图像调整为全宽和固定高度
我有一个垂直的LinearLayout,其中一项是ImageView使用毕加索加载的。我需要将图像的宽度增加到整个设备的宽度,并显示以固定高度(150dp)裁剪的图像的中心部分。我目前有以下代码: Picasso.with(getActivity()) .load(imageUrl) .placeholder(R.drawable.placeholder) .error(R.drawable.error) .resize(screenWidth, imageHeight) .centerInside() .into(imageView); 我应该输入screenWidth和哪些值imageHeight(= 150dp)?


10
Java的CSV API [关闭]
从目前的情况来看,这个问题不适合我们的问答形式。我们希望答案会得到事实,参考或专业知识的支持,但是这个问题可能会引起辩论,争论,民意调查或扩展讨论。如果您认为此问题可以解决并且可以重新提出,请访问帮助中心以获取指导。 7年前关闭。 任何人都可以推荐一个简单的API,该API允许我使用它读取CSV输入文件,进行一些简单的转换然后编写。 一个快速的Google发现http://flatpack.sourceforge.net/看起来很有希望。 在将自己与该API结合之前,我只是想查看其他人正在使用什么。
164 java  csv 

5
如何在特定连接上使用不同的证书?
我要添加到大型Java应用程序中的模块必须与另一家公司的SSL安全网站进行对话。问题在于该站点使用自签名证书。我有证书的副本以验证我没有遇到中间人攻击,并且我需要将此证书合并到我们的代码中,以确保成功连接到服务器。 这是基本代码: void sendRequest(String dataPacket) { String urlStr = "https://host.example.com/"; URL url = new URL(urlStr); HttpURLConnection conn = (HttpURLConnection)url.openConnection(); conn.setMethod("POST"); conn.setRequestProperty("Content-Length", data.length()); conn.setDoOutput(true); OutputStreamWriter o = new OutputStreamWriter(conn.getOutputStream()); o.write(data); o.flush(); } 如果没有对自签名证书进行任何其他处理,它将死于conn.getOutputStream(),但以下情况除外: Exception in thread "main" javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to …
164 java  ssl  keystore  truststore  jsse 

9
如何制作一个实现两种通用类型的接口的Java类?
我有一个通用的界面 public interface Consumer<E> { public void consume(E e); } 我有一个使用两种类型的对象的类,所以我想做些类似的事情: public class TwoTypesConsumer implements Consumer<Tomato>, Consumer<Apple> { public void consume(Tomato t) { ..... } public void consume(Apple a) { ...... } } 显然我做不到。 我当然可以自己执行调度,例如 public class TwoTypesConsumer implements Consumer<Object> { public void consume(Object o) { if (o instanceof Tomato) …

17
指定的孩子已经有一个父母。您必须先在孩子的父母上调用removeView()(Android)
我必须经常在两种布局之间切换。错误在下面发布的布局中发生。 第一次调用布局时,不会发生任何错误,一切都很好。然后,当我调用其他布局(空白)并随后再次调用我的布局时,它将引发以下错误: > FATAL EXCEPTION: main > java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first. 我的布局代码如下所示: tv = new TextView(getApplicationContext()); // are initialized somewhere else et = new EditText(getApplicationContext()); // in the code private void ConsoleWindow(){ runOnUiThread(new Runnable(){ @Override public void …

4
Java Collections Framework实现的Big-O摘要?[关闭]
关闭。此问题不符合堆栈溢出准则。它当前不接受答案。 想改善这个问题吗?更新问题,使其成为Stack Overflow 的主题。 3年前关闭。 改善这个问题 我可能很快就会教“ Java速成课程”。尽管可以很安全地假定听众成员将知道Big-O表示法,但是假设他们将知道各种集合实现上的各种操作的顺序可能是不安全的。 我可能会花一些时间自己生成一个摘要矩阵,但是如果它已经存在于公共领域中的某个地方,我肯定会重用它(当然要有适当的信誉)。 有人有指针吗?
164 java  collections  big-o 

10
java.lang.NoClassDefFoundError:无法初始化类XXX
public class PropHolder { public static Properties prop; static { //code for loading properties from file } } // Referencing the class somewhere else: Properties prop = PropHolder.prop; class PropHolder是我自己的一类。该类与主类位于同一JAR文件中。因此,这不应该是因为classpath中缺少任何JAR。 当我通过查找到JAR文件时jar tf myjarfile,可以看到其中PropHolder.class列出的内容。 顺便说一句:代码在我的本地计算机上运行良好。但是当我将其与某些脚本一起部署到Linux服务器上时无法工作。所以我认为这不是代码的问题。但是出于某种原因。部署过程很难跟踪。 可能是什么问题呢?

12
断言Junit中的2个列表之间等于
在JUnit测试用例中,如何在列表之间进行相等性声明?列表内容之间应该平等。 例如: List<String> numbers = Arrays.asList("one", "two", "three"); List<String> numbers2 = Arrays.asList("one", "two", "three"); List<String> numbers3 = Arrays.asList("one", "two", "four"); // numbers should be equal to numbers2 //numbers should not be equal to numbers3



6
使用Java的Collections.singletonList()吗?
Collections.singletonList()Java中有什么用?我了解它会返回一个包含一个元素的列表。我为什么要有一个单独的方法来做到这一点?不变性在这里如何发挥作用? 此方法是否有任何特殊有用的用例,而不仅仅是便捷的方法?
164 java 

8
如何在android中设置延迟?
public void onClick(View v) { // TODO Auto-generated method stub switch(v.getId()){ case R.id.rollDice: Random ranNum = new Random(); int number = ranNum.nextInt(6) + 1; diceNum.setText(""+number); sum = sum + number; for(i=0;i<8;i++){ for(j=0;j<8;j++){ int value =(Integer)buttons[i][j].getTag(); if(value==sum){ inew=i; jnew=j; buttons[inew][jnew].setBackgroundColor(Color.BLACK); //I want to insert a delay here buttons[inew][jnew].setBackgroundColor(Color.WHITE); break; } } …
164 java  android 

12
如何从其String值查找Java枚举?
我想从其字符串值(或可能的任何其他值)中查找一个枚举。我已经尝试了以下代码,但是在初始化程序中不允许使用静态代码。有没有简单的方法? public enum Verbosity { BRIEF, NORMAL, FULL; private static Map<String, Verbosity> stringMap = new HashMap<String, Verbosity>(); private Verbosity() { stringMap.put(this.toString(), this); } public static Verbosity getVerbosity(String key) { return stringMap.get(key); } };
164 java  enums  lookup 

5
关闭声纳的某些代码
是否可以针对特定的代码块关闭声纳(www.sonarsource.org)测量,而哪些是不想测量的? 一个示例是Findbugs输出的“保留堆栈跟踪”警告。当离开服务器时,如果客户端不知道该异常,我可能只想将消息传递回客户端,而不包括我刚刚捕获的实际异常(因为该客户端没有该JAR,例如包含例外)。

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.