Questions tagged [illegalargumentexception]

An exception that indicates that the arguments supplied to a method or function are not valid for their intended purpose, or are different to the format expected by the method.

An exception that indicates that the arguments supplied to a method or function are not valid for their intended purpose, or are different to the format expected by the method.

This could occur as a result of many different actions, such as...

  1. You are calling a method that accepts a low-level object type for an argument (such as Object) but you're passing an object that is not one of the types expected by the method. For example, the method might be declaring the argument as an Object so that it can capture a range of different objects in the one method, but the code implementation of the method only allows objects of certain types (such as expecting a Number-based object, and you're passing a String).
  2. You're using methods that are building a dynamic structure for use in a different context, and the argument that you're passing is not valid for the other context. For example, you might be building an SQL statement, and you're passing an argument as a String for a database field that expects a Number. The database context would detect the error and report back the exception.

This type of exception may be hard to predict, as it won't be detected at compile-time, and may only show up under certain circumstances.

965 questions
16
votes
4 answers

IllegalArgumentException: Failed to find configuration root that contains xxx on FileProvider.getUriForFile

I have been trying to follow the Android tutorial on sharing files. I set up the FileProvider like this: On the main manifest xml:
14
votes
3 answers

Formatting using DecimalFormat throws exception - "Cannot format given Object as a Number"

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 what's wrong. Here is my code DecimalFormat…
14
votes
2 answers

Is it okay to use Junit Assert API in Java production code

I want to do null checks for my method arguments, like parameters should not be null. Is it okay to use something like this assertNotNull("Map should not be null", filePaths); in my Java code? I'm trying to avoid if(filePaths == null){ throw new…
Charu Khurana
  • 4,511
  • 8
  • 47
  • 81
13
votes
2 answers

IllegalArgumentException: Bound must be positive

I get an error saying that my bound must be positive. Here is the line I get it on: inv.setItem(i, items.get(r.nextInt(items.size()))); As far as I know, it comes from the part where I request a random integer from the list of items. This is how I…
Guus Huizen
  • 165
  • 1
  • 2
  • 9
13
votes
3 answers

UUID.fromString() returns an invalid UUID?

In my Android app I've got this method which takes a UUID. Unfortunately when I do this: OverviewEvent overviewevent = eventAdapter.getOverviewEvent(UUID.fromString("0f14d0ab-9605-4a62-a9e4-5ed26688389b")); I get an error saying…
kramer65
  • 50,427
  • 120
  • 308
  • 488
12
votes
1 answer

Customize Spring Error Message

I want to change the default error messages being thrown by Spring. I basically have this form. Format of the date should follow "mm/dd/yyyy"

Mark Estrada
  • 9,013
  • 37
  • 119
  • 186
12
votes
1 answer

Spring Cache Abstraction VS interfaces VS key param ("Null key returned for cache operation" error)

While implementing, I came across a problem with Spring Cache Abstraction VS interfaces. Lets say I have the following interface: package com.example.cache; public interface IAddItMethod { Integer addIt(String key); } And the two…
dostiguy
  • 123
  • 1
  • 1
  • 4
11
votes
1 answer

Kotlin - IllegalArgumentException in overridden method

In Kotlin I'm overriding this two Google Sign-In functions: override fun onConnectionFailed(result: ConnectionResult) { if (result.hasResolution()) { try { result.startResolutionForResult(this,…
Daniele
  • 4,163
  • 7
  • 44
  • 95
11
votes
1 answer

GcmBroadcastReceiver IllegalStateException: Not allowed to start service Intent

I am working on FCM Push notification in Android, where I am getting this exception: GcmBroadcastReceiver IllegalStateException: Not allowed to start service Intent I have searched many question in this forum, but still didn't got help for solving…
11
votes
1 answer

DialogPreference cause error onDisplayPreferenceDialog()

I would like to create a simple (yes/no) dialog preference, I followed the the answers in this post - creating a DialogPreference from XML But I get an error saying java.lang.IllegalArgumentException: Tried to display dialog for unknown preference…
11
votes
2 answers

Dagger 2 Build IllegalArgumentException compileDebugJavaWithJavac

I have been testing out Dagger 2, and everything had been working, until I did a bit of refactoring. Now gradle is throwing an IllegalArgumentException, and I cannot figure out what I changed that is now causing the error. I haven't made any changes…
Bryan
  • 14,756
  • 10
  • 70
  • 125
11
votes
2 answers

IllegalArgumentException when adding cloud messaging api to GoogleApiClient

I am setting up Google Cloud Messaging in an Android application. At the beginning, I initialise the GoogleApiClient in order to check whether the Play Services are available: mGoogleApiClient = new GoogleApiClient.Builder(this) …
11
votes
4 answers

Null check error message as "is null" or "was null"

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…
Timo Westkämper
  • 21,824
  • 5
  • 78
  • 111
11
votes
2 answers

IllegalArgumentException : Executable name has embedded quote, split the arguments

I'm getting an error : IllegalArgumentException : Executable name has embedded quote, split the arguments While running the Runtime.getRuntime().exec(cmd, envTokens, file1); I'm using Windows7 and Java7 machine . Same line of code is working…
Gaurav Singh
  • 12,707
  • 5
  • 22
  • 24
11
votes
3 answers

Reflections IllegalArgumentException causes

UPDATE - To make the question clearer. What is the possible cause of getting a ClassCastException while calling a method via reflections? I got the following stacktrace as a part of my application while trying to invoke a method via…
Aditya
  • 2,148
  • 3
  • 21
  • 34
1 2
3
64 65