2012-08-24 53 views
0

這是我的主要活動代碼。以下是我的主要活動代碼,它顯示了四個錯誤:Android編譯錯誤例如「適配器無法解析爲類型」

  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); 
    } 
}); 
} 

} 
+1

。你已經在方法體中聲明瞭很多東西。作爲一個例子,'ListAdapter'和'ListView'初始化必須放在方法體內。嘗試將它們包含在'onCreate'中並清理代碼。 – AnujAroshA

+1

請嘗試使用特定的有用標題。如果每個人都使用各種標題,包括「我是新手,這個錯誤很糟糕,請幫助」,那麼StackOverflow主頁將不會很有用。 – halfer

+1

@halfer感謝編輯這篇文章發佈時,我什麼都不知道,所以標題是這樣的,我知道這比以前更多 – surhidamatya

回答

1

你的的onCreate功能之外編寫代碼?似乎onCreate函數在catch塊後面的'}處結束。您可能只想刪除該代碼片段中的代碼格式是否正確

+1

這非常有幫助非常感謝你 – surhidamatya

相關問題