Bonjour,

Je débute avec android et j'ai un problème au niveau de mon application qui survient quand je rajoute des tabhost.

Pour essayer de comprendre d’où vient mon l’erreur, j’ai repris un tuto sur internet qui affiche une ListeView depuis une Activity, jusqu'ici tout marche bien, puis j’ai essayé d’afficher cette ListView dans un onglet, tout simplement.

Le problème est que je me retrouve à chaque fois avec un :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
ERROR/AndroidRuntime(405): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.formation.adapter/com.formation.adapter.MonActivite}: java.lang.NullPointerException
et je ne vois pas d’où viens le problème.

Biblio qui ajoute les onglets
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package com.formation.adapter;
 
import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TabHost;
 
public class Biblio extends TabActivity {
 
	private TabHost tabHost;
	private TabHost.TabSpec spec;
	private Intent intentFeed; 
 
	@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
 
        // Mise en place des onglets
        {	
        	tabHost = getTabHost();
 
            intentFeed = new Intent().setClass(this, MonActivite.class);
 
            // Initialize a TabSpec for each tab and add it to the TabHost
            spec = tabHost.newTabSpec("livre").setIndicator("Livre",
                              null)
                          .setContent(intentFeed);
            tabHost.addTab(spec);
 
            tabHost.setCurrentTab(0);
        }
	}
}
MonActivite qui affiche la list
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package com.formation.adapter;
 
import java.util.ArrayList;
import java.util.List;
 
import android.app.Activity;
import android.os.Bundle;
import android.widget.ListView;
 
public class MonActivite extends Activity {
 
	ListView lvListe;
	List<Livre> maBibliotheque = new ArrayList<Livre>();
 
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.itemlivre);
 
        lvListe = (ListView)findViewById(R.id.lvListe);
 
        RemplirLaBibliotheque();
 
        LivreAdapter adapter = new LivreAdapter(this, maBibliotheque);
 
        lvListe.setAdapter(adapter);
 
        adapter.notifyDataSetChanged();
    }
 
    private void RemplirLaBibliotheque() {
    	maBibliotheque.clear();
    	maBibliotheque.add(new Livre("Starcraft 2 : Les diables du ciel", "William-C Dietz"));
    	maBibliotheque.add(new Livre("L'art du développement Androïd", "Mark Murphy"));
    	maBibliotheque.add(new Livre("Le seuil des ténèbres", "Karen Chance"));
    }
}
LivreAdapter
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package com.formation.adapter;
 
import java.util.List;
 
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
 
public class LivreAdapter extends BaseAdapter {
 
	List<Livre> biblio;
	LayoutInflater inflater;
 
	public LivreAdapter(Context context,List<Livre> biblio) {
		inflater = LayoutInflater.from(context);
		this.biblio = biblio;
	}
 
	@Override
	public int getCount() {
		return biblio.size();
	}
 
	@Override
	public Object getItem(int position) {
		return biblio.get(position);
	}
 
	@Override
	public long getItemId(int position) {
		return position;
	}
 
	private class ViewHolder {
		TextView tvTitre;
		TextView tvAuteur;
	}
 
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder;
 
		if(convertView == null) {
			holder = new ViewHolder();
			convertView = inflater.inflate(R.layout.itemlivre, null);
			holder.tvTitre = (TextView)convertView.findViewById(R.id.tvTitre);
			holder.tvAuteur = (TextView)convertView.findViewById(R.id.tvAuteur);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
 
		holder.tvTitre.setText(biblio.get(position).getTitre());
		holder.tvAuteur.setText(biblio.get(position).getAuteur());
 
		return convertView;
	}
 
}

Comment pourrais-je résoudre ce problème ?

Merci d'avance pour votre aide.

EDIT : résolu ! simple problème de manifest apparemment