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
-2
votes
1 answer

How to make a hash table throw an exception when inserting a null key (Java)?

For an assessment I need to create a hash table, which I have done. However, I need to throw an exception when inserting a null key. The test I ran, which I need to pass, was: @Test(expected = IllegalArgumentException.class) public void…
Xjh
  • 1
  • 1
-2
votes
1 answer

IllegalArgumentException will show an error when added String value

I'm new to Android development and it is a basic question. I have tried to replace IllegalArgumentException with the String value. How to replace this that Android error will not be shown? Need help. It wil not…
user447320
  • 1
  • 1
  • 6
-2
votes
1 answer

Currency based on HTTP request getLocale throwing IllegalArgumentException

I am trying to get currency symbols based on locale, currency code in a servlet. I tried to do the following but it is throwing IllegalArgumentException. Currency.getInstance(request.getlocale()) Locale has language as "en" but country value empty.…
Sri
  • 1,205
  • 2
  • 21
  • 52
-2
votes
1 answer

Why am i getting an IllegalArgumentException for every input?

I need to create a program that calculates the average of the test scores the user entered. This is actually the second time i've had an assignment asking to make this program. But this time the assignment wants me to throw an…
-2
votes
1 answer

Using a Try / Catch in a while loop

I'm asking my user to input via regex format "ABC-1234" otherwise an IllegalArgumentException is thrown. I would like to keep asking for the correct input (I'm thinking while or do while with a boolean variable set to false while input is…
-2
votes
1 answer

Caused by: java.lang.IllegalArgumentException: Illegal character in query at index 120

I am using the following url for fetching values from server. http://yyy.com/2013-01-01/search?q=t*&q.options={"defaultOperator":"and","fields":["name"]}&fq=(and directorytype:'directory1') I am gettting the following error when running the…
Sundeep
  • 375
  • 2
  • 4
  • 16
-2
votes
2 answers

Displays integers from first to last c-step step. If the output can lead to infinite loops, throw an exception IllegalArgumentException

Tell me what I'm missing? Input Arguments 1, 8, 2 8, 1, -2 1, 8, -2 Result 1 3 5 7 8 6 4 2 IllegalArgumentException My code: package com.Star; public class Main { public static void main(String[] args) { …
-2
votes
2 answers

java.lang.illegalargumentexception adding a window to a container

I keep receiving this error import javax.swing.*; import java.awt.*; import java.awt.event.*; import java.util.*; import javax.swing.table.*; import java.awt.Container.*; public class main extends JFrame implements…
MASUMI
  • 1
  • 1
-2
votes
1 answer

Get list object values using reflection API

i have a XML parsed pojo like below @XmlAccessorType(XmlAccessType.FIELD) @XmlType(name = "", propOrder = { "activity", "orderDetails" }) @XmlRootElement(name = "GxML") public class GxML { @XmlElement(name = "Activity", required =…
user1912935
  • 361
  • 4
  • 13
  • 34
-2
votes
2 answers

java.lang.IllegalArgumentException: Invalid xmlServletPath in servlet mapping

When I start Tomcat v7.0 Server from Servers tab in Eclipse, a problem occurred message box appears saying: Starting Tomcat v7.0 Server at localhost has encountered a problem. Server Tomcat v7.0 Server at localhost failed to start. I am a…
-2
votes
1 answer

why am i getting an illegal argument exception from this code?

This code was written following this tutorial: http://www.techsono.com/consult/update-android-gui-timer/ I don't understand why I'm getting an illegal argument exception from this code when i try and run it on my device. I'm not certain whats…
-2
votes
2 answers

Pick a random position in the word - IllegalArgumentException?

I have to implement the following instructions (pseudocode): Read a word. Repeat word.length() times Pick a random position i in the word, but not the last position. Pick a random position j > i in the word. (this is a tricky point!) Swap…
catch23
  • 17,519
  • 42
  • 144
  • 217
-2
votes
1 answer

wrong argument type # (expected Data)

I'm trying to fix a bug in my code. Some parts I've already fixed. Now I get this error ... TypeError in Ldap#getAccount Showing /home/stadler/tool/app/views/layouts/_stylesheets.html.erb where line #5 raised: wrong argument type…
-3
votes
2 answers

How to use "throws IllegalArgumentException" in method declaration

How do you write a method that has "throws IllegalArgumentEception" in the method declaration. Such like this one: If I were to only return d if d>0 otherwise throw an IllegalArgumentException, how would I do that? Do you use try{} and catch{}…
HaakonFlaar
  • 387
  • 2
  • 4
  • 15
-3
votes
1 answer

Illegal Argument Exception in Java

import java.util.ArrayDeque; import java.util.Deque; import java.util.Scanner; import static java.lang.System.in; import static java.lang.System.out; /* * * Use a stack to check parentheses, balanced and nesting * The parentheses are: (), []…
Netizen110
  • 1,644
  • 4
  • 18
  • 21
1 2 3
64
65