我正在尝试使用JSON中的Thingspeak检索数据以发布到我正在开发的移动应用程序(从Thingspeak获取JSON响应:link)。我创建了一个测试应用程序,只需在TextView
中设置从Thingspeak收到的值,但应用程序屏幕上没有显示任何内容。 logcat没有任何与此相关的错误,但有一些警告在应用程序中显示甚至没有(没有任何JSON代码)
这是MainActivity.java
:
package com.example.teerna.testapp;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.os.AsyncTask;
import android.util.Log;
import android.widget.TextView;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.MalformedURLException;
import java.io.BufferedReader;
import java.io.IOException;
public class MainActivity extends AppCompatActivity {
TextView tv;
@Override
protected void onCreate(Bundle savedInstanceState) {
setTheme(R.style.MyAppTheme);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tv =(TextView)findViewById(R.id.aTextView);
new GetMethodDemo().execute();
}
public class GetMethodDemo extends AsyncTask<String , Void ,String> {
String server_response;
@Override
protected String doInBackground(String... strings) {
//URL url;
HttpURLConnection urlConnection = null;
try {
URL url = new URL("https://api.thingspeak.com/channels/357670/feeds/last");
urlConnection = (HttpURLConnection) url.openConnection();
int responseCode = urlConnection.getResponseCode();
if(responseCode == HttpURLConnection.HTTP_OK){
server_response = readStream(urlConnection.getInputStream());
Log.v("CatalogClient", server_response);
}
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
// Converting InputStream to String
private String readStream(InputStream in) {
BufferedReader reader = null;
StringBuffer response = new StringBuffer();
try {
reader = new BufferedReader(new InputStreamReader(in, "UTF-8"));
String line = "";
while ((line = reader.readLine()) != null) {
response.append(line);
}
} catch (IOException e) {
e.printStackTrace();
} finally {
if (reader != null) {
try {
reader.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
return response.toString();
}
@Override
protected void onPostExecute(String response) {
super.onPostExecute(response);
if (response != null) {
String item=null;
try {
JSONObject json = new JSONObject(response);
JSONObject jsonResponse = json.getJSONObject("Response");
item = jsonResponse.getString("created_at");
} catch (JSONException j) {
j.printStackTrace();
}
Log.e("Response", "" + server_response);
tv.setText(String.valueOf(item));
}
}
}
}
logcat的:
12-11 13:46:44.122 12483-12483/com.example.teerna.testapp I/dalvikvm: Could not find method android.view.Window$Callback.onPointerCaptureChanged, referenced from method android.support.v7.view.WindowCallbackWrapper.onPointerCaptureChanged
12-11 13:46:44.122 12483-12483/com.example.teerna.testapp W/dalvikvm: VFY: unable to resolve interface method 15988: Landroid/view/Window$Callback;.onPointerCaptureChanged (Z)V
12-11 13:46:44.122 12483-12483/com.example.teerna.testapp D/dalvikvm: VFY: replacing opcode 0x72 at 0x0002
12-11 13:46:44.122 12483-12483/com.example.teerna.testapp I/dalvikvm: Could not find method android.view.Window$Callback.onProvideKeyboardShortcuts, referenced from method android.support.v7.view.WindowCallbackWrapper.onProvideKeyboardShortcuts
12-11 13:46:44.122 12483-12483/com.example.teerna.testapp W/dalvikvm: VFY: unable to resolve interface method 15990: Landroid/view/Window$Callback;.onProvideKeyboardShortcuts (Ljava/util/List;Landroid/view/Menu;I)V
12-11 13:46:44.122 12483-12483/com.example.teerna.testapp D/dalvikvm: VFY: replacing opcode 0x72 at 0x0002
12-11 13:46:44.122 12483-12483/com.example.teerna.testapp W/dalvikvm: VFY: unable to find class referenced in signature (Landroid/view/SearchEvent;)
12-11 13:46:44.122 12483-12483/com.example.teerna.testapp I/dalvikvm: Could not find method android.view.Window$Callback.onSearchRequested, referenced from method android.support.v7.view.WindowCallbackWrapper.onSearchRequested
12-11 13:46:44.122 12483-12483/com.example.teerna.testapp W/dalvikvm: VFY: unable to resolve interface method 15992: Landroid/view/Window$Callback;.onSearchRequested (Landroid/view/SearchEvent;)Z
12-11 13:46:44.122 12483-12483/com.example.teerna.testapp D/dalvikvm: VFY: replacing opcode 0x72 at 0x0002
12-11 13:46:44.122 12483-12483/com.example.teerna.testapp I/dalvikvm: Could not find method android.view.Window$Callback.onWindowStartingActionMode, referenced from method android.support.v7.view.WindowCallbackWrapper.onWindowStartingActionMode
12-11 13:46:44.122 12483-12483/com.example.teerna.testapp W/dalvikvm: VFY: unable to resolve interface method 15996: Landroid/view/Window$Callback;.onWindowStartingActionMode (Landroid/view/ActionMode$Callback;I)Landroid/view/ActionMode;
12-11 13:46:44.122 12483-12483/com.example.teerna.testapp D/dalvikvm: VFY: replacing opcode 0x72 at 0x0002
12-11 13:46:44.122 12483-12483/com.example.teerna.testapp I/dalvikvm: Could not find method android.content.res.TypedArray.getChangingConfigurations, referenced from method android.support.v7.widget.TintTypedArray.getChangingConfigurations
12-11 13:46:44.122 12483-12483/com.example.teerna.testapp W/dalvikvm: VFY: unable to resolve virtual method 704: Landroid/content/res/TypedArray;.getChangingConfigurations ()I
12-11 13:46:44.122 12483-12483/com.example.teerna.testapp D/dalvikvm: VFY: replacing opcode 0x6e at 0x0002
12-11 13:46:44.152 12483-12483/com.example.teerna.testapp I/dalvikvm: Could not find method android.content.res.TypedArray.getType, referenced from method android.support.v7.widget.TintTypedArray.getType
12-11 13:46:44.152 12483-12483/com.example.teerna.testapp W/dalvikvm: VFY: unable to resolve virtual method 726: Landroid/content/res/TypedArray;.getType (I)I
12-11 13:46:44.152 12483-12483/com.example.teerna.testapp D/dalvikvm: VFY: replacing opcode 0x6e at 0x0008
12-11 13:46:44.192 12483-12483/com.example.teerna.testapp I/dalvikvm: Could not find method android.content.Context.createDeviceProtectedStorageContext, referenced from method android.support.v4.content.ContextCompat.createDeviceProtectedStorageContext
12-11 13:46:44.192 12483-12483/com.example.teerna.testapp W/dalvikvm: VFY: unable to resolve virtual method 485: Landroid/content/Context;.createDeviceProtectedStorageContext ()Landroid/content/Context;
12-11 13:46:44.192 12483-12483/com.example.teerna.testapp D/dalvikvm: VFY: replacing opcode 0x6e at 0x0006
12-11 13:46:44.192 12483-12483/com.example.teerna.testapp I/dalvikvm: Could not find method android.content.Context.getCodeCacheDir, referenced from method android.support.v4.content.ContextCompat.getCodeCacheDir
12-11 13:46:44.192 12483-12483/com.example.teerna.testapp W/dalvikvm: VFY: unable to resolve virtual method 491: Landroid/content/Context;.getCodeCacheDir ()Ljava/io/File;
12-11 13:46:44.192 12483-12483/com.example.teerna.testapp D/dalvikvm: VFY: replacing opcode 0x6e at 0x0006
12-11 13:46:44.192 12483-12483/com.example.teerna.testapp I/dalvikvm: Could not find method android.content.Context.getColor, referenced from method android.support.v4.content.ContextCompat.getColor
12-11 13:46:44.192 12483-12483/com.example.teerna.testapp W/dalvikvm: VFY: unable to resolve virtual method 492: Landroid/content/Context;.getColor (I)I
12-11 13:46:44.192 12483-12483/com.example.teerna.testapp D/dalvikvm: VFY: replacing opcode 0x6e at 0x0006
12-11 13:46:44.192 12483-12483/com.example.teerna.testapp I/dalvikvm: Could not find method android.content.Context.getColorStateList, referenced from method android.support.v4.content.ContextCompat.getColorStateList
12-11 13:46:44.192 12483-12483/com.example.teerna.testapp W/dalvikvm: VFY: unable to resolve virtual method 493: Landroid/content/Context;.getColorStateList (I)Landroid/content/res/ColorStateList;
12-11 13:46:44.192 12483-12483/com.example.teerna.testapp D/dalvikvm: VFY: replacing opcode 0x6e at 0x0006
12-11 13:46:44.192 12483-12483/com.example.teerna.testapp I/dalvikvm: Could not find method android.content.Context.getDataDir, referenced from method android.support.v4.content.ContextCompat.getDataDir
12-11 13:46:44.192 12483-12483/com.example.teerna.testapp W/dalvikvm: VFY: unable to resolve virtual method 495: Landroid/content/Context;.getDataDir ()Ljava/io/File;
12-11 13:46:44.192 12483-12483/com.example.teerna.testapp D/dalvikvm: VFY: replacing opcode 0x6e at 0x0006
12-11 13:46:44.192 12483-12483/com.example.teerna.testapp I/dalvikvm: Could not find method android.content.Context.getDrawable, referenced from method android.support.v4.content.ContextCompat.getDrawable
12-11 13:46:44.192 12483-12483/com.example.teerna.testapp W/dalvikvm: VFY: unable to resolve virtual method 496: Landroid/content/Context;.getDrawable (I)Landroid/graphics/drawable/Drawable;
12-11 13:46:44.192 12483-12483/com.example.teerna.testapp D/dalvikvm: VFY: replacing opcode 0x6e at 0x0006
12-11 13:46:44.192 12483-12483/com.example.teerna.testapp I/dalvikvm: Could not find method android.content.Context.getExternalCacheDirs, referenced from method android.support.v4.content.ContextCompat.getExternalCacheDirs
12-11 13:46:44.192 12483-12483/com.example.teerna.testapp W/dalvikvm: VFY: unable to resolve virtual method 498: Landroid/content/Context;.getExternalCacheDirs ()[Ljava/io/File;
12-11 13:46:44.192 12483-12483/com.example.teerna.testapp D/dalvikvm: VFY: replacing opcode 0x6e at 0x0006
12-11 13:46:44.192 12483-12483/com.example.teerna.testapp I/dalvikvm: Could not find method android.content.Context.getExternalFilesDirs, referenced from method android.support.v4.content.ContextCompat.getExternalFilesDirs
12-11 13:46:44.192 12483-12483/com.example.teerna.testapp W/dalvikvm: VFY: unable to resolve virtual method 500: Landroid/content/Context;.getExternalFilesDirs (Ljava/lang/String;)[Ljava/io/File;
12-11 13:46:44.192 12483-12483/com.example.teerna.testapp D/dalvikvm: VFY: replacing opcode 0x6e at 0x0006
12-11 13:46:44.192 12483-12483/com.example.teerna.testapp I/dalvikvm: Could not find method android.content.Context.getNoBackupFilesDir, referenced from method android.support.v4.content.ContextCompat.getNoBackupFilesDir
12-11 13:46:44.192 12483-12483/com.example.teerna.testapp W/dalvikvm: VFY: unable to resolve virtual method 503: Landroid/content/Context;.getNoBackupFilesDir ()Ljava/io/File;
12-11 13:46:44.192 12483-12483/com.example.teerna.testapp D/dalvikvm: VFY: replacing opcode 0x6e at 0x0006
12-11 13:46:44.192 12483-12483/com.example.teerna.testapp I/dalvikvm: Could not find method android.content.Context.getObbDirs, referenced from method android.support.v4.content.ContextCompat.getObbDirs
12-11 13:46:44.192 12483-12483/com.example.teerna.testapp W/dalvikvm: VFY: unable to resolve virtual method 505: Landroid/content/Context;.getObbDirs ()[Ljava/io/File;
12-11 13:46:44.192 12483-12483/com.example.teerna.testapp D/dalvikvm: VFY: replacing opcode 0x6e at 0x0006
12-11 13:46:44.202 12483-12483/com.example.teerna.testapp I/dalvikvm: Could not find method android.content.Context.isDeviceProtectedStorage, referenced from method android.support.v4.content.ContextCompat.isDeviceProtectedStorage
12-11 13:46:44.202 12483-12483/com.example.teerna.testapp W/dalvikvm: VFY: unable to resolve virtual method 516: Landroid/content/Context;.isDeviceProtectedStorage ()Z
12-11 13:46:44.202 12483-12483/com.example.teerna.testapp D/dalvikvm: VFY: replacing opcode 0x6e at 0x0006
12-11 13:46:44.202 12483-12483/com.example.teerna.testapp I/dalvikvm: Could not find method android.content.Context.startForegroundService, referenced from method android.support.v4.content.ContextCompat.startForegroundService
12-11 13:46:44.202 12483-12483/com.example.teerna.testapp W/dalvikvm: VFY: unable to resolve virtual method 531: Landroid/content/Context;.startForegroundService (Landroid/content/Intent;)Landroid/content/ComponentName;
12-11 13:46:44.202 12483-12483/com.example.teerna.testapp D/dalvikvm: VFY: replacing opcode 0x6e at 0x0006
12-11 13:46:44.442 12483-12483/com.example.teerna.testapp I/dalvikvm: Could not find method android.widget.FrameLayout.startActionModeForChild, referenced from method android.support.v7.widget.ActionBarContainer.startActionModeForChild
12-11 13:46:44.442 12483-12483/com.example.teerna.testapp W/dalvikvm: VFY: unable to resolve virtual method 16457: Landroid/widget/FrameLayout;.startActionModeForChild (Landroid/view/View;Landroid/view/ActionMode$Callback;I)Landroid/view/ActionMode;
12-11 13:46:44.442 12483-12483/com.example.teerna.testapp D/dalvikvm: VFY: replacing opcode 0x6f at 0x0002
12-11 13:46:44.462 12483-12483/com.example.teerna.testapp I/dalvikvm: Could not find method android.content.Context.getColorStateList, referenced from method android.support.v7.content.res.AppCompatResources.getColorStateList
12-11 13:46:44.462 12483-12483/com.example.teerna.testapp W/dalvikvm: VFY: unable to resolve virtual method 493: Landroid/content/Context;.getColorStateList (I)Landroid/content/res/ColorStateList;
12-11 13:46:44.462 12483-12483/com.example.teerna.testapp D/dalvikvm: VFY: replacing opcode 0x6e at 0x0006
12-11 13:46:44.492 12483-12483/com.example.teerna.testapp W/dalvikvm: VFY: unable to find class referenced in signature (Landroid/graphics/drawable/Icon;)
12-11 13:46:44.492 12483-12483/com.example.teerna.testapp I/dalvikvm: Could not find method android.widget.ImageButton.setImageIcon, referenced from method android.support.v7.widget.AppCompatImageButton.setImageIcon
12-11 13:46:44.492 12483-12483/com.example.teerna.testapp W/dalvikvm: VFY: unable to resolve virtual method 16480: Landroid/widget/ImageButton;.setImageIcon (Landroid/graphics/drawable/Icon;)V
12-11 13:46:44.492 12483-12483/com.example.teerna.testapp D/dalvikvm: VFY: replacing opcode 0x6f at 0x0000
12-11 13:46:44.492 12483-12483/com.example.teerna.testapp I/dalvikvm: Could not find method android.content.res.Resources.getDrawable, referenced from method android.support.v7.widget.ResourcesWrapper.getDrawable
12-11 13:46:44.492 12483-12483/com.example.teerna.testapp W/dalvikvm: VFY: unable to resolve virtual method 667: Landroid/content/res/Resources;.getDrawable (ILandroid/content/res/Resources$Theme;)Landroid/graphics/drawable/Drawable;
12-11 13:46:44.492 12483-12483/com.example.teerna.testapp D/dalvikvm: VFY: replacing opcode 0x6e at 0x0002
12-11 13:46:44.492 12483-12483/com.example.teerna.testapp I/dalvikvm: Could not find method android.content.res.Resources.getDrawableForDensity, referenced from method android.support.v7.widget.ResourcesWrapper.getDrawableForDensity
12-11 13:46:44.492 12483-12483/com.example.teerna.testapp W/dalvikvm: VFY: unable to resolve virtual method 669: Landroid/content/res/Resources;.getDrawableForDensity (IILandroid/content/res/Resources$Theme;)Landroid/graphics/drawable/Drawable;
12-11 13:46:44.492 12483-12483/com.example.teerna.testapp D/dalvikvm: VFY: replacing opcode 0x6e at 0x0002
12-11 13:46:44.532 12483-12483/com.example.teerna.testapp E/dalvikvm: Could not find class 'android.graphics.drawable.RippleDrawable', referenced from method android.support.v7.widget.AppCompatImageHelper.hasOverlappingRendering
12-11 13:46:44.532 12483-12483/com.example.teerna.testapp W/dalvikvm: VFY: unable to resolve instanceof 193 (Landroid/graphics/drawable/RippleDrawable;) in Landroid/support/v7/widget/AppCompatImageHelper;
12-11 13:46:44.532 12483-12483/com.example.teerna.testapp D/dalvikvm: VFY: replacing opcode 0x20 at 0x000c
12-11 13:46:44.632 12483-12483/com.example.teerna.testapp I/dalvikvm: Could not find method android.widget.TextView.getAutoSizeMaxTextSize, referenced from method android.support.v7.widget.AppCompatTextView.getAutoSizeMaxTextSize
12-11 13:46:44.632 12483-12483/com.example.teerna.testapp W/dalvikvm: VFY: unable to resolve virtual method 16776: Landroid/widget/TextView;.getAutoSizeMaxTextSize ()I
12-11 13:46:44.632 12483-12483/com.example.teerna.testapp D/dalvikvm: VFY: replacing opcode 0x6f at 0x0006
12-11 13:46:44.632 12483-12483/com.example.teerna.testapp I/dalvikvm: Could not find method android.widget.TextView.getAutoSizeMinTextSize, referenced from method android.support.v7.widget.AppCompatTextView.getAutoSizeMinTextSize
12-11 13:46:44.632 12483-12483/com.example.teerna.testapp W/dalvikvm: VFY: unable to resolve virtual method 16777: Landroid/widget/TextView;.getAutoSizeMinTextSize ()I
12-11 13:46:44.632 12483-12483/com.example.teerna.testapp D/dalvikvm: VFY: replacing opcode 0x6f at 0x0006
12-11 13:46:44.632 12483-12483/com.example.teerna.testapp I/dalvikvm: Could not find method android.widget.TextView.getAutoSizeStepGranularity, referenced from method android.support.v7.widget.AppCompatTextView.getAutoSizeStepGranularity
12-11 13:46:44.632 12483-12483/com.example.teerna.testapp W/dalvikvm: VFY: unable to resolve virtual method 16778: Landroid/widget/TextView;.getAutoSizeStepGranularity ()I
12-11 13:46:44.632 12483-12483/com.example.teerna.testapp D/dalvikvm: VFY: replacing opcode 0x6f at 0x0006
12-11 13:46:44.632 12483-12483/com.example.teerna.testapp I/dalvikvm: Could not find method android.widget.TextView.getAutoSizeTextAvailableSizes, referenced from method android.support.v7.widget.AppCompatTextView.getAutoSizeTextAvailableSizes
12-11 13:46:44.632 12483-12483/com.example.teerna.testapp W/dalvikvm: VFY: unable to resolve virtual method 16779: Landroid/widget/TextView;.getAutoSizeTextAvailableSizes ()[I
12-11 13:46:44.632 12483-12483/com.example.teerna.testapp D/dalvikvm: VFY: replacing opcode 0x6f at 0x0006
12-11 13:46:44.632 12483-12483/com.example.teerna.testapp I/dalvikvm: Could not find method android.widget.TextView.getAutoSizeTextType, referenced from method android.support.v7.widget.AppCompatTextView.getAutoSizeTextType
12-11 13:46:44.632 12483-12483/com.example.teerna.testapp W/dalvikvm: VFY: unable to resolve virtual method 16780: Landroid/widget/TextView;.getAutoSizeTextType ()I
12-11 13:46:44.632 12483-12483/com.example.teerna.testapp D/dalvikvm: VFY: replacing opcode 0x6f at 0x0008
12-11 13:46:44.632 12483-12483/com.example.teerna.testapp I/dalvikvm: Could not find method android.widget.TextView.setAutoSizeTextTypeUniformWithConfiguration, referenced from method android.support.v7.widget.AppCompatTextView.setAutoSizeTextTypeUniformWithConfiguration
12-11 13:46:44.632 12483-12483/com.example.teerna.testapp W/dalvikvm: VFY: unable to resolve virtual method 16823: Landroid/widget/TextView;.setAutoSizeTextTypeUniformWithConfiguration (IIII)V
12-11 13:46:44.632 12483-12483/com.example.teerna.testapp D/dalvikvm: VFY: replacing opcode 0x6f at 0x0006
12-11 13:46:44.632 12483-12483/com.example.teerna.testapp I/dalvikvm: Could not find method android.widget.TextView.setAutoSizeTextTypeUniformWithPresetSizes, referenced from method android.support.v7.widget.AppCompatTextView.setAutoSizeTextTypeUniformWithPresetSizes
12-11 13:46:44.632 12483-12483/com.example.teerna.testapp W/dalvikvm: VFY: unable to resolve virtual method 16824: Landroid/widget/TextView;.setAutoSizeTextTypeUniformWithPresetSizes ([II)V
12-11 13:46:44.632 12483-12483/com.example.teerna.testapp D/dalvikvm: VFY: replacing opcode 0x6f at 0x0006
12-11 13:46:44.632 12483-12483/com.example.teerna.testapp I/dalvikvm: Could not find method android.widget.TextView.setAutoSizeTextTypeWithDefaults, referenced from method android.support.v7.widget.AppCompatTextView.setAutoSizeTextTypeWithDefaults
12-11 13:46:44.632 12483-12483/com.example.teerna.testapp W/dalvikvm: VFY: unable to resolve virtual method 16825: Landroid/widget/TextView;.setAutoSizeTextTypeWithDefaults (I)V
12-11 13:46:44.632 12483-12483/com.example.teerna.testapp D/dalvikvm: VFY: replacing opcode 0x6f at 0x0006
12-11 13:46:44.742 12483-12483/com.example.teerna.testapp I/dalvikvm: Could not find method android.widget.TextView.getAutoSizeStepGranularity, referenced from method android.support.v7.widget.AppCompatTextHelper.loadFromAttributes
12-11 13:46:44.742 12483-12483/com.example.teerna.testapp W/dalvikvm: VFY: unable to resolve virtual method 16778: Landroid/widget/TextView;.getAutoSizeStepGranularity ()I
12-11 13:46:44.742 12483-12483/com.example.teerna.testapp D/dalvikvm: VFY: replacing opcode 0x6e at 0x0197
12-11 13:46:44.742 12483-12483/com.example.teerna.testapp I/dalvikvm: Could not find method android.text.StaticLayout$Builder.obtain, referenced from method android.support.v7.widget.AppCompatTextViewAutoSizeHelper.createStaticLayoutForMeasuring
12-11 13:46:44.742 12483-12483/com.example.teerna.testapp W/dalvikvm: VFY: unable to resolve static method 15266: Landroid/text/StaticLayout$Builder;.obtain (Ljava/lang/CharSequence;IILandroid/text/TextPaint;I)Landroid/text/StaticLayout$Builder;
12-11 13:46:44.742 12483-12483/com.example.teerna.testapp D/dalvikvm: VFY: replacing opcode 0x71 at 0x0014
12-11 13:46:44.742 12483-12483/com.example.teerna.testapp I/dalvikvm: Could not find method android.widget.TextView.isInLayout, referenced from method android.support.v7.widget.AppCompatTextViewAutoSizeHelper.setRawTextSize
12-11 13:46:44.742 12483-12483/com.example.teerna.testapp W/dalvikvm: VFY: unable to resolve virtual method 16815: Landroid/widget/TextView;.isInLayout ()Z
12-11 13:46:44.742 12483-12483/com.example.teerna.testapp D/dalvikvm: VFY: replacing opcode 0x6e at 0x0021
12-11 13:46:45.053 12483-12483/com.example.teerna.testapp D/libEGL: loaded /system/lib/egl/libGLES_java.so