0

这是我的主要活动代码。以下是我的主要活动代码,它显示了四个错误:

  1. 适配器无法解析为类型
  2. 令牌“)”上的语法错误,{ 应在此令牌之后
  3. 令牌“适配器”上的语法错误,此令牌后应为 VariableDeclaratorId。

源代码:

public class HospitalParseActivity extends ListActivity {
//url where request is made
private static String url="url";

//JSON node names
private static final String TAG_NETFOX="transfer";
private static final String TAG_DATE="date";
private static final String TAG_CWEB="c_web";
private static final String TAG_CBANK="c_bank";
private static final String TAG_CCASH="c_cash";
private static final String TAG_SWEB="s_web";
private static final String TAG_SBANK="s_bank";
private static final String TAG_SCASH="s_cash";

//creation of JSONArray
JSONArray netfoxlimited=null;

private List<? extends Map<String, ?>> contactList;


@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

 // Hashmap for ListView
    ArrayList<HashMap<String, String>> contactList = new ArrayList<HashMap<String,         String>>();

    // Creating JSON Parser instance
    JSONParser jParser = new JSONParser();

    // getting JSON string from URL
    JSONObject json = jParser.getJSONFromUrl(url);

    try {
        // Getting Array of Contacts
        netfoxlimited = json.getJSONArray(TAG_NETFOX);

        // looping through All Contacts
        for(int i = 0; i < netfoxlimited.length(); i++){
            JSONObject c = netfoxlimited.getJSONObject(i);

            // Storing each json item in variable
            String date = c.getString(TAG_DATE);
            String c_web = c.getString(TAG_CWEB);
            String c_bank = c.getString(TAG_CBANK);
            String c_cash = c.getString(TAG_CCASH);
            String s_web = c.getString(TAG_SWEB);
            String s_bank = c.getString(TAG_SBANK);
            String s_cash = c.getString(TAG_SCASH);

            // creating new HashMap
            HashMap<String, String> map = new HashMap<String, String>();

            // adding each child node to HashMap key => value
            map.put(TAG_DATE, date);
            map.put(TAG_CWEB, c_web);
            map.put(TAG_CBANK, c_bank);
            map.put(TAG_CCASH, c_cash);
            map.put(TAG_SWEB, s_web);
            map.put(TAG_SBANK, s_bank);
            map.put(TAG_SCASH, s_cash);



            // adding HashList to ArrayList
            contactList.add(map);
        }
    } catch (JSONException e) {
        e.printStackTrace();
    }
}

/**
 * Updating parsed JSON data into ListView
 * */
ListAdapter adapter = new SimpleAdapter(this, contactList,
        R.layout.list_item,
        new String[] { TAG_DATE, TAG_CWEB, TAG_CBANK,TAG_CCASH, TAG_CWEB,TAG_CBANK, TAG_CCASH }, new int[] {
                R.id.date, R.id.cweb, R.id.cbank,R.id.sweb,R.id.sbank,R.id.scash });


setListAdapter(adapter);

// selecting single ListView item
ListView lv = getListView();

// Launching new screen on Selecting Single ListItem
lv.setOnItemClickListener(new OnItemClickListener() {

    @Override
    public void onItemClick(AdapterView<?> parent, View view,
            int position, long id) {
        // getting values from selected ListItem
        String dt = ((TextView) view.findViewById(R.id.date)).getText().toString();
        String web = ((TextView) view.findViewById(R.id.cweb)).getText().toString();
        String bank = ((TextView) view.findViewById(R.id.cbank)).getText().toString();
        String cash = ((TextView) view.findViewById(R.id.ccash)).getText().toString();
        String web1 = ((TextView) view.findViewById(R.id.sweb)).getText().toString();
        String bank1 = ((TextView) view.findViewById(R.id.sbank)).getText().toString();
        String cash1 = ((TextView) view.findViewById(R.id.scash)).getText().toString();


        // Starting new intent
        Intent in = new Intent(getApplicationContext(), SingleMenuItemActivity.class);
        in.putExtra(TAG_DATE, dt);
        in.putExtra(TAG_CWEB, web);
        in.putExtra(TAG_CBANK, bank);
        in.putExtra(TAG_CCASH, cash);
        in.putExtra(TAG_SWEB, web1);
        in.putExtra(TAG_SBANK, bank1);
        in.putExtra(TAG_SCASH, cash1);
        startActivity(in);
    }
});
}

}
4

1 回答 1

1

您是否在 onCreate 函数之外编写代码?似乎 onCreate 函数在 catch 块之后的“}”处结束。您可能只想删除它

于 2012-08-24T10:44:14.043 回答