0

I dont know but why it is showing remove @Override annotation from onCreateContextMenu ? Anyone can tell my why its happening ?

I already check, my compiler is set to java 1.6. and my jre is set to 1.6.

contactPHP.java

    public class contactPHP extends AsyncTask<Object, Object, JSONArray>{
        final contactActivity main;
        private ListView listView;
        public contactPHP(contactActivity indv) {
            this.main = indv;
        }
    @Override
    protected void onPreExecute() {
         super.onPreExecute();  

            listView = (ListView)main.findViewById(R.id.listnum);
            adapter = new contactAdapter(main, imlist);
            listView.setAdapter(adapter);       
}
@Override      
public void onCreateContextMenu(ContextMenu menu, View v,ContextMenuInfo menuInfo) {  
           main.onCreateContextMenu(menu, v, menuInfo);  

        CNList obj = (CNList)v.getTag(); 
        int subs = obj.getsubstance();    

        menu.setHeaderTitle(obj.getname());  
        menu.add(0, v.getId(), 0, "Add");  
        menu.add(0, v.getId(), 0, "Remove");  
    }
    }

contactActivity.java

public class contactActivity extends Activity{



   @Override
   protected void onCreate(Bundle savedInstanceState) {

       super.onCreate(savedInstanceState);

       setContentView(R.layout.contact);
       getLayoutInflater().inflate(R.layout.contact, null);
       Intent intent = getIntent();
       new contactPHP(contactActivity.this).execute();
       //getNumber(contactActivity.this.getContentResolver()); 
   }



}

UPDATE 1

Added the onCreateContextMenu in activity and also returned onPostExecute() to activity but getting an error!

contactPHP.java edited

protected void onPostExecute(JSONArray json) {  
    main.contactPhpResponse(....);
}

contactActivity.java edited

  public void contactPhpResponse(ListView listView,JSONArray json){
      this.registerForContextMenu(listView);
     //some codes
  }
  @Override
   public void onCreateContextMenu(ContextMenu menu, View v,ContextMenuInfo menuInfo) {  
       this.onCreateContextMenu(menu, v, menuInfo);  

    CNList obj = (CNList)v.getTag(); 
    int subs = obj.getsubstance();    

    menu.setHeaderTitle(obj.getname());  
        menu.add(0, v.getId(), 0, "Add");  
        menu.add(0, v.getId(), 0, "Remove");  
}

LogCAT

03-04 16:36:48.883: E/AndroidRuntime(5018): FATAL EXCEPTION: main
03-04 16:36:48.883: E/AndroidRuntime(5018): Process: com.example.soc, PID: 5018
03-04 16:36:48.883: E/AndroidRuntime(5018): java.lang.StackOverflowError
03-04 16:36:48.883: E/AndroidRuntime(5018):     at com.example.soc.contactActivity.onCreateContextMenu(contactActivity.java:92)
03-04 16:36:48.883: E/AndroidRuntime(5018):     at com.example.soc.contactActivity.onCreateContextMenu(contactActivity.java:92)
03-04 16:36:48.883: E/AndroidRuntime(5018):     at com.example.soc.contactActivity.onCreateContextMenu(contactActivity.java:92)
03-04 16:36:48.883: E/AndroidRuntime(5018):     at com.example.soc.contactActivity.onCreateContextMenu(contactActivity.java:92)

it means this line this.onCreateContextMenu(menu, v, menuInfo);

Slim Shady
  • 1,045
  • 2
  • 12
  • 38

1 Answers1

4

It's becuse onCreateContextMenu is not a method of AsyncTask, hence you can't override it. Move in your Activity class. Also, please, respect java naming conventions. Class name starts always with capital letter.

Blackbelt
  • 156,034
  • 29
  • 297
  • 305
  • @SlimShady why can't you? Your update doesn't mention anything about why? Return the values you need from `onPostExecute()` to your `Activity` and use them there. – codeMagic Mar 03 '15 at 19:32
  • Yes i am doing my stuff inside `onPostExecute()` .... how do i return my `onPostExecute()` data back to my `contactActivity.java` ? @codeMagic – Slim Shady Mar 03 '15 at 19:35
  • @SlimShady, [here](http://stackoverflow.com/questions/16752073/how-do-i-return-a-boolean-from-asynctask) an example – Blackbelt Mar 03 '15 at 19:37
  • Change this with super. You have to use super to call the super class – Blackbelt Mar 04 '15 at 11:53
  • change `this.onCreateContextMenu(menu, v, menuInfo);` with `super.onCreateContextMenu(menu, v, menuInfo);`, and you can also omit the super call, since the super implementation is empty – Blackbelt Mar 04 '15 at 12:03