Bonjour, à travers un exercice , j'affiche un ListFragment : public class EarthquakeListFragment extends ListFragment {
qui me donne une liste de tremblements de terre aux USA (connexion Web : fichier .xml)

Ds le MainActivity, je propose un menu pour affiner la séléction de la liste (Magnitude,...)

Tout est OK à partir de Honeycom mais si j'essaie de rendre le prog compatible avec Froyo en utilisant la bibli android.support.v4

j'obtiens l'erreur suivante

E/AndroidRuntime(298): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.chap_7_earthquake_part_2_c/com.example.chap_7_earthquake_part_2_c.MainActivity}: java.lang.ClassNotFoundException: com.example.chap_7_earthquake_part_2_c.MainActivity in loader dalvik.system.PathClassLoader[/data/app/com.example.chap_7_earthquake_part_2_c-1.apk]

Je joins les 2 class principales, Merci de votre collaboration

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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
 
package com.example.chap_7_earthquake_part_2_c;
 
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Build;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
 
public class MainActivity extends FragmentActivity {
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
 
    updateFromPreferences();
  }
 
  static final private int MENU_PREFERENCES = Menu.FIRST+1;
  static final private int MENU_UPDATE = Menu.FIRST+2;
  private static final int SHOW_PREFERENCES = 1;
 
  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
    super.onCreateOptionsMenu(menu);
 
    menu.add(0, MENU_PREFERENCES, Menu.NONE, R.string.menu_preferences);
 
    return true;
  }
 
  public boolean onOptionsItemSelected(MenuItem item){
    super.onOptionsItemSelected(item);
    switch (item.getItemId()) {
 
      case (MENU_PREFERENCES): {
        Class c = Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB ?    
          PreferencesActivity.class : FragmentPreferences.class;
        Intent i = new Intent(this, c);
Log.d("DEpart Staractivity", "depart");
        startActivityForResult(i, SHOW_PREFERENCES);
        return true;
      }
    }
    return false;
  }
 
 
  public int minimumMagnitude = 0;
  public boolean autoUpdateChecked = false;
  public int updateFreq = 0;
 
  private void updateFromPreferences() {
    Context context = getApplicationContext();
    SharedPreferences prefs = 
      PreferenceManager.getDefaultSharedPreferences(context);
 
    minimumMagnitude = 
      Integer.parseInt(prefs.getString(PreferencesActivity.PREF_MIN_MAG, "3"));
    updateFreq = 
      Integer.parseInt(prefs.getString(PreferencesActivity.PREF_UPDATE_FREQ, "60"));
 
    autoUpdateChecked = prefs.getBoolean(PreferencesActivity.PREF_AUTO_UPDATE, false);
  }
 
  public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
 
    if (requestCode == SHOW_PREFERENCES)
      updateFromPreferences();
 
//      FragmentManager fm = getSupportFragmentManager();
//      //android.support.v4.app.Fragment earthquakeList = fm.findFragmentById(R.id.EarthquakeListFragment);
//      android.support.v4.app.Fragment earthquakeList = fm.findFragmentById(R.id.EarthquakeListFragment);
//      earthquakeList.;
 
    FragmentManager fm = getSupportFragmentManager();
	FragmentTransaction ft = fm.beginTransaction();
	android.support.v4.app.Fragment earthquakeList = fm.findFragmentById(R.id.EarthquakeListFragment);
	ft.show(earthquakeList);
	ft.commit();
  }
 
 
}
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
 
package com.example.chap_7_earthquake_part_2_c;
 
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.GregorianCalendar;
 
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
 
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;
 
import android.os.Bundle;
import android.support.v4.app.ListFragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
 
public class EarthquakeListFragment extends ListFragment {
 
  ArrayAdapter<Quake> aa;
  ArrayList<Quake> earthquakes = new ArrayList<Quake>();
 
  public String location = "";
  public String depth;
 
