[英]Timer schedule Caused by: java.lang.IllegalArgumentException
getting, Timer Schedule Caused by: java.lang.IllegalArgumentException
获取,计时器计划Caused by: java.lang.IllegalArgumentException
I am using image and period objects in JSON, period object controls the duration of image
to be visible, but I am getting Caused by: java.lang.IllegalArgumentException 我在JSON中使用图像和期间对象,期间对象controls the duration of image
可见controls the duration of image
,但我正在通过以下原因引起:java.lang.IllegalArgumentException
my json objects
look like this: 我的json objects
看起来像这样:
{
"image": "http://localhost/image_01.jpg",
"period": "15000"
}
May I know where i am doing mistake
and where i have to make changes
, to get it done soon ... 我可以知道我在做什么mistake
,并在那里我必须作出changes
,以得到它很快完成了...
Here is my complete
code: 这是我complete
代码:
public class MainActivity extends Activity {
ArrayList<String> actorsList;
ViewFlipper viewFlipper;
int period = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
viewFlipper = (ViewFlipper) findViewById(R.id.flipper);
actorsList = new ArrayList<String>();
// execute AsyncTask
new JSONAsyncTask().execute("http://localhost/images.txt");
// handler to set duration and to upate animation
final Handler mHandler = new Handler();
// Create runnable for posting
final Runnable mUpdateResults = new Runnable() {
public void run() {
viewFlipper.showNext(); // showNext() method
}
};
int delay = 500;
Timer timer = new Timer(); // here i am getting error
timer.scheduleAtFixedRate(new TimerTask() {
public void run() {
mHandler.post(mUpdateResults);
}
}, delay, period);
}
}
Logcat Logcat
10-10 05:22:09.196: E/AndroidRuntime(537): FATAL EXCEPTION: main
10-10 05:22:09.196: E/AndroidRuntime(537): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.wingnity.jsonparsingtutorial/com.wingnity.jsonparsingtutorial.MainActivity}: java.lang.IllegalArgumentException
10-10 05:22:09.196: E/AndroidRuntime(537): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1955)
10-10 05:22:09.196: E/AndroidRuntime(537): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1980)
10-10 05:22:09.196: E/AndroidRuntime(537): at android.app.ActivityThread.access$600(ActivityThread.java:122)
10-10 05:22:09.196: E/AndroidRuntime(537): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1146)
10-10 05:22:09.196: E/AndroidRuntime(537): at android.os.Handler.dispatchMessage(Handler.java:99)
10-10 05:22:09.196: E/AndroidRuntime(537): at android.os.Looper.loop(Looper.java:137)
10-10 05:22:09.196: E/AndroidRuntime(537): at android.app.ActivityThread.main(ActivityThread.java:4340)
10-10 05:22:09.196: E/AndroidRuntime(537): at java.lang.reflect.Method.invokeNative(Native Method)
10-10 05:22:09.196: E/AndroidRuntime(537): at java.lang.reflect.Method.invoke(Method.java:511)
10-10 05:22:09.196: E/AndroidRuntime(537): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
10-10 05:22:09.196: E/AndroidRuntime(537): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
10-10 05:22:09.196: E/AndroidRuntime(537): at dalvik.system.NativeStart.main(Native Method)
10-10 05:22:09.196: E/AndroidRuntime(537): Caused by: java.lang.IllegalArgumentException
10-10 05:22:09.196: E/AndroidRuntime(537): at java.util.Timer.scheduleAtFixedRate(Timer.java:526)
10-10 05:22:09.196: E/AndroidRuntime(537): at com.wingnity.jsonparsingtutorial.MainActivity.onCreate(MainActivity.java:60)
10-10 05:22:09.196: E/AndroidRuntime(537): at android.app.Activity.performCreate(Activity.java:4465)
10-10 05:22:09.196: E/AndroidRuntime(537): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
10-10 05:22:09.196: E/AndroidRuntime(537): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1919)
10-10 05:22:09.196: E/AndroidRuntime(537): ... 11 more
10-10 05:22:11.355: I/Process(537): Sending signal. PID: 537 SIG: 9
It is giving you this error because the time you scheduled is zero or less than zero. 这是因为您计划的时间为零或小于零,所以出现此错误。 Try to debug and see what are the values you're passing in delay
& period
as parameters. 尝试调试,看看在delay
和period
作为参数传递的值是什么。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.