无法使用json对象加载memtrack模块

时间:2018-12-06 14:33:35

标签: android json android-studio

在运行应用程序时,我在logcat窗口上遇到此错误“ Memtrack:无法加载memtrack模块” 错误。我应该创建一个json数组并解析它以便在logcat窗口中打印它。 以下代码出现此错误后。

因此,我无法在logcat中查看已解析的数组。

mainactivity.java

 public class MainActivity extends Activity {

 EditText cityName;

  public void findWeather(View view) {
    Log.i("cityName", cityName.getText().toString());
}

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    cityName = (EditText) findViewById(R.id.cityName);
    DownloadTask task = new DownloadTask();
    task.execute("https://api.openweathermap.org/data/2.5/weather?q=" + 
    cityName.getText().toString());


}

public class DownloadTask extends AsyncTask<String, Void, String> {

    @Override
    protected String doInBackground(String... urls) {
        String result = null;
        URL url;
        HttpURLConnection urlConnection = null;

        try {
            url = new URL(urls[0]);

            urlConnection = (HttpURLConnection) url.openConnection();

            InputStream in = urlConnection.getInputStream();

            InputStreamReader reader = new InputStreamReader(in);

            int data = reader.read();

            while (data != -1) {

                char current = (char) data;

                result = result + current;

                data = reader.read();

            }
            return result;

        } catch (MalformedURLException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }


       return "";
    }


    @Override

    protected void onPostExecute(String result) {
        super.onPostExecute(result);

            try {
                if (result != null) {

                    JSONObject jsonObject = new JSONObject(result);

                    String weatherInfo = 
                   jsonObject.getString("weather");


                    Log.i("weather content : ", weatherInfo);

                    JSONArray arr = new JSONArray(weatherInfo);

                    for (int i = 0; i < arr.length(); i++) {

                        JSONObject jsonPart = arr.getJSONObject(i);

                        Log.i("main", jsonPart.getString("main"));

                        Log.i("description", 
                   jsonPart.getString("description"));
                    }
                }
                result = null;
            }

                catch(JSONException e){
                e.printStackTrace();
               }
            }
         }
      }

xml代码:

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

   <ImageView
    android:id="@+id/imageView2"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_alignParentStart="true"
    android:layout_alignParentTop="true"
    android:layout_alignParentEnd="true"
    android:layout_marginStart="10dp"
    android:layout_marginLeft="10dp"
    android:layout_marginTop="0dp"
    android:layout_marginEnd="0dp"
    android:src="@drawable/background1"
    app:srcCompat="?attr/actionModeBackground" />

   <Button
    android:id="@+id/button"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="160dp"
    android:onClick="findWeather"
    android:text="WHAT'S THE WEATHER" />

    <TextView
    android:id="@+id/textView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignStart="@+id/button"
    android:layout_alignParentTop="true"
    android:layout_marginTop="12dp"
    android:text="Enter a city .."
    android:textColor="@android:color/background_light"
    android:textSize="40dp" />

    <EditText
    android:id="@+id/cityName"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignEnd="@+id/textView"
    android:layout_alignParentTop="true"
    android:layout_marginLeft="40dp"
    android:layout_marginTop="98dp"
    android:ems="10"
    android:inputType="textPersonName" />

    <TextView
    android:id="@+id/textView3"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_centerHorizontal="true"
    android:layout_marginBottom="115dp"
    android:text="TextView"
    android:textColor="@android:color/white"
    android:textSize="30sp" />

   </RelativeLayout>

android清单文件

    <uses-permission android:name="android.permission.INTERNET" />

*日志猫错误*

    --------- beginning of system
       2018-12-06 19:56:43.275 1758-1806/? E/storaged: getDiskStats failed 
       with result NOT_SUPPORTED and size 0
       2018-12-06 19:56:44.777 1828-2287/? W/audio_hw_generic: Not 
       supplying enough data to HAL, expected position 4159419 , only wrote 
       4006800
       2018-12-06 19:56:53.271 2045-2633/system_process 
       I/GnssLocationProvider: WakeLock acquired by 
      sendMessage(REPORT_SV_STATUS, 0, 
     com.android.server.location.GnssLocationProvider$SvStatusInfo@704cb9c)
      2018-12-06 19:56:53.272 2045-2063/system_process 
      I/GnssLocationProvider: WakeLock released by 
      handleMessage(REPORT_SV_STATUS, 0, 
     com.android.server.location.GnssLocationProvider$SvStatusInfo@704cb9c)
     2018-12-06 19:56:53.323 2960-7959/com.google.android.gms.persistent 
    W/ctxmgr: [AclManager]No 2 for (accnt=account#-517948760#, 
    com.google.android.gms(10020):IndoorOutdoorProducer, vrsn=12862000, 0, 
   3pPkg = null ,  3pMdlId = null ,  pid = 2960). Was: 3 for 57, 
    account#-517948760#
    2018-12-06 19:57:03.273 2045-2633/system_process 
    I/GnssLocationProvider: WakeLock acquired by 
    sendMessage(REPORT_SV_STATUS, 0, 
    com.android.server.location.GnssLocationProvider$SvStatusInfo@807717a)
    2018-12-06 19:57:03.275 2045-2063/system_process 
     I/GnssLocationProvider: WakeLock released by 
    handleMessage(REPORT_SV_STATUS, 0, 
    com.android.server.location.GnssLocationProvider$SvStatusInfo@807717a)
    2018-12-06 19:57:03.279 2960-7959/com.google.android.gms.persistent 
    W/ctxmgr: [AclManager]No 2 for (accnt=account#-517948760#, 
    com.google.android.gms(10020):IndoorOutdoorProducer, vrsn=12862000, 0, 
    3pPkg = null ,  3pMdlId = null ,  pid = 2960). Was: 3 for 57, 
    account#-517948760#
    2018-12-06 19:57:08.084 2960-7527/com.google.android.gms.persistent 
    E/WakeLock: GCM_HB_ALARM release without a matched acquire!
       2018-12-06 19:57:09.201 2045-4310/system_process E/memtrack: 
   Couldn't load memtrack module
     2018-12-06 19:57:09.201 2045-4310/system_process W/android.os.Debug: 
    failed to get memory consumption info: -1
    2018-12-06 19:57:13.274 2045-2633/system_process 
   I/GnssLocationProvider: WakeLock acquired by 
   sendMessage(REPORT_SV_STATUS, 0, 
   com.android.server.location.GnssLocationProvider$SvStatusInfo@42efb21)
    2018-12-06 19:57:13.275 2045-2063/system_process 
   I/GnssLocationProvider: WakeLock released by 
   handleMessage(REPORT_SV_STATUS, 0, 
   com.android.server.location.GnssLocationProvider$SvStatusInfo@42efb21)
    2018-12-06 19:57:13.279 2960-7894/com.google.android.gms.persistent 
    W/ctxmgr: [AclManager]No 2 for (accnt=account#-517948760#, 
   com.google.android.gms(10020):IndoorOutdoorProducer, vrsn=12862000, 0, 
    3pPkg = null ,  3pMdlId = null ,  pid = 2960). Was: 3 for 57, 
    account#-517948760#

0 个答案:

没有答案