getting, Timer Schedule 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
my json objects
look like this:
{
"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 ...
Here is my complete
code:
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
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.