2013-12-09 2 views
0

@Override에 대한 오류가 발생하며이를 수정하거나 상위 유형을 구현해야한다고 말합니다.@Override는 슈퍼 유형을 무시하거나 구현해야합니다.

이것은 내 코드이며 오류를주는 비트는 onNewIntent (Intent intent)로 보호됩니다.

감사

public class CartListActivity extends ListActivity { 

     public class ProductListAdapter extends BaseAdapter { 

      @Override 
      protected void onNewIntent(Intent intent) { 
       String query = ""; 

       if (Intent.ACTION_SEARCH.equals(intent.getAction())) { 
        //use the query to search your data 
        query = intent.getStringExtra(SearchManager.QUERY); 
       } 
       int catId = intent.getIntExtra(MainActivity.SELECTED_CATEGORY, 0); 
       if (catId != 0) 
        categoryId = catId; 

       loader = new ListViewLoader(adapter, categoryId); 
       if (query.length() > 0) { 
        loader.execute(String.format(MainActivity.WEBSERVER_GETLIST + "q=%s", categoryId, query)); 
       } 
       else { 
        loader.execute(String.format(MainActivity.WEBSERVER_GETLIST, categoryId)); 
       } 
      } 

      private final Context context; 
      private List<Product> itemList; 
      public List<Product> getItemList() { 
       return itemList; 
      } 

      public void setItemList(List<Product> itemList) { 
       this.itemList = itemList; 
      } 

      public Context getContext() { 
       return context; 
      } 

      public ProductListAdapter(Context c) { 
       context = c; 
      } 

      @Override 
      public int getCount() { 
       if(itemList == null) return 0; 
       else return itemList.size(); 
      }  

      @Override 
      public Object getItem(int position) { 
       if (itemList == null) return null; 
       else return itemList.get(position); 
      } 

      @Override 
      public long getItemId(int position) { 
       if (itemList == null) return 0; 
       else return itemList.get(position).hashCode(); 
      } 

      @Override 
      public View getView(int position, View convertView, ViewGroup parent) { 


       View cell = convertView; 

       if (cell == null) { 
        // get layout from mobile xml 
        LayoutInflater inflater = ((Activity)context).getLayoutInflater(); 
        cell = inflater.inflate(R.layout.adapter_product_list, parent, false); 
       } 

       Product p = itemList.get(position); 

       //set value into textview according to position 
       TextView textView = (TextView) cell.findViewById(R.id.product_title); 
       textView.setText(p.getProductName()); 

       // add £ symbol 
       textView = (TextView) cell.findViewById(R.id.product_info); 
       textView.setText("Price: " + "£"+ p.getPrice()); 

       //set value into imageview according to position 
       ImageView imgView = (ImageView) cell.findViewById(R.id.product_image); 
       // clear the image 
       imgView.setImageDrawable(null); 
       //and load from the network 
       p.loadImage(imgView, 54, 54); 

       return cell;    

      } 


     } 

     public static final Integer[] productIcons = { 
      0, // index 0 is empty 
      R.drawable.books, 
      R.drawable.films, 
      R.drawable.music, 
      R.drawable.games, 
     }; 

     private int categoryId; 
     private ProductListAdapter adapter; 
     private ListViewLoader loader; 

     @Override 
     protected void onCreate(Bundle savedInstanceState) { 
      super.onCreate(savedInstanceState); 
      // get the category from the intent 
      Intent intent = getIntent(); 
      categoryId = intent.getIntExtra(MainActivity.SELECTED_CATEGORY, 0); 

      adapter = new ProductListAdapter(this); 
      setListAdapter(adapter); 

      // Show the Up button in the action bar. 
      setupActionBar(); 

      loader = new ListViewLoader(adapter, categoryId); 
      loader.execute(String.format(MainActivity.WEBSERVER_GETLIST, categoryId)); 
     } 

     /** 
     * Set up the {@link android.app.ActionBar}. 
     */ 
     private void setupActionBar() { 

      getActionBar().setDisplayHomeAsUpEnabled(true); 

     } 

     @Override 
     public boolean onCreateOptionsMenu(Menu menu) { 
      // Inflate the menu; this adds items to the action bar if it is present. 
      getMenuInflater().inflate(R.menu.product_list, menu); 
      return true; 
     } 

