i am trying to send the value of string which is accessed from a spinner and send it to data helper class to run a query and insert value in another spinner which is running on another activity

Method inside class which fetches value of string

NewTask.java

```
@Override
public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2,
        long arg3) {

     // On selecting a spinner item
     label = spinnerComp.getSelectedItem().toString(); //storing value of spinner in string label
     System.out.println("NewTask label="+label);

     toRetDeptString();   //it will call return string method

    // Showing selected spinner item
    Toast.makeText(spinnerComp.getContext(), "You selected: " + label,
            Toast.LENGTH_LONG).show();
}

```

now the return string method is which is also declared inside NewTask.java

```
    public String toRetDeptString() {
    System.out.println("NewTask String label="+label);
    return label;
  }

```

and now i am trying to access the value of label string dataHelper class which runs the query on basis of value inside the string label 

Inside DataHelper.java 
and in that inside DatabaseHelper class

```
    public List<String> getAllLabelsDept(){

           NewTask a = new NewTask();
           String n1= a.toRetDeptString();  //this one doesn't worked

               // String n1 = a.label;  //this one doesn't worked

         //  String n1="umbrella";  //this method worked by directly assiging string value
           System.out.println("a="+n1);
            List<String> labels = new ArrayList<String>();

            //  Query
            String selectQuery = "select  " + Dept + " from "+TABLE_NAME +" where " + Comp + " = '" + n1 +"'";

            SQLiteDatabase db1 = this.getReadableDatabase();
            Cursor cursor = db1.rawQuery(selectQuery, null);

            // looping through all rows and adding to list
            if (cursor.moveToFirst()) {
                do {
                    labels.add(cursor.getString(cursor.getColumnIndex(Dept)));
                } while (cursor.moveToNext());
            }

            // closing connection
            cursor.close();
            db1.close();

            // returning lables
            return labels;
        }

```

Select\_Dept.java

```
  public class Select_Dept extends Activity implements OnItemSelectedListener{
Spinner spinnerDept;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_select__dept);

    spinnerDept = (Spinner) findViewById(R.id.spinnerDept);
    spinnerDept.setOnItemSelectedListener(this);
    loadSpinnerDataDept();
}

private void loadSpinnerDataDept() {
    // database handler
    DatabaseHelper db = new DatabaseHelper(getApplicationContext());

    // Spinner Drop down elements
    List<String> lables = db.getAllLabelsDept();

    // Creating adapter for spinner
    ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(this,
            android.R.layout.simple_spinner_item, lables);

    // Drop down layout style - list view with radio button
    dataAdapter
            .setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

    // attaching data adapter to spinner
    spinnerDept.setAdapter(dataAdapter);
}

@Override
public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2,
        long arg3) {

     // On selecting a spinner item
     String label = spinnerDept.getSelectedItem().toString();

    // Showing selected spinner item
    Toast.makeText(spinnerDept.getContext(), "You selected: " + label,
            Toast.LENGTH_LONG).show();
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.select__dept, menu);
    return true;
}

@Override
public void onNothingSelected(AdapterView<?> arg0) {
    // TODO Auto-generated method stub

}

 }

```

output of Logcat:-

```
 - 06-05 12:30:13.369: I/ActivityManager(59): Starting activity: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=com.EzyCloud.ezytask/.MainActivity }
 - 06-05 12:30:14.160: I/ActivityManager(59): Displayed activity com.EzyCloud.ezytask/.MainActivity: 562 ms (total 562 ms)
06-05 12:30:16.139: I/ActivityManager(59): Starting activity: Intent { cmp=com.EzyCloud.ezytask/.NewTask }
 - 06-05 12:30:16.299: I/System.out(280): NewTask label=umbrella
 - 06-05 12:30:16.299: I/System.out(280): NewTask String label=umbrella
 - 06-05 12:30:16.559: I/ActivityManager(59): Displayed activity com.EzyCloud.ezytask/.NewTask: 406 ms (total 406 ms)
 - 06-05 12:30:19.140: I/ActivityManager(59): Starting activity: Intent { cmp=com.EzyCloud.ezytask/.Select_Dept }
 - 06-05 12:30:19.339: I/System.out(280): NewTask String label= //no value accesed
 - 06-05 12:30:19.339: I/System.out(280): a=                     **//no value accesed**
 - 06-05 12:30:19.699: I/ActivityManager(59): Displayed activity  - com.EzyCloud.ezytask/.Select_Dept: 508 ms (total 508 ms)
 - 06-05 12:30:24.849: D/dalvikvm(128): GC_EXPLICIT freed 202 objects / 9800 bytes in 145ms

```

but due to some problems value of string is not accesed