Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8189299
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T03:13:52+00:00 2026-06-07T03:13:52+00:00

I build this webservice on netbeans, package in.figures.on.mobile; import db.koneksi.dbKoneksi; import java.sql.Statement; import java.sql.ResultSet;

  • 0

I build this webservice on netbeans,

package in.figures.on.mobile;

import db.koneksi.dbKoneksi;
import java.sql.Statement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService;
import org.json.simple.JSONValue;

/**
 *
 * @author Setyadi
 */
@WebService()
public class AksesData {

    /**
     * Web service operation
     */
    @WebMethod(operationName = "Kategori")
    public String Kategori() {
        //TODO write your implementation code here:

        dbKoneksi con = new dbKoneksi();
        Statement statement;
        Properties properties;
        List list = new ArrayList();
        String sql = "SELECT idPrimary_key, kategori FROM kategori ";
        ResultSet hasil;
        String kategori = null;

        try{
            statement = con.getConnection().createStatement();
            hasil = statement.executeQuery(sql);
            while (hasil.next()) {
                properties = new Properties();
                properties.put("idPrimary_key", hasil.getString(1));
                properties.put("kategori", hasil.getString(2));
                list.add(properties);
            }
            kategori = JSONValue.toJSONString(list);
        }
        catch(Exception e){
        }

        return kategori;
    }


}

And return a JSON like this

[{"idPrimary_key":"21ye21","kategori":"FirstCategory"},
{"idPrimary_key":"89oy89","kategori":"SecondCategory"},
{"idPrimary_key":"34ew34","kategori":"ThirdCategory"}]

