获取,计时器计划Caused by: java.lang.IllegalArgumentException
我在JSON中使用image和period对象,期间对象controls the duration of image
是可见的,但是我得到了引起:java.lang.IllegalArgumentException
我的json objects
看起来像这样:
{
"image": "http://localhost/image_01.jpg",
"period": "15000"
}
我可以知道我在做什么mistake
以及我必须在哪里制作changes
,以便尽快完成......
这是我的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的
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
答案 0 :(得分:0)
它给你这个错误,因为你安排的时间是零或小于零。尝试调试并查看您在delay
&amp;中传递的值。 period
作为参数。