Go Back   Android Forums > Android Development > Application Development
Application Development Dev lounge for our application developers.

Get excited for the Samsung Galaxy S5! Find everything you need and discuss it in our Galaxy S5 Forum!

test: Reply
 
LinkBack Thread Tools
Old January 30th, 2013, 08:24 AM   #1 (permalink)
Member
Thread Author (OP)
 
Join Date: Dec 2011
Location: chennai
Posts: 158
 
Device(s):
Carrier: Not Provided

Thanks: 1
Thanked 0 Times in 0 Posts
Default fetching data from mysql database and display on android edittext and spinner box

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:

Quote:
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:

Quote:
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:

Quote:
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.onItemSelec ted(RetailerActivity.java:129)
01-30 14:07:14.147: E/AndroidRuntime(2144): at android.widget.AdapterView.fireOnSelected(AdapterV iew.java:864)
01-30 14:07:14.147: E/AndroidRuntime(2144): at android.widget.AdapterView.selectionChanged(Adapte rView.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...

krishnaveni is offline  
Last edited by krishnaveni; January 30th, 2013 at 11:18 PM.
Reply With Quote
sponsored links
Old January 30th, 2013, 11:19 PM   #2 (permalink)
Member
Thread Author (OP)
 
Join Date: Dec 2011
Location: chennai
Posts: 158
 
Device(s):
Carrier: Not Provided

Thanks: 1
Thanked 0 Times in 0 Posts
Default

Hi.,

I got the solution for these after put the createSpinnerDropDown(); function inside the try clause....
krishnaveni is offline  
Reply With Quote
Reply
Tags
android, java, jdbc, ksoap, mysql, spinner


Go Back   Android Forums > Android Development > Application Development
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -5. The time now is 01:11 AM.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.