And I try to consume in Android ListView like this, but still got errors,

        SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);  

        SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
        envelope.setOutputSoapObject(request);

        HttpTransportSE transportSE = new HttpTransportSE(URL);

        try {
            transportSE.call(SOAP_ACTION, envelope);
            SoapPrimitive response = (SoapPrimitive) envelope.getResponse();
            result = response.toString();

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

        }

        String jsonAN = "{\"kat\":"+result+"}"; //try to build to be like this {"kat":[{blablablaJSON}]}
        String kategoriJSONList[][] = new String[99][2];
        String katList[] = new String[99]; //tobe shown on listview, derived from two dimensional array above.
        try {
            jsonObject = new JSONObject(jsonAN);
            jsonArray = jsonObject.getJSONArray("kat");

            for(int i=0; i < jsonArray.length() ; i++){
                kategoriJSONList[i][0] = jsonArray.getJSONObject(i).getString("idPrimary_key").toString();
                kategoriJSONList[i][1] = jsonArray.getJSONObject(i).getString("kategori").toString();
            }

            for(int i=0; i < jsonArray.length(); i++){
                katList[i] = kategoriJSONList[i][1];
            }

        } catch (JSONException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        ListView list  = (ListView) findViewById(R.id.listKategori);
        ArrayAdapter<String> adapter = new ArrayAdapter<String>(
                WebServiceActivity.this, android.R.layout.simple_list_item_1,katList
                );

        list.setAdapter(adapter);

        list.setOnItemClickListener(new AdapterView.OnItemClickListener() {

            public void onItemClick(AdapterView<?> arg0, View arg1, int position,
                    long arg3) {
                final String kategori = (String) ((TextView)arg1).getText();
                Toast.makeText(WebServiceActivity.this, kategori,
                        Toast.LENGTH_LONG).show();
            }
        });

Need help how to consume the JSONValue that return as shown above to be shown as ListView.
I got stress in this days.
Thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T03:13:54+00:00Added an answer on June 7, 2026 at 3:13 am

    Ok. Try this bellow code. It is full functional to me. You should implement the HttpRequest in the commented line. Pay atention to that the JSON array is hard-coded.

    // the Adapter
    public class ListViewAdapter extends BaseAdapter {
    
        private Context context = null;
        private List<String> fields = null;
    
        public ListViewAdapter(Context context, JSONArray arr) {
            this.context = context;
            this.fields = new ArrayList<String>();
            for (int i=0; i<arr.length(); ++i) {
                try {
                    fields.add(arr.getJSONObject(i).toString());
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
        }
    
        @Override
        public int getCount() {
            return fields.size();
        }
    
        @Override
        public Object getItem(int position) {
            return fields.get(position);
        }
    
        @Override
        public long getItemId(int position) {
            return position;
        }
    
        @Override
        public View getView(int position, View convertView, ViewGroup viewGroup) {
            LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            convertView = inflater.inflate(R.layout.itemlist, null);
            TextView txt = (TextView) convertView.findViewById(R.id.ItemList_txt);
            txt.setText(fields.get(position));
            return convertView;
        }
    
    }
    
    // the activity
    public class ListViewActivity extends Activity {
    
        public final String result = "[{\"idPrimary_key\":\"21ye21\",\"kategori\":\"FirstCategory\"},{\"idPrimary_key\":\"89oy89\",\"kategori\":\"SecondCategory\"},{\"idPrimary_key\":\"34ew34\",\"kategori\":\"ThirdCategory\"}]";
        public final String obj = "{\"kat\":"+result+"}";
    
        private ListViewAdapter adapter = null;
        private ListView myList = null;
        private JSONArray items = new JSONArray();
    
        final Handler handler = new Handler() {
            @Override
            public void handleMessage(android.os.Message msg) {
                if (msg.what == 0) { // server returned null, try again
                    loadFields();
                } else if(msg.what == 1) { // error in json
                    // do something to treat it
                } else if (msg.what == 2) { // ready to roll the list
                    adapter = new ListViewAdapter(ListViewActivity.this, items);
                    myList.setAdapter(adapter);
                    adapter.notifyDataSetChanged();
                }
            }
        };
    
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        myList = (ListView) findViewById(R.id.Lists_notificationsListview);
        loadFields();
    }
    
    private void loadFields() {
        new Thread() {
            @Override
            public void run() {
                Looper.prepare();
                StringBuilder builder = new StringBuilder(obj);
                if (builder != null) {
                    try {
                        // HERE, you should implement the HTTP request...
                        items = new JSONObject(obj).getJSONArray("kat");
                        handler.sendEmptyMessage(2);
                    } catch (JSONException e) {
                        handler.sendEmptyMessage(1);
                    }
                } else {
                    handler.sendEmptyMessage(0);
                }
                Looper.loop();
            }
        }.start();
    }
    

    And the xml files:

    <?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="fill_parent">
        <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="fill_parent" android:layout_height="wrap_content"
            android:orientation="vertical"
            android:isScrollContainer="true">
            <ListView
                android:id="@+id/Lists_notificationsListview"
                android:layout_width="fill_parent" android:layout_height="match_parent">
            </ListView>
        </RelativeLayout>
    </LinearLayout>
    

    <?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="fill_parent">
        <TextView
            android:id="@+id/ItemList_txt"
            android:layout_width="fill_parent" android:layout_height="wrap_content"/>
    </LinearLayout>
    

    As result, it generates the following view:

    enter image description here

    Of course, you can customize it to create lists that you want, just parsing the jsons!
    Hope that I’ve helped in some way…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to build a webservice with this signature, which does not throw an
This is my first attempt to build a json webservice using the Tornado Framework
I'm busing to build a simple RESTful webservice for my thesis, maybe this is
I'm getting this error message whiile running a Webservice I'm working on. it builds,
I'm trying to build this layout: I have this at this time: http://jsfiddle.net/Gh6mB/12/ The
I might end up having to build this, but it would be nice if
This build warning just started showing up. I'm building for 3.1.3. Not sure what
I get this build error when I build my iPhone project to run on
I have a doubt, I made this build file in order to build 3
my project this year : build safe search engine for kids so i need

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.