     @Override 
     public boolean onOptionsItemSelected(MenuItem item) { 
      switch (item.getItemId()) { 
      case R.id.show_cart: 
       //create the intent for the cart activity 
       Intent intent = new Intent(getApplicationContext(), CartActivity.class); 
       startActivity(intent); 
       return true; 
      } 
      return super.onOptionsItemSelected(item); 
     } 

     @Override 
     public void onListItemClick(ListView l, View v, int position, long id) { 
      //create an intent 
      Intent intent = new Intent(this, ProductActivity.class); 
      Product p = (Product)adapter.getItem(position); 
      //specify the extra parameters we want to pass 
      intent.putExtra(MainActivity.SELECTED_CATEGORY, p.getCategoryId()); 
      intent.putExtra(MainActivity.SELECTED_PRODUCTID, p.getProductId()); 
      intent.putExtra(MainActivity.SELECTED_PRODUCTNAME, p.getProductName()); 
      intent.putExtra(MainActivity.SELECTED_PRODUCTPRICE, p.getPrice()); 
      intent.putExtra(MainActivity.SELECTED_SUITABLEFORKIDS, p.getSuitableForKids()); 

      startActivity(intent); 
     } 
    } 

답변

0

OnNewIntent는 활동에서만 재정의 할 수 있습니다. 어댑터에서 확장하고 있습니다. 메서드를 Activity 클래스로 옮기고 시도해 볼 수 있습니까?

+0

나는 이것을 시도하고 오류가 사라지지만 구현하려고하는 검색 기능은 결과를 끌어 오지 않습니다. 덕분에 – user3070626

+0

귀하의 어댑터에 공용 메서드를 추가하고 NewIntent 메서드에서 결과를 전송 :) 활동에 도움이된다면 답변을 올바르게 표시하십시오 – SalGad

0

@Override 주석을 사용하면 서브 클래스 (또는 인터페이스)에서 메서드를 재정의하려는 컴파일러를 알려줍니다. 원하지 않는 경우 (예 : 서명을 변경했기 때문에 더 이상 무시하지 않음) 경고가 생성됩니다. 메소드의 서명에 대해 변경했거나 다른 곳에서 복사/이동 했습니까?

2

OnNewIntentActivity의 기능이며 extendsActivity 인 클래스에서만 재정의 할 수 있습니다. ProductListAdapter을 연장하면 Adapter입니다.

탄원은 ProductListAdapter 클래스

public class CartListActivity extends ListActivity 
{ 
    @Override 
    protected void onNewIntent(Intent intent) 
    { 
     String query = ""; 
     if (Intent.ACTION_SEARCH.equals(intent.getAction())) 
     { 
      //use the query to search your data 
      query = intent.getStringExtra(SearchManager.QUERY); 
     } 
     int catId = intent.getIntExtra(MainActivity.SELECTED_CATEGORY, 0); 
     if (catId != 0) 
      categoryId = catId; 

     loader = new ListViewLoader(adapter, categoryId); 
     if (query.length() > 0) 
     { 
      loader.execute(String.format(MainActivity.WEBSERVER_GETLIST + "q=%s", categoryId, query)); 
     } 
     else 
     { 
      loader.execute(String.format(MainActivity.WEBSERVER_GETLIST, categoryId)); 
     } 
    } 

    //ALL OTHER FUNCTION OF CartListActivity 

    public class ProductListAdapter extends BaseAdapter 
    { 
     @Override 
     public int getCount() 
     { 
      if(itemList == null) 
       return 0; 
      else 
       return itemList.size(); 
     }  

     @Override 
     public Object getItem(int position) 
     { 
      if (itemList == null) 
       return null; 
      else 
       return itemList.get(position); 
     } 

     @Override 
     public long getItemId(int position) 
     { 
      if (itemList == null) 
       return 0; 
      else 
       return itemList.get(position).hashCode(); 
     } 
    } 
} 
0

프로젝트는 JRE의 소스 레벨 1.4 (이하)을 사용하도록 구성되어 선언하는 당신의 상류층 CartListActivity에 코드를 이동합니다. Compiler Compliance Level가 1.5 이상

로 설정되어 있는지

  • 확인 Java Compiler 메뉴로 이클립스에서 자바 프로젝트의 Properties에 이클립스에
  • 이동을

    1. 이동이 문제를 해결하려면 그냥 메서드를 재정의하는 데 @Override 주석이 필요하지 않음을 알려드립니다.

  • +0

    1.6으로 설정되어 있습니다. 팁 고마워 :) – user3070626

    관련 문제