在具有显示java.lang.NullPointerException的Andr​​oid客户端的YouTube [英] YouTube Client on Android having a java.lang.NullPointerException

查看:250
本文介绍了在具有显示java.lang.NullPointerException的Andr​​oid客户端的YouTube的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

现在我知道这个问题,但还是不知道该如何解决呢,resquest是由谷歌,而不是我续约的关键事实拒绝,在此之前的工作,现在它给了我这个错误:我prefererBlocked :消息:有你的API密钥配置每个IP或每个Referer的限制和要求不符合这些限制,请使用谷歌开发者控制台更新您的API密钥。配置如果从这个IP或引荐请求应该被允许。
因为请求被拒绝返回的列表为空。

******老问题*******

我试着沿SICE时间创建YouTube客户端应用程序,但whenevr它拼命地跑它与一个NullPointerException异常停止。
SearchActivity.java有重新present意见activity_search.xml领域。它也有一个处理程序,使用户界面线程更新。
在onCreate方法,我们初始化的意见,并添加一个OnEditorActionListener到的EditText知道当用户完成输入关键字。
即时通讯使用我的三星S3与棒棒糖的Andr​​oid,如果可以使差异。
请帮我出这个问题...

 显示java.lang.NullPointerException:尝试对空对象引用调用接口方法'廉政java.util.List.size()
在android.widget.ArrayAdapter.getCount(ArrayAdapter.java:330​​)
在android.widget.ListView.setAdapter(ListView.java:487)
在leader.org.sqwatch.SearchActivity.updateVideosFound(SearchActivity.java:99)
在leader.org.sqwatch.SearchActivity.access $ 200(SearchActivity.java:33)
在leader.org.sqwatch.SearchActivity $ 2 $ 1.run(SearchActivity.java:72)
在android.os.Handler.handleCallback(Handler.java:739)
在android.os.Handler.dispatchMessage(Handler.java:95)
在android.os.Looper.loop(Looper.java:135)
在android.app.ActivityThread.main(ActivityThread.java:5256)
在java.lang.reflect.Method.invoke(本机方法)
在java.lang.reflect.Method.invoke(Method.java:372)
在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:898)
在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:693)

这是为SearchActivity:

 公共类SearchActivity延伸活动{
    私人的EditText searchInput;
    私人的ListView videosFound;
    私人处理程序处理程序;
    私人列表< VideoItem>搜索结果;    @覆盖
    保护无效的onCreate(捆绑savedInstanceState){
        super.onCreate(savedInstanceState);
        的setContentView(R.layout.activity_search);
        sea​​rchInput =(EditText上)findViewById(R.id.search_input);
        videosFound =(ListView控件)findViewById(R.id.videos_found);
        处理器=新的处理程序();
        sea​​rchInput.setOnEditorActionListener(
                新TextView.OnEditorActionListener(){
                    @覆盖
                    公共布尔onEditorAction(TextView的V,INT actionId,KeyEvent的事件){
                        如果(actionId == EditorInfo.IME_ACTION_DONE){
                            sea​​rchOnYoutube(v.getText()的toString());
                            返回false;
                        }
                        返回true;
                    }
                }
        );
    }    私人无效searchOnYoutube(最后弦乐关键字){
        新的Thread(){
            公共无效的run(){
                YoutubeConnector YC =新YoutubeConnector(SearchActivity.this);
                的SearchResult = yc.search(关键字);
                handler.post(新的Runnable(){
                    公共无效的run(){
                        updateVideosFound();
                    }
                });
            }
        }。开始();
    }    私人无效updateVideosFound(){
        ArrayAdapter< VideoItem>适配器=新ArrayAdapter< VideoItem>
                (getApplicationContext(),R.layout.video_item,SearchResult所){
            @覆盖
            公共查看getView(INT位置,查看convertView,父母的ViewGroup){
                如果(convertView == NULL){
                    convertView = getLayoutInflater()。膨胀(R.layout.video_item,父母,
                            假);
                }
                ImageView的缩略图=
                        (ImageView的)convertView.findViewById(R.id.video_thumbnail);
                TextView的标题=(TextView中)convertView.findViewById(R.id.video_title);
                TextView中描述=
                        (TextView中)convertView.findViewById(R.id.video_description);
                VideoItem的SearchResult = searchResults.get(位置);
                Picasso.with(getApplicationContext())。负载(SearchResult中。
                        getThumbnailURL())到(缩略图)。
                title.setText(searchResult.getTitle());
                description.setText(searchResult.getDescription());
                返回convertView;
            }
        };
        videosFound.setAdapter(适配器);
    }    私人无效addClickListener(){
        videosFound.setOnItemClickListener(新适配器视图。
                OnItemClickListener(){
            @覆盖
            公共无效onItemClick(适配器视图<> AV,视图V,INT POS,长I​​D){
                意向意图=新意图(getApplicationContext()
                        PlayerActivity.class);
                intent.putExtra(VIDEO_ID,searchResults.get(POS).getId());
                startActivity(意向);
            }
        });
    }
}

这是activity_search.xml code:

 <?XML版本=1.0编码=UTF-8&GT?;
