我不知道为什么它会显示从onCreateContextMenu
删除@Override注释?
任何人都可以告诉我为什么会这样?
我已经检查过,我的编译器设置为java 1.6。我的jre设置为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());
}
}
在活动中添加了onCreateContextMenu
,并将onPostExecute()
返回给活动,但收到了错误!
contactPHP.java 已修改
protected void onPostExecute(JSONArray json) {
main.contactPhpResponse(....);
}
contactActivity.java 已编辑
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)
表示此行this.onCreateContextMenu(menu, v, menuInfo);
答案 0 :(得分:4)
这是onCreateContextMenu
不是AsyncTask
的方法,因此你无法覆盖它。移入Activity
课程。另外,请尊重java命名约定。班级名称始终以大写字母开头。