- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在我的应用程序中集成了 youtube channel ,但它没有显示所有视频。对于某些 channel ,它只显示很少的视频。如果我将 throw new RuntimeException(e);
while捕获 JSONException 应用程序崩溃并显示以下错误-
11-02 20:00:40.868: E/AndroidRuntime(15351): FATAL EXCEPTION: AsyncTask #1
11-02 20:00:40.868: E/AndroidRuntime(15351): java.lang.RuntimeException: An error occured while executing doInBackground()
11-02 20:00:40.868: E/AndroidRuntime(15351): at android.os.AsyncTask$3.done(AsyncTask.java:299)
11-02 20:00:40.868: E/AndroidRuntime(15351): at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
11-02 20:00:40.868: E/AndroidRuntime(15351): at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
11-02 20:00:40.868: E/AndroidRuntime(15351): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
11-02 20:00:40.868: E/AndroidRuntime(15351): at java.util.concurrent.FutureTask.run(FutureTask.java:137)
11-02 20:00:40.868: E/AndroidRuntime(15351): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
11-02 20:00:40.868: E/AndroidRuntime(15351): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
11-02 20:00:40.868: E/AndroidRuntime(15351): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
11-02 20:00:40.868: E/AndroidRuntime(15351): at java.lang.Thread.run(Thread.java:856)
11-02 20:00:40.868: E/AndroidRuntime(15351): Caused by: java.lang.RuntimeException: org.json.JSONException: No value for videoId
11-02 20:00:40.868: E/AndroidRuntime(15351): at com.wingnity.jsonparsingtutorial.SoundcloudActivity$JSONAsyncTask.doInBackground(SoundcloudActivity.java:223)
11-02 20:00:40.868: E/AndroidRuntime(15351): at com.wingnity.jsonparsingtutorial.SoundcloudActivity$JSONAsyncTask.doInBackground(SoundcloudActivity.java:1)
11-02 20:00:40.868: E/AndroidRuntime(15351): at android.os.AsyncTask$2.call(AsyncTask.java:287)
11-02 20:00:40.868: E/AndroidRuntime(15351): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
11-02 20:00:40.868: E/AndroidRuntime(15351): ... 5 more
11-02 20:00:40.868: E/AndroidRuntime(15351): Caused by: org.json.JSONException: No value for videoId
11-02 20:00:40.868: E/AndroidRuntime(15351): at org.json.JSONObject.get(JSONObject.java:354)
11-02 20:00:40.868: E/AndroidRuntime(15351): at org.json.JSONObject.getString(JSONObject.java:510)
11-02 20:00:40.868: E/AndroidRuntime(15351): at com.wingnity.jsonparsingtutorial.SoundcloudActivity$JSONAsyncTask.doInBackground(SoundcloudActivity.java:191)
11-02 20:00:40.868: E/AndroidRuntime(15351): ... 8 more
11-02 20:00:40.952: E/AppErrorDialog(348): Failed to get ILowStorageHandle instance
11-02 20:00:41.476: E/WindowManager(15351): Activity com.wingnity.jsonparsingtutorial.SoundcloudActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@41929000 that was originally added here
11-02 20:00:41.476: E/WindowManager(15351): android.view.WindowLeaked: Activity com.wingnity.jsonparsingtutorial.SoundcloudActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@41929000 that was originally added here
11-02 20:00:41.476: E/WindowManager(15351): at android.view.ViewRootImpl.<init>(ViewRootImpl.java:418)
11-02 20:00:41.476: E/WindowManager(15351): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:294)
11-02 20:00:41.476: E/WindowManager(15351): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:226)
这是我要整合的 channel -
http://www.youtube.com/user/BeingIndianchannel
它只显示最新的三个视频这是代码-
ArrayList<Channel> actorsList;
//private static String url = "https://www.googleapis.com/youtube/v3/search?key=xyz&channelId=UCdf6i1jTJl0TLzXc1KMDMKA&part=snippet,id&order=date&maxResults=20";
String videoid;
// JSON Node names
private static final String TAG_ITEMS = "items";
private static final String TAG_KIND = "kind";
private static final String TAG_ETAG = "etag";
private static final String TAG_ID = "id";
private static final String TAG_KINDV = "kind";
private static final String TAG_VIDEOID = "videoId";
private static final String TAG_SNIPPET = "snippet";
private static final String TAG_PUBLISHED = "publishedAt";
private static final String TAG_CHANNELID = "channelId";
private static final String TAG_TITLE = "title";
private static final String TAG_DESCRIPTION = "description";
private static final String TAG_THUMBNAILS = "thumbnails";
private static final String TAG_DEFAULT = "default";
private static final String TAG_URL = "url";
private static final String TAG_MEDIUM = "medium";
private static final String TAG_URL2 = "url";
private static final String TAG_HIGH = "high";
private static final String TAG_URL3 = "url";
private static final String TAG_CHANNEL = "channelTitle";
private static final String TAG_BROADCAST = "liveBroadcastContent";
ChannelAdapter adapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.youtubevidlist);
actorsList = new ArrayList<Channel>();
new JSONAsyncTask().execute("https://www.googleapis.com/youtube/v3/search?key=xyz&channelId=UChAlpEbfW1y9auiBC08ZwGQ&part=snippet,id&order=date&maxResults=20");
ListView listview = (ListView)findViewById(R.id.list);
adapter = new ChannelAdapter(getApplicationContext(), R.layout.row, actorsList);
listview.setAdapter(adapter);
listview.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int position,
long id) {
// TODO Auto-generated method stub
String name = ((TextView) arg1.findViewById(R.id.name_label))
.getText().toString();
Intent in = new Intent(getApplicationContext(),
YoutubeActivity2.class);
in.putExtra("TAG_VIDEOID", name);
startActivity(in);
;
}
});
}
class JSONAsyncTask extends AsyncTask<String, Void, Boolean> {
ProgressDialog dialog;
@Override
protected void onPreExecute()
{
super.onPreExecute();
dialog = new ProgressDialog(SoundcloudActivity.this);
dialog.setMessage("Loading, please wait");
dialog.setTitle("Connecting server");
dialog.show();
dialog.setCancelable(false);
}
@Override
protected Boolean doInBackground(String... urls) {
try {
//------------------>>
HttpGet httppost = new HttpGet(urls[0]);
HttpClient httpclient = new DefaultHttpClient();
HttpResponse response = httpclient.execute(httppost);
// StatusLine stat = response.getStatusLine();
int status = response.getStatusLine().getStatusCode();
if (status == 200) {
HttpEntity entity = response.getEntity();
String data = EntityUtils.toString(entity);
JSONObject jsono = new JSONObject(data);
JSONArray jarray = jsono.getJSONArray(TAG_ITEMS);
for (int i = 0; i < jarray.length(); i++) {
JSONObject c = jarray.getJSONObject(i);
Channel actor = new Channel();
actor.setKind(c.getString(TAG_KIND));
actor.setEtag(c.getString(TAG_ETAG));
JSONObject id = c.getJSONObject(TAG_ID);
actor.setKind2(id.getString(TAG_KINDV));
actor.setVideoid(id.getString(TAG_VIDEOID));
JSONObject snippet = c.getJSONObject(TAG_SNIPPET);
actor.setPublished(snippet.getString(TAG_PUBLISHED));
actor.setChannelid(snippet.getString(TAG_CHANNELID));
actor.setTitle(snippet.getString(TAG_TITLE));
actor.setDescription(snippet.getString(TAG_DESCRIPTION));
JSONObject thumbnail = snippet.getJSONObject(TAG_THUMBNAILS);
JSONObject defaul = thumbnail.getJSONObject(TAG_DEFAULT);
actor.setUri1(defaul.getString(TAG_URL));
JSONObject medium = thumbnail.getJSONObject(TAG_MEDIUM);
actor.setUri2(medium.getString(TAG_URL2));
JSONObject high = thumbnail.getJSONObject(TAG_HIGH);
actor.setUri3(high.getString(TAG_URL3));
actor.setChannel(snippet.getString(TAG_CHANNEL));
actor.setBroadcast(snippet.getString(TAG_BROADCAST));
actorsList.add(actor);
}
return true;
}
//------------------>>
} catch (ParseException e1) {
e1.printStackTrace();
Log.e("exception","ParseException");
} catch (IOException e) {
e.printStackTrace();
Log.e("exception","IOException");
} catch (JSONException e) {
e.printStackTrace();
throw new RuntimeException(e);
}
return false;
}
protected void onPostExecute(Boolean result) {
dialog.cancel();
adapter.notifyDataSetChanged();
if(result == false)
Toast.makeText(getApplicationContext(), "Unable to fetch data from server", Toast.LENGTH_LONG).show();
}
}
}
最佳答案
Caused by: org.json.JSONException: No value for videoId
根据 the API :
If the id.type property's value is youtube#video, then this property will be present and its value will contain the ID that YouTube uses to uniquely identify a video that matches the search query.
videoId
是可选值。在调用 JSONObject.getString()
之前,您需要使用 JSONObject.has()
检查它是否存在。
关于java - 加载集成的 youtube channel 视频时出现 JSONException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26701469/
我有 7 个协议(protocol),我想在网站上显示。但该网站仅显示 4 个协议(protocol),尽管 JSON 文件中有 7 个协议(protocol)。我决定用调试器检查一下,它通过了 4
我在此代码中遇到 JSON 异常: JSONObject jObject = new JSONObject(JSONString); pontosUsuario.setIdUsuari
我创建了以下价格和移动型号名称的 json 数组。此数据是从表名称为“products”的 wamp phpmyadmin 服务器读取的: { "products": [
我正在从 linkedHashMap 获取 JSON 值 LinkedHashMap lst = JsonPath.parse(json).read("$.projects[0].issuetypes
我正在尝试使用来自 Guardian API 的 JSON 对象。 这是我调用的结果: https://pastebin.com/wqggLEeZ 这是我的代码 JSONObject root = n
我正在尝试从数据库中检索数据。我向此 PHP 文件发送请求: $code, "message"=>$message); echo json_encode($err); }
JSONObject login = new JSONObject(); login.put("Key1", "Value1"); 我只是想用键值对创建一个简单的 JSON 对象。我收到此异常“Unh
我试图解析下面的 json 并在第 150 行(在代码中标记)捕获了 JSONException,但我无法弄清楚为什么会发生。目标是找到特定包的测试列表并将其存储在 arraylist 中。 当我将
我在解析 JSON 时遇到很多问题,其中一个值具有空值。 { "available_from" : "2012-11-05T00:00:00Z", "available_to" : "2012-11-
我有一个带有一些 spring crud 存储库的经典 spring web 应用程序。 我正在尝试以经典的 Angular 形式保存我的实体,但我随机收到此错误: .w.s.m.s.DefaultH
我正在尝试将字符串转换为 JSONObject。这是我的代码: JSONObject obj = new JSONObject(str); Vehicle.feature 文件包含: Scen
@Override protected Integer doInBackground(Void... params) { String readMyJSON = rea
我想解析一些从网上下载的 JSONArray 中的 json。我认为这很简单,但无法让它发挥作用。 看来问题出在 JSON 格式上。我尝试了不同的方法修复它,但没有任何帮助。 我用这种方法下载字符串:
我收到以下错误: JSONException: No value for error 在 Android Studio 中的我的日志(查看日志截图的链接: /image/45eeF.png )上,它说
它可以很好地从数据库读取和写入,但会给出 JSONException 错误。任何帮助将不胜感激! 谢谢 最佳答案 此错误发生在 JSONObject 的 getter 函数中,这意味着您尝试使用 JS
我想从此链接获取json数据:link &这是我的代码: private static String url = "https://graph.facebook.com/fql?q=SELECT%20
描述:在 OnRespose 方法中,我可以在日志中看到从 froecast.io 接收的数据,但是当我传递“response.body().string()”时,即来自 Forecast.io 的数
我正在尝试从此网址中抓取书名:http://api.nytimes.com/svc/books/v2/lists/2010-10-01/trade-fiction-paperback?api-key=
我一直在尝试在 android studio 中为我的应用程序创建一个登录系统,但我不断收到此错误 org.json.JSONException: Value Connection of type j
我有一个 iOS 应用程序和一个 Android 应用程序,可以使用 RESTFul Web 服务。 当我向服务进行查询时,我得到一个像这样返回的 JSON 对象。 [ { "
我是一名优秀的程序员,十分优秀!