First, I am trying to create SeekBar with a change listener. I hope I am doing this correctly. Below, red is giving me a null exception. I believe that is because my list is one xml and my seekbar/textview layout is another xml. Is that the case? How would I go about grabbing it?
seekbars.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/seekBarLayout"
>
<TextView
android:gravity="center_horizontal"
android:background="#aa0000"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1"
android:id="@+id/seekBarLabel"/>
<TextView
android:gravity="center_horizontal"
android:background="#aa0000"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1"
android:id="@+id/seekBarValue"/>
<SeekBar
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/seekBarID"/>
</LinearLayout>
seekbarlist.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<ListView
android:id="@android:id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
</ListView>
</LinearLayout>
android code
package thisPackage.Tabs;
public class ColorsActivity extends ListActivity implements SeekBar.OnSeekBarChangeListener {
/** Called when the activity is first created. */
//Array Adapter that will hold our ArrayList and display the items on the ListView
SeekBarAdaptor seekBarAdaptor;
//List that will host our items and allow us to modify that array adapter
ArrayList<SeekBar> seekBarArrayList=null;
TextView myValueText;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.seekbarlist);
//Initialize ListView
ListView lstTest= getListView();
//Initialize our ArrayList
seekBarArrayList = new ArrayList<SeekBar>();
//Initialize our array adapter
seekBarAdaptor = new SeekBarAdaptor(ColorsActivity.this, R.layout.seekbars,seekBarArrayList);
//setContentView(R.layout.seekbars);
SeekBar red = (SeekBar)findViewById(R.id.seekBarID);
red.setOnSeekBarChangeListener(this);
// SeekBar blue = new SeekBar(this);
//Set the above adapter as the adapter of choice for our list
lstTest.setAdapter(seekBarAdaptor);
seekBarArrayList.add(red);
//seekBarArrayList.add(blue);
}
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromTouch) {
//myLayout = (LinearLayout)seekBar.findViewById(R.id.seekBarLayout);
myValueText = (TextView)findViewById(R.id.seekBarValue);
myValueText.setText("hello");
//myValueText.setText("text");
}
public void onStopTrackingTouch(SeekBar seekBar){
}
public void onStartTrackingTouch (SeekBar seekBar){
}
}
logcat
03-15 00:01:52.020: D/AndroidRuntime(345): Shutting down VM
03-15 00:01:52.020: W/dalvikvm(345): threadid=1: thread exiting with uncaught exception (group=0x40015560)
03-15 00:01:52.040: E/AndroidRuntime(345): FATAL EXCEPTION: main
03-15 00:01:52.040: E/AndroidRuntime(345): java.lang.RuntimeException: Unable to start activity ComponentInfo{thisPackage.Tabs/thisPackage.Tabs.ColorsActivity}: java.lang.NullPointerException
03-15 00:01:52.040: E/AndroidRuntime(345): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
03-15 00:01:52.040: E/AndroidRuntime(345): at android.app.ActivityThread.startActivityNow(ActivityThread.java:1487)
03-15 00:01:52.040: E/AndroidRuntime(345): at android.app.LocalActivityManager.moveToState(LocalActivityManager.java:127)
03-15 00:01:52.040: E/AndroidRuntime(345): at android.app.LocalActivityManager.startActivity(LocalActivityManager.java:339)
03-15 00:01:52.040: E/AndroidRuntime(345): at android.widget.TabHost$IntentContentStrategy.getContentView(TabHost.java:654)
03-15 00:01:52.040: E/AndroidRuntime(345): at android.widget.TabHost.setCurrentTab(TabHost.java:326)
03-15 00:01:52.040: E/AndroidRuntime(345): at android.widget.TabHost$2.onTabSelectionChanged(TabHost.java:132)
03-15 00:01:52.040: E/AndroidRuntime(345): at android.widget.TabWidget$TabClickListener.onClick(TabWidget.java:456)
03-15 00:01:52.040: E/AndroidRuntime(345): at android.view.View.performClick(View.java:2485)
03-15 00:01:52.040: E/AndroidRuntime(345): at android.view.View$PerformClick.run(View.java:9080)
03-15 00:01:52.040: E/AndroidRuntime(345): at android.os.Handler.handleCallback(Handler.java:587)
03-15 00:01:52.040: E/AndroidRuntime(345): at android.os.Handler.dispatchMessage(Handler.java:92)
03-15 00:01:52.040: E/AndroidRuntime(345): at android.os.Looper.loop(Looper.java:123)
03-15 00:01:52.040: E/AndroidRuntime(345): at android.app.ActivityThread.main(ActivityThread.java:3683)
03-15 00:01:52.040: E/AndroidRuntime(345): at java.lang.reflect.Method.invokeNative(Native Method)
03-15 00:01:52.040: E/AndroidRuntime(345): at java.lang.reflect.Method.invoke(Method.java:507)
03-15 00:01:52.040: E/AndroidRuntime(345): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
03-15 00:01:52.040: E/AndroidRuntime(345): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
03-15 00:01:52.040: E/AndroidRuntime(345): at dalvik.system.NativeStart.main(Native Method)
03-15 00:01:52.040: E/AndroidRuntime(345): Caused by: java.lang.NullPointerException
03-15 00:01:52.040: E/AndroidRuntime(345): at thisPackage.Tabs.ColorsActivity.onCreate(ColorsActivity.java:52)
03-15 00:01:52.040: E/AndroidRuntime(345): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
03-15 00:01:52.040: E/AndroidRuntime(345): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
03-15 00:01:52.040: E/AndroidRuntime(345): ... 18 more
Is R.id.seekBarID refers to something in R.layout.seekbarlist? If not, then
SeekBar red = (SeekBar)findViewById(R.id.seekBarID);
will returns null as it cannot find the specified view, it would be helpful if you can post the 2 layout files as well.