Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/181.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 填充自定义listView的奇怪问题_Android_Listview_Android Listview_Youtube_Android Arrayadapter - Fatal编程技术网

Android 填充自定义listView的奇怪问题

Android 填充自定义listView的奇怪问题,android,listview,android-listview,youtube,android-arrayadapter,Android,Listview,Android Listview,Youtube,Android Arrayadapter,我在尝试填充我的listView时遇到了一些问题。ListView的条目有一个特殊的设计原因,就是用于youtube的视频。它们由两个字符串(标题和描述)和图像组成。我得到了一个nullPointerException,但我还没有找到原因 listVideos正确填充,使用与youtube连接的线程并使用JSON获取播放列表中的每个视频。videosListView是一个普通的listView,R.layout.entry是一个线性布局,包含一个图像和另一个线性布局(视频标题和描述) YouTu

我在尝试填充我的listView时遇到了一些问题。ListView的条目有一个特殊的设计原因,就是用于youtube的视频。它们由两个字符串(标题和描述)和图像组成。我得到了一个nullPointerException,但我还没有找到原因

listVideos正确填充,使用与youtube连接的线程并使用JSON获取播放列表中的每个视频。videosListView是一个普通的listView,R.layout.entry是一个线性布局,包含一个图像和另一个线性布局(视频标题和描述)

YouTube活动类:

public class YoutubeActivity extends YouTubeBaseActivity implements YouTubePlayer.OnInitializedListener  {

    YouTubePlayerView youTubeView; 
    String URL_VIDEO = "CaA-k1l0xa4";
    String KEY_DEVELOPER = MYKEY;


    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.videos_layout);     
        YouTubePlayerView youtubeView = (YouTubePlayerView) findViewById(R.id.youtube_view);  
        Youtube youtube = new Youtube(getApplicationContext(), youtubeView, KEY_DEVELOPER); 
        //youtube.reproduce(URL_VIDEO);
        ListView videosListView = (ListView) findViewById(R.id.listListView);
        youtube.loadListView(videosListView, "PLOhl4anP1Mp1vJKmmqGAcu10h5OSbx4zf");
    }

    @Override
    public void onInitializationFailure(Provider arg0,
            YouTubeInitializationResult arg1) {
        // TODO Auto-generated method stub

    }

    @Override
    public void onInitializationSuccess(Provider arg0, YouTubePlayer arg1,
            boolean arg2) {
        // TODO Auto-generated method stub

    }
}
Youtube类(内部FillListView)


知道错误来自哪里吗??谢谢

解决了!经典的空指针愚蠢的错误…我正在做ListView list=ListView videosListView=(ListView)findViewById(R.id.ListView);但是videos_layout.xml中的listView的ID为listaListView…该死,我讨厌这些错误!浪费了这么多时间。

