Java 试图完成一个输入事件,但输入事件接收器已经被释放
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/33975140/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Attempted to finish an input event but the input event receiver has already been disposed
提问by Hilary Mwape
I am trying out a Tutorial i saw online,The app Gets and displays JSONfeed from server,this part works correctly,i am trying to display this feed in Custom listview but when i try to do so i get the "Attempted to finish an input event but the input event receiver has already been disposed" error in logcat and nothing happens in app,i have an adpter class:
我正在尝试我在网上看到的教程,该应用程序从服务器获取并显示 JSONfeed,这部分工作正常,我正在尝试在自定义列表视图中显示此提要,但是当我尝试这样做时,我收到“尝试完成输入事件,但输入事件接收器已被处理” logcat 中的错误,应用程序中没有任何反应,我有一个适配器类:
public class UserAdapter extends ArrayAdapter<UserData>{
private Context context;
private List<UserData> users_list;
public UserAdapter(Context context, int resource,List<UserData> objects) {
super(context, resource);
this.context= context;
this.users_list= objects;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater= (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View customview= inflater.inflate(R.layout.item_user, parent, false);
UserData userData= users_list.get(position);
TextView tv = (TextView) customview.findViewById(R.id.textview1);
tv.setText(userData.getName());
return customview;
}
}
My MainAtivity:
我的主要活动:
import android.app.ListActivity;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.AsyncTask;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Toast;
import java.util.ArrayList;
import java.util.List;
public class MainActivity extends ListActivity {
List<MyTask> tasks;
List<UserData> userDataList;
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
userDataList= new ArrayList<>();
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == R.id.ac) {
if (isOnline()) {
requestData("http://192.168.1.4/database/getInfoDroid.php");
} else {
Toast.makeText(MainActivity.this, "Network Unavailable", Toast.LENGTH_LONG).show();
}
return true;
}
return super.onOptionsItemSelected(item);
}
private void requestData(String uri) {
MyTask task=new MyTask();
task.execute(uri);
}
protected void updateDisplay(){
UserAdapter adapter= new UserAdapter(this,R.layout.item_user,userDataList);
setListAdapter(adapter);
}
protected boolean isOnline(){
ConnectivityManager cm= (ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE);
NetworkInfo netinfo= cm.getActiveNetworkInfo();
if(netinfo!= null && netinfo.isConnectedOrConnecting()){
return true;
}
else {
return false;
}
}
private class MyTask extends AsyncTask {
@Override
protected void onPreExecute() {
}
@Override
protected Object doInBackground(Object[] objects) {
System.out.print("Do in background ");
String content =HttpManager.getData(objects[0].toString());
System.out.print(content);
return content;
}
@Override
protected void onPostExecute(Object o) {
if (o.toString()==null){
Toast.makeText(MainActivity.this,"Cant connect to Web",Toast.LENGTH_LONG).show();
}
userDataList= UserDataJsonParser.parseFeed(o.toString());
System.out.print(userDataList);
updateDisplay();
}
@Override
protected void onProgressUpdate(Object[] values) {
//updateDisplay(values[0].toString());
}
}
}
LogCat:
日志猫:
11-28 20:50:12.115 28063-28078/hilz.myapplication W/EGL_emulation: eglSurfaceAttrib not implemented
11-28 20:50:12.115 28063-28078/hilz.myapplication W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0xa50c8260, error=EGL_SUCCESS
11-28 20:50:13.287 28063-28063/hilz.myapplication W/InputEventReceiver: Attempted to finish an input event but the input event receiver has already been disposed.
采纳答案by Emanuel Aliprantis
In your Public UserAdapter function, your super is not passing in the Objects.
在您的 Public UserAdapter 函数中,您的 super 没有传入对象。
It should be:
它应该是:
public UserAdapter(Context context, int resource,List<UserData> objects)
{
super(context, resource, objects);
this.context= context;
this.users_list= objects;
}
and not:
并不是:
public UserAdapter(Context context, int resource,List<UserData> objects)
{
super(context, resource);
this.context= context;
this.users_list= objects;
}