  public static String TAG = "EARTHQUAKE_ListFragment";
 
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        return inflater.inflate(R.layout.liste_fragment, container, false);
    }
 
    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
 
    int layoutID = android.R.layout.simple_list_item_1;
    aa = new ArrayAdapter<Quake>(getActivity(), layoutID , earthquakes);
    setListAdapter(aa);
 
    refreshEarthquakes();
  }
 
  //--------------------------------------------------------
  public void refreshEarthquakes() {
	    // Get the XML
	    URL url;
	    try {
	      String quakeFeed = getString(R.string.quake_feed);
	      url = new URL(quakeFeed);
 
	      URLConnection connection;
	      connection = url.openConnection();
 
	      HttpURLConnection httpConnection = (HttpURLConnection)connection;
	      int responseCode = httpConnection.getResponseCode();
 
	      if (responseCode == HttpURLConnection.HTTP_OK) {
	        InputStream in = httpConnection.getInputStream();
 
	        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
	        DocumentBuilder db = dbf.newDocumentBuilder();
 
	        // Parse the earthquake feed.
	        Document dom = db.parse(in);
	        Element docEle = dom.getDocumentElement();
 
	        // Clear the old earthquakes
	        earthquakes.clear();
 
	        // Get a list of each earthquake entry.
	        NodeList nl = docEle.getElementsByTagName("entry");
	        if (nl != null && nl.getLength() > 0) {
	          for (int i = 0 ; i < nl.getLength(); i++) {
	            Element entry = (Element)nl.item(i);
	            Element title = (Element)entry.getElementsByTagName("title").item(0);
	            Element when = (Element)entry.getElementsByTagName("updated").item(0);
	            Element link = (Element)entry.getElementsByTagName("link").item(0);
	            Element summary = (Element)entry.getElementsByTagName("summary").item(0);
	            Element g = (Element)entry.getElementsByTagName("georss:point").item(0);
	            Element d = (Element)entry.getElementsByTagName("georss:elev").item(0);
 
 
	            if (title!= null) Log.d("pas null ","pas null title");
	            Log.d("vanleur de Title ",title.getFirstChild().getNodeValue());
	            if (when!= null) Log.d("pas null ","pas null when");
	            if (link!= null) {
	            	Log.d("pas null ","pas null link");	
	            }
	            if (summary!= null) Log.d("pas null ","pas null summary");
 
	            if (g!= null) Log.d("pas null ","pas null");
 
	            // Le titre
	            //----------
	            String details = title.getFirstChild().getNodeValue();
	            if (details.equals("Data Feed Deprecated")) details = "USGS M 2.5+ Earthquakes";         
 
	            // La date
	            // -------    	      
	            String dt = when.getFirstChild().getNodeValue(); 
	            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'hh:mm:ss'Z'");
	            Date qdate = new GregorianCalendar(0,0,0).getTime();
	            try {
	              qdate = sdf.parse(dt);
	            } catch (ParseException e) {
	            }
 
 
	            // Localisation : latitude  Longitude
	            // -----------------------------------
	            if (g!= null){
	            	location = g.getFirstChild().getNodeValue();
	            	Log.d("CI ","ICI");
	            }
 
	            // Profondeur 
	            // -----------
	            if (d!= null){
	            	depth = d.getFirstChild().getNodeValue();
	            	Log.d("Depth ",depth);
	            }
 
	            // Magnitude
	            String magnitudeString = details.split(" ")[1];
	            int end =  magnitudeString.length()-1;
	            String magnitude_S = ((magnitudeString.substring(0, end))+ "0").trim();
	            double magnitude = Double.parseDouble(magnitude_S);
 
	            Quake quake = new Quake(qdate,details,location,magnitude,depth);
 
            // Process a newly found earthquake
            addNewQuake(quake);
          }
        }
      }
    } catch (MalformedURLException e) {
      Log.d(TAG, "MalformedURLException", e);
    } catch (IOException e) {
      Log.d(TAG, "IOException", e);
    } catch (ParserConfigurationException e) {
      Log.d(TAG, "Parser Configuration Exception", e);
    } catch (SAXException e) {
      Log.d(TAG, "SAX Exception", e);
    }
    finally {
    }
  }
 
  private void addNewQuake(Quake _quake) {
    MainActivity earthquakeActivity = (MainActivity)getActivity();
    if (_quake.getMagnitude() > earthquakeActivity.minimumMagnitude) {
      // Add the new quake to our list of earthquakes.
      earthquakes.add(_quake);
    }
 
    // Notify the array adapter of a change.
    aa.notifyDataSetChanged();
  }
 
 
}