我添加了更多信息,让它更清晰!经典的空指针愚蠢的错误…我正在做ListView list=ListView videosListView=(ListView)findViewById(R.id.ListView);但是videos_layout.xml中的listView的ID为listaListView…该死,我讨厌这些错误!浪费了这么多时间。
public class Youtube{

YouTubePlayerView youtubeView;
String keyDeveloper;
ListView videosListView;
LinearLayout videoEntryView;
Context context;
String urlVideo;

public Youtube(Context context, YouTubePlayerView youtubeView, String keyDeveloper){

    this.context = context;
    this.youtubeView = youtubeView;
    this.keyDeveloper = keyDeveloper;

}

public void loadListView(ListView videosListView, String channel){

    this.videosListView = videosListView;

    new Thread(new GetYouTubeUserVideosTask(myHandler, channel)).start();

}

Handler myHandler = new Handler(){
    public void handleMessage(Message msg){
        fillListView(msg);
    }
};

private void fillListView(Message msg){

    ArrayList<Video> listVideos = (ArrayList) msg.getData().get("VideosList");  

    videosListView.setAdapter(new AdapterList(context, R.layout.entry, listVideos){
        @Override
        public void onEntry(Object entry, View view) {
            if (entry != null) {
                TextView superiorText = (TextView) view.findViewById(R.id.textView_superior); 
                if (superiorText != null) 
                    superiorText.setText(((Video) entry).getTitle()); 

                TextView inferiorText = (TextView) view.findViewById(R.id.textView_inferior); 
                if (inferiorText != null)
                    inferiorText.setText(((Video) entry).getUrl()); 

                ImageView thumb = (ImageView) view.findViewById(R.id.imageView_imagen);

                String aux = ((Video)entry).getThumbUrl();
                ImageDownloader downloader = new ImageDownloader();
                downloader.download(aux, thumb);
            }
        }
    });


private void fillListView(Message msg){

    ArrayList<Video> listVideos = (ArrayList) msg.getData().get("VideosList");  

    videosListView.setAdapter(new AdapterList(context, R.layout.entry, listVideos){
        @Override
        public void onEntry(Object entry, View view) {
            if (entry != null) {
                TextView superiorText = (TextView) view.findViewById(R.id.textView_superior); 
                if (superiorText != null) 
                    superiorText.setText(((Video) entry).getTitle()); 

                TextView inferiorText = (TextView) view.findViewById(R.id.textView_inferior); 
                if (inferiorText != null)
                    inferiorText.setText(((Video) entry).getUrl()); 

                ImageView thumb = (ImageView) view.findViewById(R.id.imageView_imagen);

                String aux = ((Video)entry).getThumbUrl();
                ImageDownloader downloader = new ImageDownloader();
                downloader.download(aux, thumb);
            }
        }
    });`
public abstract class AdapterList extends BaseAdapter{

private ArrayList<?> entries; 
private int R_layout_IdView; 
private Context context;

public AdapterList(Context context, int R_layout_IdView, ArrayList<?> entry){

    super();
    this.entries = entry;
    this.R_layout_IdView = R_layout_IdView;
    this.context = context;

}

@Override
public View getView(int posicion, View view, ViewGroup pariente) {
    if (view == null) {
        LayoutInflater vi = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
        view = vi.inflate(R_layout_IdView, null); 
    }
    onEntry (entries.get(posicion), view);
    return view; 
}

@Override
public int getCount() {
    return entries.size();
}

@Override
public Object getItem(int position) {
    return entries.get(position);
}

@Override
public long getItemId(int position) {
    return position;
}

public abstract void onEntry(Object object, View view);
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/LinearLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@color/Blanco"
android:gravity="center"
android:orientation="vertical"
tools:context=".MainActivity" >

<ImageView
    android:id="@+id/header"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:contentDescription="@string/app_name"
/>

<TextView
    android:id="@+id/tituloTextView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:paddingBottom="6dp"
    android:text="@string/title"
    android:textColor="@color/Negro"
    android:textSize="20sp"
    android:textStyle="bold" />

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical" >

<ListView
    android:id="@+id/listaListView"
    android:layout_width="match_parent"
    android:layout_height="136dp"
    android:background="@color/Blanco"
    android:paddingBottom="15dp" >

</ListView>

</LinearLayout>

<com.google.android.youtube.player.YouTubePlayerView
    android:id="@+id/youtube_view"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="0.83"
     />
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/entryListView"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal" >

    <ImageView
        android:id="@+id/imageView_imagen"
        android:layout_width="50dp"
        android:layout_height="50dp"
        android:adjustViewBounds="true"
        android:scaleType="fitXY"
        android:contentDescription="@string/DescriptionImage"
        android:src="@android:drawable/ic_menu_gallery" />

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="match_parent"
        android:gravity="center"
        android:orientation="vertical" >

        <TextView
            android:id="@+id/textView_superior"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/largeText"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:textSize="14sp" />

        <TextView
            android:id="@+id/textView_inferior"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/smallText"
            android:textAppearance="?android:attr/textAppearanceSmall"
            android:textSize="12sp" />

    </LinearLayout>

</LinearLayout>
08-24 13:34:51.828: E/AndroidRuntime(7580): FATAL EXCEPTION: main
08-24 13:34:51.828: E/AndroidRuntime(7580): java.lang.NullPointerException
08-24 13:34:51.828: E/AndroidRuntime(7580):     at guidelines.youtube.Youtube.fillListView(Youtube.java:67)
08-24 13:34:51.828: E/AndroidRuntime(7580):     at guidelines.youtube.Youtube.access$0(Youtube.java:63)
08-24 13:34:51.828: E/AndroidRuntime(7580):     at guidelines.youtube.Youtube$1.handleMessage(Youtube.java:59)
08-24 13:34:51.828: E/AndroidRuntime(7580):     at android.os.Handler.dispatchMessage(Handler.java:99)
08-24 13:34:51.828: E/AndroidRuntime(7580):     at android.os.Looper.loop(Looper.java:137)
08-24 13:34:51.828: E/AndroidRuntime(7580):     at android.app.ActivityThread.main(ActivityThread.java:4645)
08-24 13:34:51.828: E/AndroidRuntime(7580):     at java.lang.reflect.Method.invokeNative(Native Method)
08-24 13:34:51.828: E/AndroidRuntime(7580):     at java.lang.reflect.Method.invoke(Method.java:511)
08-24 13:34:51.828: E/AndroidRuntime(7580):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:809)
08-24 13:34:51.828: E/AndroidRuntime(7580):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:576)
08-24 13:34:51.828: E/AndroidRuntime(7580):     at dalvik.system.NativeStart.main(Native Method)