Tag: 例外

尝试填充float数组时出现ArrayStoreException

为什么以下代码引发exception,它是什么意思? float[][] foo_array = new float[WIDTH][HEIGHT]; //Assume WDITH and Height are defined java.util.Arrays.fill(foo_array, Float.POSITIVE_INFINITY); 正如您所看到的,我只是尝试在无穷大处初始化float数组,但这会导致以下exception: Exception in thread “LWJGL Application” com.badlogic.gdx.utils.GdxRuntimeException: java.lang.ArrayStoreException: java.lang.Float at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:113) Caused by: java.lang.ArrayStoreException: java.lang.Float at java.util.Arrays.fill(Arrays.java:2170) 当然我可以遍历整个数组并将每个值设置为无穷大,我知道这就是fill方法所做的事情(它还有什么用呢)。 但我只是好奇为什么这不起作用,这是什么例外。 编辑:我省略了大部分exception消息,因为我不想这么长时间,并没有提供任何相关信息。

Java FXexception(媒体播放器应用程序)

我刚刚开始使用Java FX而且在我的生活中无法弄清楚为什么这个exception不断发生。 我有2节课。 一个叫做Main,另一个叫做Player。 这是他们每个人的样子…. 主类 package application; import javafx.application.Application; import javafx.stage.Stage; import javafx.scene.Scene; import javafx.scene.layout.BorderPane; import javafx.scene.paint.Color; public class Main extends Application { @Override public void start(Stage primaryStage) { Player player = new Player(“/Applications/Nacho.mp4”); Scene scene = new Scene (player, 720, 480, Color.BLACK); primaryStage.setScene(scene); primaryStage.show(); } public static void main(String[] args) { launch(args); } […]

未报告的exceptionjava

我得到一个未报告的例外; 必须在下面的填充方法中捕获或声明抛出错误。 从我读过的类似post我假设错误起源,因为read方法抛出Exception但我无法修复它。 public void read(int fileName) throws Exception { FileInputStream in = null; try { Scanner in = new Scanner(“dataset.txt”); File inFile = new File(in.nextLine()); in = new FileInputStream(inFile); } catch ( Exception e) { System.out.println(e); } BufferedReader buf = new BufferedReader(new InputStreamReader(in) ); String input; input = buf.readLine(); fill(input,buf); } 其中fill定义为: public void […]

Android Hello World Exception

我想让这个hello world android应用程序正常工作。 我将完成这个安装过程,并了解使用“Hello World”应用程序启动和运行是多么容易。 我运行简单的hello world应用程序(完全按照它说的每一步)和POOF ……没有。 我收到错误java.lang.IllegalArgumentException:错误版本:独立于com.android.sdkstats.sdkStatsService.normalizeVersion(sdkStatsService.java:467) 知道如何解决这个问题吗? 我已经仔细检查了我的命名空间(所有3个)并且还使用XML编辑器尝试了这个…

未知主机exception

try { { long startTime = System.currentTimeMillis(); String source=”s”; String source1=”s”; URL google = new URL(“http://google.com/”); HttpURLConnection yc =(HttpURLConnection)google.openConnection(); BufferedReader in = new BufferedReader(new InputStreamReader(yc.getInputStream())); String inputLine; while ((inputLine = in.readLine()) != null) { source=source.concat(inputLine); } in.close(); yc.disconnect(); } long endTime1 = System.currentTimeMillis(); System.out.println(“Total elapsed time in execution of method callMethod() is :”+ (endTime1-startTime)); } […]

Android:尝试HttpURLConnection.getOutputStream()时抛出SocketException

这是我的第一个android程序,它是一个修改过的hello世界。 我在MAC上的模拟器上运行它。 我尝试与.NET Web服务进行通信,但它在connection.getOutputStream()给出了exception。 我可以从模拟器访问该站点。 任何帮助表示赞赏:) URL url = new URL(“http://192.168.3.47/service.asmx”); HttpURLConnection connection = (HttpURLConnection)url.openConnection(); connection.setRequestMethod(“POST”); connection.setRequestProperty(“Content-Type”, “application/soap+xml; charset=utf-8”); connection.setUseCaches(false); connection.setDoInput(true); connection.setDoOutput(true); String soapRequest = String.format(getText(R.string.ws_listemain_ds_new).toString(), city, keyword); connection.setRequestProperty(“Content-Length”, Integer.toString(soapRequest.getBytes(“UTF-8”).length)); //Send request OutputStreamWriter owr = new OutputStreamWriter(connection.getOutputStream(), “UTF-8”); 03-02 15:51:26.950: WARN/System.err(618): java.net.SocketException: Permission denied 03-02 15:51:26.978: WARN/System.err(618): at org.apache.harmony.luni.platform.OSNetworkSystem.socket(Native Method) 03-02 15:51:26.988: WARN/System.err(618): at dalvik.system.BlockGuard$WrappedNetworkSystem.socket(BlockGuard.java:335) […]

Java并发修改exception

我编写了以下代码,导致并发修改exception。 我该怎样预防呢? 我们的想法是逃避Map的所有值,并使用新的param map重新构建对象(dO)。 try { Map paramMap = dO.getParameterMap(); Set<Map.Entry> entries = paramMap.entrySet(); Iterator<Map.Entry> it = entries.iterator(); while (it.hasNext()) { Map.Entry entry = it.next(); String[] values = entry.getValue(); List valList = new ArrayList(); if (values != null) { for (String value : values) { valList.add(escapeHTML(value)); } dO.removeParameter(entry.getKey()); //请注意参数是一个hashMap所以,是否需要在插入之前先删除该条目,否则它将替换与key关联的新值。 它在Java中如何工作? dO.addParameter(entry.getKey(),valList.toArray(new String[valList.size()])); } } }

在java中为什么自定义exception也应该有一个构造函数,其中arg为’Throwable cause’

任何人都可以在定义自定义exception时解释为什么我们应该有如下的构造函数: public MyException(Throwable cause) { super(cause); } public MyException(String message, Throwable cause) { super(message, cause); }

Javaexceptiontry-catchexception与IOException

即使try块实际上没有抛出任何exception,下面的代码也可以编译好。 public static void main(String[] args) { try {} catch (Exception e) {} // compiles ok } 但是如果使用Exception的子类替换catch,则代码将无法编译。 public static void main(String[] args) { try {} catch (IOException e) {} // won’t compile. } 编译器错误是:IOException的无法访问的catch块。 永远不会从try语句主体抛出此exception。 当Exception和IOException都被检查exception时,为什么会出现这种情况? 我正在使用Java 7。

导致exception中的递归原因的原因是什么?

在调试器中查看Java中的exception时,您经常会看到原因是无限递归(我认为它是无限的)。 例如: Exception1, Caused by -> Exception2 Caused by -> Exception2 Caused by -> Exception2 为什么是这样? 注意:这是在查看调试器中的代码时,在这种情况下是Eclipse。