illegalargumentexception

IllegalArgumentException: File contains a path separator Android

拟墨画扇 提交于 2019-11-30 22:28:40
I'm trying to write to an output file on my HTC One and get the following message in the LogCat: 11-21 08:05:18.228: W/System.err(6609): java.lang.IllegalArgumentException: File /storage/emulated/0/com.example.pattern1/myfile.txt contains a path separator The source code is given below: protected void writeToFile(String string){ File patternDirectory = new File(Environment.getExternalStorageDirectory().getAbsolutePath().toString()+"/com.example.pattern1/myfile.txt"); patternDirectory.mkdirs(); FileOutputStream outputStream; try { outputStream = openFileOutput(patternDirectory.getAbsolutePath()

IllegalArgumentException: File contains a path separator Android

末鹿安然 提交于 2019-11-30 17:23:26
问题 I'm trying to write to an output file on my HTC One and get the following message in the LogCat: 11-21 08:05:18.228: W/System.err(6609): java.lang.IllegalArgumentException: File /storage/emulated/0/com.example.pattern1/myfile.txt contains a path separator The source code is given below: protected void writeToFile(String string){ File patternDirectory = new File(Environment.getExternalStorageDirectory().getAbsolutePath().toString()+"/com.example.pattern1/myfile.txt"); patternDirectory.mkdirs()

How to properly use reflection to access hidden methods in Telephony Manager

安稳与你 提交于 2019-11-30 16:28:21
I'm not sure if I'm having trouble with Reflection itself, or the method I'm trying to obtain. What I'd like to do is call the function setLine1Number from the class: com.android.internal.telephony.gsm.GSMPhone So that I can have my number properly inserted into my phone as it is not required to be in my SIM. Therefore I want to be able to call the function getLine1Number and have it return the same number that I set. Reflection appears the only way to be able to use this function as it is not in the public API. I've written this, but keep getting an illegal argument exception. Here is my code

Null check error message as “is null” or “was null”

走远了吗. 提交于 2019-11-30 12:33:27
When doing null checks in Java code, and you throw IllegalArgumentExceptions for null values, what kind of message template do you use? We tend to use something like this public User getUser(String username){ if (username == null){ throw new IllegalArgumentException("username is null"); } // ... } What is better : "is null" or "was null", and why? For me "is null" feels more natural. polygenelubricants Since the Exception is thrown due to a failed precondition check, I think rather than simply stating a fact, you should state the requirement that was violated. That is, instead of saying

Formating using DecimalFormat throws exception - “Cannot format given Object as a Number”

痴心易碎 提交于 2019-11-30 09:31:22
This might look like a repeated question but I tried in all the below links and can't get a proper answer. Cannot format given Object as a Number ComboBox Illegal Argument Exception But I'm not getting whats wrong. Here is my code DecimalFormat twoDForm = new DecimalFormat("#.##"); double externalmark = 1.86; double internalmark = 4.0; System.out.println(String.valueOf((externalmark*3+internalmark*1)/4)); String val = String.valueOf((externalmark*3+internalmark*1)/4); String wgpa1=twoDForm.format(val); // gives exception String wgpa2=twoDForm.format((externalmark*3+internalmark*1)/4)); //

Exception : adding a window to a container. How to solve it?

一个人想着一个人 提交于 2019-11-30 09:21:04
问题 I have a JDialog class named Preferences . This class creates a constructor like: class Preferences extends javax.swing.JDialog { Preferences(java.awt.Frame parent,modal) { super(parent,modal); //...... } } In my program I want this preferences dialog to open up as I click a button from a JFrame form. After I registered the action listener on the button, I wrote the code inside as: Frame fr = new Frame(); Preferences p = new Preferences(fr,false); fr.add(p); fr.setVisible(true); When I run

Host name may not be null in HttpResponse execute for android

ぃ、小莉子 提交于 2019-11-30 08:20:47
问题 I get the error "Target host must not be null, or set in parameters". I DO have Internet permission in my manifest file I have put 'http://' before my Url I DO encode the URL This is my code: String url = "http://maps.google.com/maps/api/directions/json?origin=1600 Pennsylvania Avenue NW, Washington, DC 20500&destination=1029 Vermont Ave NW, Washington, DC 20005&sensor=false"; HttpClient httpclient = new DefaultHttpClient(); String goodURL = convertURL(url);//change weird characters for %etc

Why do I get “object is not an instance of declaring class” when invoking a method using reflection?

廉价感情. 提交于 2019-11-30 07:45:13
问题 public class Shared { public static void main(String arg[]) throws SecurityException, NoSuchMethodException, IllegalArgumentException, IllegalAccessException, InvocationTargetException { Shared s1 = new Shared(); Object obj[] = new Object[2]; obj[0] = "object1"; obj[1] = "object2"; s1.testParam(null, obj); Class param[] = new Class[2]; param[0] = String.class; param[1] = Object[].class; //// how to define the second parameter as array Method testParamMethod = s1.getClass().getDeclaredMethod(

How to properly use reflection to access hidden methods in Telephony Manager

左心房为你撑大大i 提交于 2019-11-29 23:35:38
问题 I'm not sure if I'm having trouble with Reflection itself, or the method I'm trying to obtain. What I'd like to do is call the function setLine1Number from the class: com.android.internal.telephony.gsm.GSMPhone So that I can have my number properly inserted into my phone as it is not required to be in my SIM. Therefore I want to be able to call the function getLine1Number and have it return the same number that I set. Reflection appears the only way to be able to use this function as it is

Null check error message as “is null” or “was null”

二次信任 提交于 2019-11-29 17:53:14
问题 When doing null checks in Java code, and you throw IllegalArgumentExceptions for null values, what kind of message template do you use? We tend to use something like this public User getUser(String username){ if (username == null){ throw new IllegalArgumentException("username is null"); } // ... } What is better : "is null" or "was null", and why? For me "is null" feels more natural. 回答1: Since the Exception is thrown due to a failed precondition check, I think rather than simply stating a