我的 Volley 应用程序崩溃了,可能是在 listView 代码上

Volley 正在工作,当我关闭 listData 时,没有崩溃并且工作良好,但没有 listView:


package com.example.tronksinc4d;



import androidx.appcompat.app.AppCompatActivity;


import android.content.Context;

import android.content.Intent;

import android.database.DataSetObserver;

import android.os.Bundle;

import android.util.Log;

import android.view.LayoutInflater;

import android.view.View;

import android.view.ViewGroup;

import android.widget.BaseAdapter;

import android.widget.Button;

import android.widget.ImageView;

import android.widget.ListAdapter;

import android.widget.ListView;

import android.widget.TextView;


import com.android.volley.Request;

import com.android.volley.RequestQueue;

import com.android.volley.Response;

import com.android.volley.VolleyError;

import com.android.volley.toolbox.JsonObjectRequest;

import com.android.volley.toolbox.Volley;

import com.google.gson.JsonArray;

import com.google.gson.JsonObject;

import com.squareup.picasso.Picasso;

import com.squareup.picasso.PicassoProvider;


import org.json.JSONArray;

import org.json.JSONException;

import org.json.JSONObject;


import java.util.ArrayList;


public class Home extends AppCompatActivity {


       public static prefconfig prefcoonfig;

       private TextView helloo;

       RequestQueue requestQueue;

       String url = 

"https://tronksinc4d.000webhostapp.com/show_all_movies.php";

       ArrayList<listitem> listmovies = new ArrayList<listitem>();

       ListView listView;

       TextView text_total, try_data;


      @Override

   `enter code here`   protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_home);


        prefcoonfig = new prefconfig(this);

        helloo = (TextView) findViewById(R.id.hello);

        helloo.setText(" أهلا بك " + prefcoonfig.readname());


繁星coding
浏览 116回答 1
1回答

慕少森

从错误消息中可以清楚地看出尝试在空对象引用上调用虚拟方法 'void android.widget.TextView.setText(java.lang.CharSequence)' , textview 在getView中未正确初始化。正确的方法是&nbsp; &nbsp; &nbsp; &nbsp; LayoutInflater layoutInflater = getLayoutInflater();&nbsp; &nbsp; &nbsp; &nbsp; View view = layoutInflater.inflate(R.layout.row_item, null);&nbsp; &nbsp; &nbsp; &nbsp; TextView Title = (TextView) view.findViewById(R.id.text_view_title);&nbsp; &nbsp; &nbsp; &nbsp; TextView info = (TextView) view.findViewById(R.id.text_view_info);&nbsp; &nbsp; &nbsp; &nbsp; ImageView img = (ImageView) view.findViewById(R.id.row_img);
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java