ioexception

Getting unhandled IOException on globally defined variable - JAVA

我们两清 提交于 2020-01-17 15:24:12
问题 How can one stop the IOException question being raised on something as such: public class ExampleClass { String path = "path to directory"; Path filePath = Paths.get(path); BasicFileAttributes Attr = Files.readAttributes(filePath, BasicFileAttributes.class); ... } I receive a warning from IntelliJ stating Unhandled exception: java.io.IOException on the last line BasicFileAttributes inAttr = Files.readAttributes(filePathIn, BasicFileAttributes.class); If I put these declarations within a

File.createNewFile() method throws exception in Android M

谁说胖子不能爱 提交于 2020-01-17 04:46:05
问题 I have a problem to create file in Android M. I use Nexus 9 with Android 6.0.1 . Then I set in my project as below: AndroidManifest.xml <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> build.gradle android { defaultConfig { targetSdkVersion 23 ... } } MainActivity.Java public class MainActivity extends AppCompatActivity { super.onCreate(savedInstanceState); setContentView(R.layout.activity

Closing Reader/Stream in Java [duplicate]

笑着哭i 提交于 2020-01-17 04:32:09
问题 This question already has an answer here : How can I fix an “IOException: Stream closed” exception using System.in? (1 answer) Closed 4 years ago . In my code I have to read user input from console: class Demo { //...some code public String readUserInput() throws IOException { BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); String userInput = reader.readLine(); reader.close(); return userInput; } } On first time when I use method readUserInput() on Demo object

How to put `throws IOException` to the statement

丶灬走出姿态 提交于 2020-01-16 08:05:17
问题 I am trying to implement a class from HighestScoreFile.java and when I compile, I get this error : ...MemoryGame.java:211: error: unreported exception IOException; must be caught or declared to be thrown HighestScoreFile.HighestScoreFile(input, hours, minutes, seconds, click); ^ 1 error Before I implement this HighestScoreFile.java , I have tested with a main class using public static void main(String[] args) throws IOException { HighestScoreFile("abcdefg", 12, 13, 14, 30); } The

How to put `throws IOException` to the statement

牧云@^-^@ 提交于 2020-01-16 08:04:38
问题 I am trying to implement a class from HighestScoreFile.java and when I compile, I get this error : ...MemoryGame.java:211: error: unreported exception IOException; must be caught or declared to be thrown HighestScoreFile.HighestScoreFile(input, hours, minutes, seconds, click); ^ 1 error Before I implement this HighestScoreFile.java , I have tested with a main class using public static void main(String[] args) throws IOException { HighestScoreFile("abcdefg", 12, 13, 14, 30); } The

Do I have to include catch blocks in Java when calling a method that throws exceptions?

為{幸葍}努か 提交于 2020-01-15 11:49:07
问题 i create an android application. and typed some codes just like : public void onCreate(Bundle savedInstanceState) { ... XmlResourceParser xrp = getResources().getXml(R.xml.OneXml); <==OneXml is a custom xml file in folder res/xml ... try { .... xrp.next(); .... } catch(IOException e) { e.printStackTrace(); } catch(XmlPullParserException e) { e.printStackTrace(); } ... i found that i can neither delete catch(IOException e) nor catch(XmlPullParserException e) , when i try to delete one of them,

Reading input using Scanner causes an infinite loop in Java [duplicate]

假装没事ソ 提交于 2020-01-11 12:48:32
问题 This question already has answers here : How to handle infinite loop caused by invalid input (InputMismatchException) using Scanner (5 answers) Closed 2 years ago . In my program I'm trying to get a user to input an int between 1-3 and then do something based off what they type. If it is not a number or not one of the options then it will allow them to reenter a valid option. The issue I have is I'm having trouble brainstorming how to not have it infinitely loop and just allow them to enter

Android: IOException: Permission denied

我只是一个虾纸丫 提交于 2020-01-04 06:31:30
问题 I'm creating/saving file on SD card. This is the code: File sdDir = Environment.getExternalStorageDirectory(); public void btnsave_clicked(View v) throws FileNotFoundException, IOException{ File f; f=new File(sdDir, "deposit.dma"); if(!f.exists()) f.createNewFile(); ... } But when I click the button, it throws "Permission denied". Don't ask me for add uses-permission. <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> I've already added this in Manifest. What should I

Deleting a window's background image WPF

半腔热情 提交于 2020-01-02 08:39:10
问题 I'm having a problem in WPF where a window doesn't release it's file-lock on the background image file after closing, before another part of the application tries to write to the image. So as an example; say I have a WPF app consisting of 3 windows, 1 "menu" selection window and 2 others. Both of the windows create an ImageBrush using a BitmapImage as the ImageSource (the same image). Window A has a button that when pressed, cycles through the available background images by copying them each

Pairing two Android devices to a third device using Bluetooth

99封情书 提交于 2020-01-02 04:58:08
问题 I am doing an Android application where I need 2 devices or more to be able to connect to one device via Bluetooth. The code to connect two devices together in a peer-to-peer form works, but when I try to connect another I get an IOException saying "Connection refused" because the Socket is closed and as such, is unable to complete pairing. The error is shown below. Socket closed. Unable to complete pairing. java.io.IOException: Connection refused at android.bluetooth.BluetoothSocket