gpt4 book ai didi

java - 没有虚方法 getLayoutInflater

转载 作者:行者123 更新时间:2023-11-30 00:03:47 27 4
gpt4 key购买 nike

<分区>

我正在尝试编写一个应用程序,从在线 MySQL 数据库下载某些事件的数据并将其写入我的 Android 应用程序。现在,我正在尝试做的只是测试下载事件名称是否有效,但我不断收到此错误:

java.lang.NoSuchMethodError: No virtual method getLayoutInflater()Landroid/view/LayoutInflater; in class Lcom/suspicio/appfisio_business/FrammentoCorsi; or its super classes (declaration of 'com.suspicio.appfisio_business.FrammentoCorsi' appears in /data/app/com.suspicio.appfisio_business-1/split_lib_slice_8_apk.apk)
at com.suspicio.appfisio_business.FrammentoCorsi$EventoAdapter.getView(FrammentoCorsi.java:204)

它指向的线:

listViewItem = getLayoutInflater().inflate(R.layout.frammento_corsi, null, true);

这是我的代码(它是一个 fragment ):

FrammentoCorsi.java:

public class FrammentoCorsi extends Fragment {

public static final int CODE_GET_REQUEST = 1024;
public static final int CODE_POST_REQUEST = 1025;

public FrammentoCorsi() { //Vuoto
}

boolean isUpdating = false;
View rootView;
List<Evento> eventoList;
ListView listView;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}


@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.frammento_corsi, container, false);
listView = (ListView) rootView.findViewById(R.id.listViewEventi);
return rootView;
}

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {

eventoList = new ArrayList<>();
readEventi();

}

private void readEventi() {
PerformNetworkRequest request = new PerformNetworkRequest(Api.URL_READ_EVENTI, null, CODE_GET_REQUEST);
request.execute();
}

private void refreshEventoList(JSONArray eventi) throws JSONException {
//clearing previous heroes
eventoList.clear();

//traversing through all the items in the json array
//the json we got from the response
for (int i = 0; i < eventi.length(); i++) {
//getting each hero object
JSONObject obj = eventi.getJSONObject(i);

//adding the hero to the list
eventoList.add(new Evento(
obj.getInt("id"),
obj.getString("titolo"),
obj.getString("inizio"),
obj.getString("fine"),
obj.getInt("categoria"),
obj.getString("link"),
obj.getString("luogo")
));
}

//creating the adapter and setting it to the listview
EventoAdapter adapter = new EventoAdapter(eventoList);
listView.setAdapter(adapter);
}

//inner class to perform network request extending an AsyncTask
public class PerformNetworkRequest extends AsyncTask<Void, Void, String> {

//the url where we need to send the request
String url;

//the parameters
HashMap<String, String> params;

//the request code to define whether it is a GET or POST
int requestCode;

ProgressBar barra = (ProgressBar) getView().findViewById(R.id.progressBar);

//constructor to initialize values
PerformNetworkRequest(String url, HashMap<String, String> params, int requestCode) {
this.url = url;
this.params = params;
this.requestCode = requestCode;
}

//when the task started displaying a progressbar
@Override
protected void onPreExecute() {
super.onPreExecute();
barra.setVisibility(View.VISIBLE);
}

//this method will give the response from the request
@Override
protected void onPostExecute(String s) {
super.onPostExecute(s);
barra.setVisibility(View.INVISIBLE);
try {
JSONObject object = new JSONObject(s);
if (!object.getBoolean("error")) {
Toast.makeText(getActivity().getApplicationContext(), object.getString("message"), Toast.LENGTH_SHORT).show();
refreshEventoList(object.getJSONArray("eventi"));
}
} catch (JSONException e) {
e.printStackTrace();
}
}

//the network operation will be performed in background
@Override
protected String doInBackground(Void... voids) {
RequestHandler requestHandler = new RequestHandler();

if (requestCode == CODE_POST_REQUEST)
return requestHandler.sendPostRequest(url, params);


if (requestCode == CODE_GET_REQUEST)
return requestHandler.sendGetRequest(url);

return null;
}
}

class EventoAdapter extends ArrayAdapter<Evento> {

List<Evento> eventoList;

//constructor to get the list
public EventoAdapter(List<Evento> eventoList) {
super(getActivity(), R.layout.frammento_corsi, eventoList);
this.eventoList = eventoList;
}

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

View listViewItem = convertView;
if (listViewItem == null) {
listViewItem = getLayoutInflater().inflate(R.layout.frammento_corsi, null, true);
}

//getting the textview for displaying name
TextView textViewName = listViewItem.findViewById(R.id.nomeeventocalendario);

//the update and delete textview
//ImageView textViewUpdate = listViewItem.findViewById(R.id.notifica);
//ImageView textViewDelete = listViewItem.findViewById(R.id.link);

final Evento evento = eventoList.get(position);

textViewName.setText(evento.getTitolo());

return listViewItem;


}

}

}

及其资源文件frammento_corsi.xml:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:context="com.suspicio.appfisio_business.FrammentoCorsi">

<ListView
android:id="@+id/listViewEventi"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>

<TextView
android:id="@+id/nomeeventocalendario"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>

<ProgressBar
android:id="@+id/progressBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:visibility="gone"/>

</FrameLayout>

你能帮帮我吗?

提前致谢!

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com