• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps fetching data from mysql database and display on android edittext and spinner box

krishnaveni

Well-Known Member
Hi.,
I have to develop one android native application.

Here i have to fetch the value from mysql database and display on android edittext and spinner box.

I have to run the app means the value is fetching from database and displayed on android edittext.but not display on spinner box.

How can i display the value on android spinner box fetching from mysql database.

I have used the below webservice code:

public class DisplayProfile {
public String customerData(String Username,String Bcountry){

String customerInfo = "";

try{

Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://10.0.0.75:3306/xcart432pro","root","");
PreparedStatement statement = con.prepareStatement("SELECT * FROM xcart_customers where `login` = 'mercy'");
ResultSet result = statement.executeQuery();

while(result.next()){
customerInfo = customerInfo + result.getString("login")+ ":" +result.getString("b_country");
}

}
catch(Exception exc){
System.out.println(exc.getMessage());
}
return customerInfo;
These is my android code:

public class RetailerActivity extends Activity {
private final String NAMESPACE = "http://xcart.com";
private final String URL = "http://10.0.0.75:8085/XcartLogin/services/DisplayProfile?wsdl";
private int i;
private final String SOAP_ACTION = "http://xcart.com/customerData";
private final String METHOD_NAME = "customerData";
String str,country,country1;

String selectedItem;

Spinner spinner;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
spinner = (Spinner) findViewById(R.id.tf_country);


createSpinnerDropDown();
try {
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);

envelope.setOutputSoapObject(request);

HttpTransportSE ht = new HttpTransportSE(URL);

ht.call(SOAP_ACTION, envelope);
SoapPrimitive response = (SoapPrimitive)envelope.getResponse();
SoapPrimitive s = response;
str = s.toString();
String[] words = str.split(":");
EditText tv = (EditText) findViewById(R.id.user);


tv.setText(words[0].toString());
spinner = (Spinner) findViewById(R.id.tf_country);
country = words[1].toString();





for (int i = 0, l = words.length; i < l; ++i) {

}



}

catch (Exception e) {
e.printStackTrace();
}
}









private void createSpinnerDropDown() {


//Array list of animals to display in the spinner
List<String> list = new ArrayList<String>();

list.add(country);

list.add("United Status");
list.add("Afghanistan");
list.add("Aland Islands");
list.add("Albania");
list.add("Algeria");
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
R.layout.row, R.id.country, list);


spinner.setPrompt("Choose a Country");

spinner.setAdapter(adapter);
adapter.notifyDataSetChanged();

spinner.setOnItemSelectedListener(new OnItemSelectedListener() {

public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {

selectedItem = parent.getItemAtPosition(pos).toString();

}

public void onNothingSelected(AdapterView<?> parentView)
{
}
});
Here i have to run the app means am getting following error on my console window:

01-30 14:07:14.147: E/AndroidRuntime(2144): FATAL EXCEPTION: main
01-30 14:07:14.147: E/AndroidRuntime(2144): java.lang.NullPointerException
01-30 14:07:14.147: E/AndroidRuntime(2144): at com.retailer.client.RetailerActivity$1.onItemSelected(RetailerActivity.java:129)
01-30 14:07:14.147: E/AndroidRuntime(2144): at android.widget.AdapterView.fireOnSelected(AdapterView.java:864)
01-30 14:07:14.147: E/AndroidRuntime(2144): at android.widget.AdapterView.selectionChanged(AdapterView.java:847)
01-30 14:07:14.147: E/AndroidRuntime(2144): at android.widget.AdapterView.checkSelectionChanged
Why am getting the above error??? please help me how can i resolve the above error ???? how can i display the fetching data on spinner box list on first item...
 
Back
Top Bottom