对于想了解线程“main”中的异常java.lang.IllegalArgumentException:n必须为正的读者,本文将是一篇不可错过的文章,我们将详细介绍线程main中发生异常,并且为您提供
对于想了解线程“ main”中的异常java.lang.IllegalArgumentException:n必须为正的读者,本文将是一篇不可错过的文章,我们将详细介绍线程main中发生异常,并且为您提供关于 java.lang.IllegalArgumentException、Exception in thread “main“ java.lang.IllegalArgumentException: 传入的参数有误、ios – 线程“main”中的异常java.lang.RuntimeException:无效的十六进制字符:v – APNS notnoop、Java Appium-线程“主”中的异常java.lang.ExceptionInInitializerError-由以下原因引起:java.lang.IllegalArgumentException的有价值信息。
本文目录一览:- 线程“ main”中的异常java.lang.IllegalArgumentException:n必须为正(线程main中发生异常)
- java.lang.IllegalArgumentException
- Exception in thread “main“ java.lang.IllegalArgumentException: 传入的参数有误
- ios – 线程“main”中的异常java.lang.RuntimeException:无效的十六进制字符:v – APNS notnoop
- Java Appium-线程“主”中的异常java.lang.ExceptionInInitializerError-由以下原因引起:java.lang.IllegalArgumentException
线程“ main”中的异常java.lang.IllegalArgumentException:n必须为正(线程main中发生异常)
这是我的错误信息:
Exception in thread "main" java.lang.IllegalArgumentException: n must be positive at java.util.Random.nextInt(Random.java:265) at Game.generateSecretNumber(Game.java:44) at Game.start(Game.java:32) at Game.main(Game.java:18
我的代码是:
import java.util.Random;import java.util.Scanner;public class Game {private final int LOWER_BOUND = 1;private int secretNumber;private int top;private static enum Response {YES, NO}private Random random;private Scanner scanner;public static void main(String[] args) { Game GuessingGame = new Game(); GuessingGame.start();} public Game() { random = new Random( ); scanner = new Scanner(System.in); } public void start() { Response answer; answer = Response.YES; while (answer == Response.YES) { generateSecretNumber(); playGame(); answer = prompt(""); } System.out.println("Bye!");} private void generateSecretNumber() { secretNumber = random.nextInt(top) + 1; System.out.println("You are going to guess a number between 1 and what number? "); top = scanner.nextInt(); System.out.println("Type a number between 1 and: " + top); } private void playGame() { int guessCount = 0; int guess; do { guess = getNextGuess(); guessCount++; if (guess < secretNumber) { System.out.println("Too low. Try again:"); } else if (guess > secretNumber) { System.out.println("Too high. Try again:"); } } while ( guess != secretNumber ); if ( guess == secretNumber ) { System.out.println("Right! It took you " + guessCount + " tries"); } else { System.out.println("game over"); } } private Response prompt(String question) { String input; Response response = Response.NO; System.out.print(question + "Would you like to play again? "); input = scanner.next(); if (input.equals("Y") || input.equals("y")) { response = Response.YES; } return response; } private int getNextGuess() { int input; while(true) { System.out.print(" "); input = scanner.nextInt(); if (LOWER_BOUND <= input && input <= top) { return input; } System.out.println("Invalid input: " + "must be between " + LOWER_BOUND + " and" + top); } } }
答案1
小编典典首次调用时top
为零,因此random.nextInt(top)
引发异常。只能使用正数调用此方法。
java.lang.IllegalArgumentException
问题描述:java.lang.IllegalArgumentException: Wrong state class, expecting View State but received class cn.etouch.ecalendar.waterfallview.StaggeredGridView$GridListSavedState instead. This usually happens when two views of different type have the same id in the same hierarchy. This view''s id is id/lv. Make sure other views do not use the same id.
问题出现情况分析:
android 5.0及以下版本如果出现这个问题,不要以为真的是id重复了。
我的项目情况是这样的在一个activity中有四个fagment ,F1,F2,F3,F4,在F2和F3的切换过程中,F4其实也已经初始化了,我在F4的布局中使用了自定义了一个ListView,它的id为lv.
之所以报错说id相同,大约是F4的上一次状态被保留下来了。
问题解决方案:
自定义的Listview的方法重写
@Override
protected void onRestoreInstanceState(Parcelable state) {
super.onRestoreInstanceState(state); }
修改为:
@Override
protected void onRestoreInstanceState(Parcelable state) {
try {
super.onRestoreInstanceState(state);
}catch (Exception e) {}
state=null;
}
Exception in thread “main“ java.lang.IllegalArgumentException: 传入的参数有误
跟着黑马视频学mybatis框架的时候,第一天的内容是手写框架,所以每一步都按照老师的来,出现了这样的错误,
找了好几个小时没有找出来,每一个类都按照老师的源码一一对照,最后还是没发现,知道准备放弃的时候,发现了这里居然写成了用class!!!!!!
原来是之前写的注解,但是开始写新的代码的时候忘记把他改过来了,每个文件都对比了,就是把这个文件忘了,把这里改过来!运行成功!!
ios – 线程“main”中的异常java.lang.RuntimeException:无效的十六进制字符:v – APNS notnoop
Exception in thread “main” java.lang.RuntimeException: Invalid hex character: v
at com.notnoop.apns.internal.Utilities.charVal(Utilities.java:133)
at com.notnoop.apns.internal.Utilities.decodeHex(Utilities.java:120)
at com.notnoop.apns.EnhancedApnsNotification.(EnhancedApnsNotification.java:72)
at com.notnoop.apns.internal.AbstractApnsService.push(AbstractApnsService.java:54)
at com.notnoop.apns.internal.ApnsServiceImpl.push(ApnsServiceImpl.java:36)
at com.notnoop.apns.internal.AbstractApnsService.push(AbstractApnsService.java:45)
at PushServiceTryout.main(PushServiceTryout.java:16)
我有什么不对的想法吗?我能感觉到我快到了!提前致谢.
编辑:这是代码.无论如何,一旦我运行程序,我就会收到错误:s
import com.notnoop.apns.APNS; import com.notnoop.apns.ApnsService; public class PushServiceTryout { public static void main(String[] args) { ApnsService service = APNS.newService() .withCert("c:/fcertificates.p12","1234") .withSandBoxDestination() .build(); String msg = "Hello"; String payload = APNS.newPayload().alertBody(msg).build(); String token = "devicetoken"; service.push(token,payload); } }
解决方法
String token = "devicetoken";
您不能将字符串“devicetoken”用作设备令牌.设备令牌由64个十六进制字符组成(例如:“1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef”).当然,你也不能使用随机十六进制字符串.您应该使用从安装了应用程序的设备发送给您的设备令牌.
您获得String中第一个非十六进制字符的异常,恰好是v.
Java Appium-线程“主”中的异常java.lang.ExceptionInInitializerError-由以下原因引起:java.lang.IllegalArgumentException
如何解决Java Appium-线程“主”中的异常java.lang.ExceptionInInitializerError-由以下原因引起:java.lang.IllegalArgumentException?
我正在用Java学习Appium,并尝试通过安装构造函数应用pageObjects来将驱动程序传递给我的测试用例。当我执行代码时,出现以下错误,我在线搜索并找不到解决方案。请帮助我调查此问题。我是Java编程的新手。
Sep 17,2020 3:29:25 PM io.appium.java_client.remote.AppiumCommandExecutor$1 lambda$0
INFO: Detected dialect: W3C
Exception in thread "main" java.lang.ExceptionInInitializerError
at io.appium.java_client.pagefactory.utils.ProxyFactory.getEnhancedProxy(ProxyFactory.java:52)
at io.appium.java_client.pagefactory.utils.ProxyFactory.getEnhancedProxy(ProxyFactory.java:33)
at io.appium.java_client.pagefactory.AppiumFieldDecorator.proxyForAnElement(AppiumFieldDecorator.java:222)
at io.appium.java_client.pagefactory.AppiumFieldDecorator.access$0(AppiumFieldDecorator.java:220)
at io.appium.java_client.pagefactory.AppiumFieldDecorator$1.proxyForLocator(AppiumFieldDecorator.java:105)
at org.openqa.selenium.support.pagefactory.DefaultFieldDecorator.decorate(DefaultFieldDecorator.java:62)
at io.appium.java_client.pagefactory.AppiumFieldDecorator.decorate(AppiumFieldDecorator.java:160)
at org.openqa.selenium.support.PageFactory.proxyFields(PageFactory.java:113)
at org.openqa.selenium.support.PageFactory.initElements(PageFactory.java:105)
at pageObjects.HomePage.<init>(HomePage.java:18)
at TestCases.Basics.main(Basics.java:22)
Caused by: java.lang.IllegalArgumentException
at org.objectweb.asm.ClassVisitor.<init>(ClassVisitor.java:79)
at net.sf.cglib.core.DebuggingClassWriter.<init>(DebuggingClassWriter.java:49)
at net.sf.cglib.core.DefaultGeneratorStrategy.getClassVisitor(DefaultGeneratorStrategy.java:30)
at net.sf.cglib.core.DefaultGeneratorStrategy.generate(DefaultGeneratorStrategy.java:24)
at net.sf.cglib.core.AbstractClassGenerator.generate(AbstractClassGenerator.java:332)
at net.sf.cglib.core.AbstractClassGenerator$ClassLoaderData$3.apply(AbstractClassGenerator.java:96)
at net.sf.cglib.core.AbstractClassGenerator$ClassLoaderData$3.apply(AbstractClassGenerator.java:94)
at net.sf.cglib.core.internal.LoadingCache$2.call(LoadingCache.java:54)
at java.util.concurrent.FutureTask.run(UnkNown Source)
at net.sf.cglib.core.internal.LoadingCache.createEntry(LoadingCache.java:61)
at net.sf.cglib.core.internal.LoadingCache.get(LoadingCache.java:34)
at net.sf.cglib.core.AbstractClassGenerator$ClassLoaderData.get(AbstractClassGenerator.java:119)
at net.sf.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:294)
at net.sf.cglib.core.KeyFactory$Generator.create(KeyFactory.java:221)
at net.sf.cglib.core.KeyFactory.create(KeyFactory.java:174)
at net.sf.cglib.core.KeyFactory.create(KeyFactory.java:153)
at net.sf.cglib.proxy.Enhancer.<clinit>(Enhancer.java:73)
... 11 more
HomePage.java代码:
package pageObjects;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.PageFactory;
import io.appium.java_client.AppiumDriver;
import io.appium.java_client.pagefactory.AndroidFindBy;
import io.appium.java_client.pagefactory.AppiumFieldDecorator;
public class HomePage{
//All the objects belongs to one page will be defined in a java class
//1. Call the driver object from testcase to PageObject file
//Concatenate driver
public HomePage(AppiumDriver driver) {
// Todo Auto-generated constructor stub
//AppiumFieldDecorator give the ability to test across iOS and Android platforms
PageFactory.initElements(new AppiumFieldDecorator(driver),this);
}
@AndroidFindBy(xpath="//android.widget.TextView[@text=''Preference'']")
public WebElement preferences;
}
Basics.java代码:
package TestCases;
import java.net.MalformedURLException;
import java.util.concurrent.TimeUnit;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.android.AndroidElement;
import pageObjects.HomePage;
import pageObjects.PreferencesPage;
public class Basics extends Base{
public static void main(String[] args) throws MalformedURLException {
// Todo Auto-generated method stub
AndroidDriver<AndroidElement> driver = Capabilities();
/*
* //xpath id className,androidUIautomator
* xpath Syntax
* //tagName[@attribute=''value'']
*/
HomePage home = new HomePage(driver);
home.preferences.click();
//PreferencesPage preferences = new PreferencesPage(driver);
driver.findElementByXPath("//android.widget.TextView[@text=''Preference'']").click();
driver.findElementByXPath("//android.widget.TextView[@text=''3. Preference dependencies'']").click();
driver.findElementById("android:id/checkBox").click();
driver.findElementByXPath("(//android.widget.RelativeLayout)[2]").click();
driver.findElementByClassName("android.widget.EditText").sendKeys("hello");
driver.findElementsByClassName("android.widget.Button").get(1).click();
}
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)
今天关于线程“ main”中的异常java.lang.IllegalArgumentException:n必须为正和线程main中发生异常的分享就到这里,希望大家有所收获,若想了解更多关于 java.lang.IllegalArgumentException、Exception in thread “main“ java.lang.IllegalArgumentException: 传入的参数有误、ios – 线程“main”中的异常java.lang.RuntimeException:无效的十六进制字符:v – APNS notnoop、Java Appium-线程“主”中的异常java.lang.ExceptionInInitializerError-由以下原因引起:java.lang.IllegalArgumentException等相关知识,可以在本站进行查询。
本文标签: