简体   繁体   中英

Logcat error in android Studio

when I run my project then error show in log cat which is not understandable for me please anyone can help me what is the meaning of these errors mean what mistakes I am making in my codes. Even I download other projects from google, on the running same log cat is showing please help.

LogCat is here:-

02-03 12:09:05.115 7614-7614/com.example.administrator.mainpage E/GMPM: GoogleService failed to initialize, status: 10, Missing an expected resource: 'R.string.google_app_id' for initializing Google services.  Possible causes are missing google-services.json or com.google.gms.google-services gradle plugin.
02-03 12:09:05.115 7614-7614/com.example.administrator.mainpage E/GMPM: Scheduler not set. Not logging error/warn.
02-03 12:09:05.240 7614-7639/com.example.administrator.mainpage E/GMPM: Uploading is not possible. App measurement disabled
02-03 12:09:06.371 7614-7689/com.example.administrator.mainpage E/GED: Failed to get GED Log Buf, err(0)
02-03 12:09:06.471 7614-7614/com.example.administrator.mainpage E/AndroidRuntime: FATAL EXCEPTION: main                                                 Process: com.example.administrator.mainpage, PID: 7614
    java.lang.NullPointerException: Attempt to invoke interface method 'int java.util.List.size()' on a null object reference
    at android.widget.ArrayAdapter.getCount(ArrayAdapter.java:330)
    at android.widget.ListView.setAdapter(ListView.java:499)
    at com.example.administrator.mainpage.MainActivity$JSONTask.onPostExecute(MainActivity.java:56)
    at com.example.administrator.mainpage.MainActivity$JSONTask.onPostExecute(MainActivity.java:41)
    at android.os.AsyncTask.finish(AsyncTask.java:636)
    at android.os.AsyncTask.access$500(AsyncTask.java:177)
    at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:653)
    at android.os.Handler.dispatchMessage(Handler.java:111)
    at android.os.Looper.loop(Looper.java:194)
    at android.app.ActivityThread.main(ActivityThread.java:5649)
    at java.lang.reflect.Method.invoke(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:372)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:959)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:754)

This is code:-

  public class MainActivity extends AppCompatActivity {
      ListView lvCity;
      private static String url="14.140.200.186/Hospital/get_city.php";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.arjuncontent_main);
        new JSONTask().execute(url);

    }
    public class JSONTask extends AsyncTask<String,String, List<CityModel>>{
        private final ProgressDialog dialog = new ProgressDialog(MainActivity.this);

        @Override
        protected void onPreExecute() {
            super.onPreExecute();
            dialog.setMessage("Downloading Cities...");
            dialog.show();
        }

        @Override
        protected void onPostExecute( List<CityModel> result) {
            super.onPostExecute(result);
            CityAdapter adapter=new CityAdapter(getApplicationContext(),R.layout.city_single_row,result);
            lvCity = (ListView) findViewById(R.id.lvCity);
            lvCity.setAdapter(adapter);
        }
        public class CityAdapter extends ArrayAdapter {
            private List<CityModel> cityModelList;
            private int resource;
            private LayoutInflater inflater;
            public CityAdapter(Context context, int resource, List<CityModel> objects) {
                super(context, resource, objects);
                cityModelList=objects;
                this.resource=resource;
                inflater= (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
            }

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

                if (convertView==null)
                    convertView=inflater.inflate(resource,null);
                TextView cityname;
                TextView cityid;
                cityid= (TextView) convertView.findViewById(R.id.cityid);
                cityid.setText(cityModelList.get(position).getCity_id());
                cityname= (TextView)convertView.findViewById(R.id.cityname);
                cityname.setText(cityModelList.get(position).getCity_name());

                return  convertView;

            }
        }
        @Override
        protected  List<CityModel> doInBackground(String... params) {
            HttpURLConnection connection = null;
            BufferedReader reader = null;
            try {
                URL url = new URL(params[0]);
                connection = (HttpURLConnection) url.openConnection();
                connection.setRequestMethod("GET");
                connection.connect();
                InputStream stream = connection.getInputStream();
                reader = new BufferedReader(new InputStreamReader(stream));
                StringBuffer buffer = new StringBuffer();
                String line = "";
                while ((line = reader.readLine()) != null) {
                    buffer.append(line);
                }
                String finalJson=buffer.toString();
                JSONObject parentObject=new JSONObject(finalJson);
                JSONArray parentArray=parentObject.getJSONArray("Cities");
                List<CityModel>cityModelList=new ArrayList<>();
                for (int i=0; i<parentArray.length(); i++){
                    JSONObject finalObject = parentArray.getJSONObject(i);
                    CityModel cityModel=new CityModel();
                    cityModel.setCity_name(finalObject.getString("city_name"));
                    cityModel.setCity_id(finalObject.getString("city_id"));
                    cityModelList.add(cityModel);
                }
                return cityModelList;
            } catch (MalformedURLException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            } catch (JSONException e) {
                e.printStackTrace();
            } finally {
                if (connection != null)
                    connection.disconnect();
                ;
                try {
                    if (reader != null)
                        reader.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }

            }


            return null;
        }


    }

`

You need to download the configuration file from developer console and add it to your project. Second step of this link .

File name is google-services.json

问题是删除项目中的firebase组件后有firebase的痕迹,请确保删除中介中的文件

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM