runtimeexception

Reading text file and skipping blank lines until EOF is reached

自作多情 提交于 2019-12-06 13:51:02
I am trying to read csv file full of text; however if there is a blank line in the middle somewhere, the whole thing breaks and I get a: java.lang.RuntimeException: java.lang.StringIndexOutOfBoundsException How would I go about removing/ignoring blank lines as long as it's not the end of the file? file = new FileReader(fileName); @SuppressWarnings("resource") BufferedReader reader = new BufferedReader(file); while ((line = reader.readLine()) != null) { //do lots of stuff to sort the data into lists etc } } catch (Exception e) { System.out.println("INPUT DATA WAS NOT FOUND, PLEASE PLACE FILE

Catch RuntimeExceptions in Java application and send them via email

假装没事ソ 提交于 2019-12-06 09:23:27
问题 I'm starting my app on Linux server with a command like this /usr/local/bin/jsvc \ -home /usr/local/jdk1.8.0_111 \ -cp /opt/myapp/myapp.jar:/opt/myapp/lib/* \ -user myappuser \ -outfile /opt/myapp/out.log \ -errfile /opt/myapp/error.log \ -pidfile /opt/myapp/myapp.pid \ com.example.MyApp I'm using log4j for logging in my app and it has own configuration described in log4j.properties which is located inside myapp.jar . I want to be able to catch any exception which happens in the app and to

MediaRecorder throw “java.lang.RuntimeException: start failed: -2147483648” when trying to record audio on LG G Watch

让人想犯罪 __ 提交于 2019-12-06 06:06:46
I am trying to record audio in my app on a LG G Watch. The following code throws RuntimeException with message "start failed: -2147483648" at the statement "recorder.start();". Wondering what I'm doing wrong here. I have tried a lot of different set of parameters, for example for AudioSource: recorder.setAudioSource(MediaRecorder.AudioSource.DEFAULT); //-and- recorder.setAudioSource(MediaRecorder.AudioSource.MIC); Also for OutputFormat I have tried recorder.setOutputFormat(MediaRecorder.OutputFormat.DEFAULT); //-and- recorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4); //-and- recorder

Design issue: to what extent should I rely on exceptions for the flow of control?

核能气质少年 提交于 2019-12-06 04:56:57
I am working on a java web application and I have a few questions regarding design. Basically in its current version, it relies heavily on catching exceptions to determine the flow of control . For instance in one of my spring service classes, I have the following method that checks whether an email given as a parameter exists in the database. @Override public boolean validateEmailAddressDoesNotExist(String accountEmailAddress) { try { return !dao.checkIfEmailAddressAlreadyExists(accountEmailAddress); } catch (NoResultException re) { log.error("NoResultException", re); } catch

class extends ListActivity “whose id attribute is 'android.R.id.list'”

南笙酒味 提交于 2019-12-06 04:30:32
I'm trying to extend my main Activity to "ListActivity" (previously extends to: Activity) to use onListItemClick, but the logcat, send me "Your content must-have a ListView whose id attribute is 'android.r.id.list'". (i'm using SQLite for populate the ListView). mi xml is: <ListView android:id="@+id/list" // to "@id/android:list" or other styles (but nothing works) android:layout_width="fill_parent" android:layout_height="fill_parent"/> // or closing with </ListView> this is the complete xml for the ListView: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas

Why is the ArrayStoreException a RuntimeException?

佐手、 提交于 2019-12-06 01:08:30
Let's say we have the following program: class Fruit {} class Apple extends Fruit {} class Jonathan extends Apple {} class Orange extends Fruit {} public class Main { public static void main(String[] args) { Fruit[] fruit = new Apple[10]; try { fruit[0] = new Fruit(); // ArrayStoreException fruit[0] = new Orange(); // ArrayStoreException } catch(Exception e) { System.out.println(e); } } } Based on the Java documentation : Thrown to indicate that an attempt has been made to store the wrong type of object into an array of objects. I've read here that When array is created it remembers what type

takePicture RuntimeException Android

耗尽温柔 提交于 2019-12-05 19:24:46
I've developed an app which has got a service taking snapshots in the background. Whilst this app runs okay in all the devices I've tried so far (not Motorola ones), I found that running it on a Bionic Droid, crashes. Basically, what I'm doing is: camera = Camera.open(); camera.setParameters(parameters); camera.setPreviewDisplay(null); camera.startPreview(); camera.takePicture(null,null,callback); This sequence works with no issues on different HTC and Samsung devices running from Android 2.2 to Android 2.3.4 The Bionic is running 2.3.4 and the takePicture method throws a RuntimeException at

Camera java.lang.RuntimeException: setParameters failed

牧云@^-^@ 提交于 2019-12-05 15:00:06
问题 I have created a custom camera app using this source code, but on few devices (like on High Resolution Devices) I am getting: RuntimeException setParameters failed I am facing this exception, due to this: params.setPictureSize(1200, 900); And I have noticed, If I use (1600, 1200) instead of (1200, 900) then I am not facing such issues Logcat: 11-07 11:45:20.630: E/AndroidRuntime(3827): FATAL EXCEPTION: main 11-07 11:45:20.630: E/AndroidRuntime(3827): java.lang.RuntimeException: Unable to

Throw RuntimeException inside Stream with Optional.orElseThrow

喜夏-厌秋 提交于 2019-12-05 12:57:24
问题 The following code works fine: Stream.of("key1", "key2") .map(key -> { SomeObject foo = service.find(key); if (foo == null) { throw new RuntimeException("No entity found with key: " + key); } return foo; }) // ... However, when I use orElseThrow from Optional: Stream.of("key1", "key2") .map(key -> Optional.ofNullable(someService.find(key)) .orElseThrow(() -> new RuntimeException("No entity found with key: " + key))) // ... I get a compile time error: Error:(129, 33) java: unreported exception

Android Tab Action Bar

会有一股神秘感。 提交于 2019-12-05 06:20:40
I am trying out on the android action bar for 3.0, where I refer to http://www.youtube.com/watch?v=gMu8XhxUBl8 The code in the TabsActivity are as follow: package com.test.actionbar; import android.app.ActionBar; import android.app.ActionBar.Tab; import android.app.Activity; import android.app.Fragment; import android.app.FragmentTransaction; import android.os.Bundle; public class TabsActivity extends Activity{ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); ActionBar bar = getActionBar(); bar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);