0

I am trying to implement this custom seekbar.

I added the comboseekbar with these steps:

  • Right-click on the project
  • Properties
  • Android
  • Add
  • select "android-comboseekbar-master"
  • OK
  • OK

This is the xml layout file:

<com.infteh.comboseekbar.ComboSeekBar
    android:id="@+id/seekbar" 
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    app:color="#000"
    app:textSize="12sp"
    app:multiline="false"
    />

And the java class:

private ComboSeekBar segmentedSeekbar;

@Override
protected void onCreate(Bundle savedInstanceState)
{
    ....
    List<String> seekbarlist = Arrays.asList("A","B","C","D","E");
    segmentedSeekbar = new ComboSeekBar(this);       
    segmentedSeekbar.setAdapter(seekbarlist);
    ....
 }

After running the app on my device, I get this error.

E/AndroidRuntime(2751): FATAL EXCEPTION: main
E/AndroidRuntime(2751): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.salehjavaprograms.timetraveler/com.salehjavaprograms.timetraveler.Main}: java.lang.NullPointerException
E/AndroidRuntime(2751):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2114)
E/AndroidRuntime(2751):     at  android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2139)
E/AndroidRuntime(2751):     at  android.app.ActivityThread.access$700(ActivityThread.java:143)
E/AndroidRuntime(2751):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1241)
E/AndroidRuntime(2751):     at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime(2751):     at android.os.Looper.loop(Looper.java:137)
E/AndroidRuntime(2751):     at android.app.ActivityThread.main(ActivityThread.java:4960)
E/AndroidRuntime(2751):     at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime(2751):     at java.lang.reflect.Method.invoke(Method.java:511)
E/AndroidRuntime(2751):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1038)
E/AndroidRuntime(2751):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:805)
E/AndroidRuntime(2751):     at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime(2751): Caused by: java.lang.NullPointerException
E/AndroidRuntime(2751):     at com.infteh.comboseekbar.ComboSeekBar.initDotsCoordinates(ComboSeekBar.java:189)
E/AndroidRuntime(2751):     at com.infteh.comboseekbar.ComboSeekBar.setAdapter(ComboSeekBar.java:102)
E/AndroidRuntime(2751):     at com.salehjavaprograms.timetraveler.Main.onCreate(Main.java:69)
E/AndroidRuntime(2751):     at android.app.Activity.performCreate(Activity.java:5203)
E/AndroidRuntime(2751):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094)
E/AndroidRuntime(2751):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2078)
E/AndroidRuntime(2751):     ... 11 more

How can I fix this problem?

indivisible
  • 4,892
  • 4
  • 31
  • 50
Saleh Feek
  • 2,048
  • 8
  • 34
  • 56

1 Answers1

0

Looks like you need to call setThumb() on the seekbar first. The code assumes mThumb is not null and mThumb is normally only initialized in the two-arg constructor ComboSeekBar(Context,AttributeSet) but not in the one-arg constructor ComboSeekBar(Context) you're using.

laalto
  • 150,114
  • 66
  • 286
  • 303
  • How to make `AttributeSet`? – Saleh Feek May 29 '14 at 16:22
  • The platform calls that constructor when you inflate the view from an XML layout. – laalto May 29 '14 at 16:24
  • Hi @laalto can you tell how to get the selected step-value from this android-comboseekbar-master library.I asked a question http://stackoverflow.com/questions/28084069/how-to-get-the-step-value-selected-in-android-comboseekbar-master – George Thomas Jan 22 '15 at 08:31