<的LinearLayout机器人:layout_height =match_parent
    机器人:layout_width =match_parent
    机器人:方向=垂直
    的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android>
    < EditText上的android:提示=@字符串/搜索
        机器人:ID =@ + ID / SEARCH_INPUT
        机器人:layout_height =WRAP_CONTENT
        机器人:layout_width =match_parent
        机器人:单线=真
        机器人:文字=搞笑/>
    < ListView的机器人:dividerHeight =5DP
        机器人:ID =@ + ID / videos_found
        机器人:layout_height =match_parent
        机器人:layout_width =match_parent/>
< / LinearLayout中>


解决方案

真的遇到我只是删除所有允许应用程序在谷歌控制台中的指
我开了:API放大器;认证/凭据,然后单击编辑允许参照网址清空输入字段。

感谢您ρяσѕρєяK代表你的帮助。

Now I know the problem but still no idea how to resolve it, the resquest is rejected by google instead of the fact that I renewed the key, and it was working before, now it gives me this error: ipRefererBlocked : "message": "There is a per-IP or per-Referer restriction configured on your API key and the request does not match these restrictions. Please use the Google Developers Console to update your API key configuration if request from this IP or referer should be allowed." the list returned is null since the request is rejected.

******the Old issue*******

Im trying sice along time to create a youtube client app, but whenevr it is runned it stops with a NullPointerException. SearchActivity.java has fields that represent the views activity_search.xml. It also has a Handler to make updates on the user interface thread. In the onCreate method, we initialize the views and add an OnEditorActionListener to the EditText to know when the user has finished entering keywords. Im using my samsung S3 with a lollipop android, if that can make difference. Please help me out with this issue...

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:487)
at leader.org.sqwatch.SearchActivity.updateVideosFound(SearchActivity.java:99)
at leader.org.sqwatch.SearchActivity.access$200(SearchActivity.java:33)
at leader.org.sqwatch.SearchActivity$2$1.run(SearchActivity.java:72)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5256)
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:898)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:693)

this is for the SearchActivity:

public class SearchActivity extends Activity {
    private EditText searchInput;
    private ListView videosFound;
    private Handler handler;
    private List<VideoItem> searchResults;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_search);
        searchInput = (EditText) findViewById(R.id.search_input);
        videosFound = (ListView) findViewById(R.id.videos_found);
        handler = new Handler();
        searchInput.setOnEditorActionListener(
                new TextView.OnEditorActionListener() {
                    @Override
                    public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
                        if (actionId == EditorInfo.IME_ACTION_DONE) {
                            searchOnYoutube(v.getText().toString());
                            return false;
                        }
                        return true;
                    }
                }
        );
    }

    private void searchOnYoutube(final String keywords) {
        new Thread() {
            public void run() {
                YoutubeConnector yc = new YoutubeConnector(SearchActivity.this);
                searchResults = yc.search(keywords);
                handler.post(new Runnable() {
                    public void run() {
                        updateVideosFound();
                    }
                });
            }
        }.start();
    }

    private void updateVideosFound() {
        ArrayAdapter<VideoItem> adapter = new ArrayAdapter<VideoItem>
                (getApplicationContext(), R.layout.video_item, searchResults) {
            @Override
            public View getView(int position, View convertView, ViewGroup parent) {
                if (convertView == null) {
                    convertView = getLayoutInflater().inflate(R.layout.video_item, parent,
                            false);
                }
                ImageView thumbnail =
                        (ImageView) convertView.findViewById(R.id.video_thumbnail);
                TextView title = (TextView) convertView.findViewById(R.id.video_title);
                TextView description =
                        (TextView) convertView.findViewById(R.id.video_description);
                VideoItem searchResult = searchResults.get(position);
                Picasso.with(getApplicationContext()).load(searchResult.
                        getThumbnailURL()).into(thumbnail);
                title.setText(searchResult.getTitle());
                description.setText(searchResult.getDescription());
                return convertView;
            }
        };
        videosFound.setAdapter(adapter);
    }

    private void addClickListener() {
        videosFound.setOnItemClickListener(new AdapterView.
                OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> av, View v, int pos, long id) {
                Intent intent = new Intent(getApplicationContext(),
                        PlayerActivity.class);
                intent.putExtra("VIDEO_ID", searchResults.get(pos).getId());
                startActivity(intent);
            }
        });
    }
}

And this is the activity_search.xml code:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:layout_height="match_parent" 
    android:layout_width="match_parent" 
    android:orientation="vertical" 
    xmlns:android="http://schemas.android.com/apk/res/android">
    <EditText android:hint="@string/search" 
        android:id="@+id/search_input" 
        android:layout_height="wrap_content" 
        android:layout_width="match_parent"
        android:singleLine="true" 
        android:text="funny"/>
    <ListView android:dividerHeight="5dp" 
        android:id="@+id/videos_found" 
        android:layout_height="match_parent" 
        android:layout_width="match_parent"/>
</LinearLayout>

解决方案

Acually I just remove all the allowed apps in the refers in google console I opened Api & auth/ Credentials and click "Edit allowed referers" empty the input field.

Thank you ρяσѕρєя K for your help

这篇关于在具有显示java.lang.NullPointerException的Andr​​oid客户端的YouTube的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