I 'm doing an Android application but i have ever the same problem: If i want for example a variable of a second class, my application crashes.
Here's an exemple with my code:
public class Classement extends Activity{
TextView textview;
GetCode getCode = new GetCode();
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.classement);
textview = (TextView)findViewById(R.id.textView1);
try {
textview.setText(String.valueOf(getCode.methode()[1]));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
my logcat:
01-14 13:39:13.740: I/Process(3304): Sending signal. PID: 3304 SIG: 9 01-14 13:39:22.770: W/Trace(3342): Unexpected value from nativeGetEnabledTags: 0 01-14 13:39:22.791: W/Trace(3342): Unexpected value from nativeGetEnabledTags: 0 01-14 13:39:22.930: W/Trace(3342): Unexpected value from nativeGetEnabledTags: 0 01-14 13:39:22.930: W/Trace(3342): Unexpected value from nativeGetEnabledTags: 0 01-14 13:39:23.440: D/dalvikvm(3342): GC_FOR_ALLOC freed 54K, 7% free 2514K/2688K, paused 33ms, total 38ms 01-14 13:39:23.450: I/dalvikvm-heap(3342): Grow heap (frag case) to 3.210MB for 674916-byte allocation 01-14 13:39:23.510: D/dalvikvm(3342): GC_FOR_ALLOC freed 1K, 6% free 3171K/3348K, paused 59ms, total 59ms 01-14 13:39:23.580: D/dalvikvm(3342): GC_CONCURRENT freed <1K, 6% free 3171K/3348K, paused 6ms+14ms, total 70ms 01-14 13:39:25.441: W/Trace(3342): Unexpected value from nativeGetEnabledTags: 0 01-14 13:39:25.441: W/Trace(3342): Unexpected value from nativeGetEnabledTags: 0 01-14 13:39:25.451: W/Trace(3342): Unexpected value from nativeGetEnabledTags: 0 01-14 13:39:25.481: W/Trace(3342): Unexpected value from nativeGetEnabledTags: 0 01-14 13:39:25.560: W/Trace(3342): Unexpected value from nativeGetEnabledTags: 0 01-14 13:39:25.560: W/Trace(3342): Unexpected value from nativeGetEnabledTags: 0 01-14 13:39:25.570: W/Trace(3342): Unexpected value from nativeGetEnabledTags: 0 01-14 13:39:25.650: W/Trace(3342): Unexpected value from nativeGetEnabledTags: 0 01-14 13:39:25.650: W/Trace(3342): Unexpected value from nativeGetEnabledTags: 0 01-14 13:39:25.670: W/Trace(3342): Unexpected value from nativeGetEnabledTags: 0 01-14 13:39:25.670: W/Trace(3342): Unexpected value from nativeGetEnabledTags: 0 01-14 13:39:25.680: W/Trace(3342): Unexpected value from nativeGetEnabledTags: 0 01-14 13:39:25.680: W/Trace(3342): Unexpected value from nativeGetEnabledTags: 0 01-14 13:39:25.700: D/gralloc_goldfish(3342): Emulator without GPU emulation detected. 01-14 13:39:25.800: W/Trace(3342): Unexpected value from nativeGetEnabledTags: 0 01-14 13:39:25.840: W/Trace(3342): Unexpected value from nativeGetEnabledTags: 0 01-14 13:39:27.040: W/Trace(3342): Unexpected value from nativeGetEnabledTags: 0 01-14 13:39:27.060: W/Trace(3342): Unexpected value from nativeGetEnabledTags: 0 01-14 13:39:27.060: W/Trace(3342): Unexpected value from nativeGetEnabledTags: 0 01-14 13:39:27.060: W/Trace(3342): Unexpected value from nativeGetEnabledTags: 0 01-14 13:39:27.260: W/Trace(3342): Unexpected value from nativeGetEnabledTags: 0 01-14 13:39:27.260: W/Trace(3342): Unexpected value from nativeGetEnabledTags: 0 01-14 13:39:27.260: W/Trace(3342): Unexpected value from nativeGetEnabledTags: 0 01-14 13:39:27.270: W/Trace(3342): Unexpected value from nativeGetEnabledTags: 0 01-14 13:39:27.400: W/Trace(3342): Unexpected value from nativeGetEnabledTags: 0 01-14 13:39:27.520: W/Trace(3342): Unexpected value from nativeGetEnabledTags: 0 01-14 13:39:27.520: I/Choreographer(3342): Skipped 34 frames! The application may be doing too much work on its main thread. 01-14 13:39:27.530: W/Trace(3342): Unexpected value from nativeGetEnabledTags: 0 01-14 13:39:27.530: W/Trace(3342): Unexpected value from nativeGetEnabledTags: 0 01-14 13:39:27.731: W/Trace(3342): Unexpected value from nativeGetEnabledTags: 0 01-14 13:39:27.790: W/Trace(3342): Unexpected value from nativeGetEnabledTags: 0 01-14 13:39:27.800: W/Trace(3342): Unexpected value from nativeGetEnabledTags: 0 01-14 13:39:28.771: W/System.err(3342): android.os.NetworkOnMainThreadException 01-14 13:39:28.801: W/System.err(3342): at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1117) 01-14 13:39:28.801: W/System.err(3342): at java.net.InetAddress.lookupHostByName(InetAddress.java:385) 01-14 13:39:28.831: W/System.err(3342): at java.net.InetAddress.getAllByNameImpl(InetAddress.java:236) 01-14 13:39:28.850: W/System.err(3342): at java.net.InetAddress.getAllByName(InetAddress.java:214) 01-14 13:39:28.850: W/System.err(3342): at libcore.net.http.HttpConnection.(HttpConnection.java:70) 01-14 13:39:28.871: W/System.err(3342): at libcore.net.http.HttpConnection.(HttpConnection.java:50) 01-14 13:39:28.871: W/System.err(3342): at libcore.net.http.HttpConnection$Address.connect(HttpConnection.java:340) 01-14 13:39:28.871: W/System.err(3342): at libcore.net.http.HttpConnectionPool.get(HttpConnectionPool.java:87) 01-14 13:39:28.900: W/System.err(3342): at libcore.net.http.HttpConnection.connect(HttpConnection.java:128) 01-14 13:39:28.900: W/System.err(3342): at libcore.net.http.HttpEngine.openSocketConnection(HttpEngine.java:316) 01-14 13:39:28.920: W/System.err(3342): at libcore.net.http.HttpEngine.connect(HttpEngine.java:311) 01-14 13:39:28.940: W/System.err(3342): at libcore.net.http.HttpEngine.sendSocketRequest(HttpEngine.java:290) 01-14 13:39:28.950: W/System.err(3342): at libcore.net.http.HttpEngine.sendRequest(HttpEngine.java:240) 01-14 13:39:28.990: W/System.err(3342): at libcore.net.http.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:282) 01-14 13:39:28.990: W/System.err(3342): at libcore.net.http.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:177) 01-14 13:39:29.000: W/System.err(3342): at com.example.gotteron.GetCode.methode(GetCode.java:18) 01-14 13:39:29.000: W/System.err(3342): at com.example.gotteron.Classement.onCreate(Classement.java:16) 01-14 13:39:29.031: W/System.err(3342): at android.app.Activity.performCreate(Activity.java:5104) 01-14 13:39:29.060: W/System.err(3342): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080) 01-14 13:39:29.060: W/System.err(3342): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144) 01-14 13:39:29.070: W/System.err(3342): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230) 01-14 13:39:29.070: W/System.err(3342): at android.app.ActivityThread.access$600(ActivityThread.java:141) 01-14 13:39:29.100: W/System.err(3342): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234) 01-14 13:39:29.130: W/System.err(3342): at android.os.Handler.dispatchMessage(Handler.java:99) 01-14 13:39:29.130: W/System.err(3342): at android.os.Looper.loop(Looper.java:137) 01-14 13:39:29.140: W/System.err(3342): at android.app.ActivityThread.main(ActivityThread.java:5039) 01-14 13:39:29.151: W/System.err(3342): at java.lang.reflect.Method.invokeNative(Native Method) 01-14 13:39:29.230: W/System.err(3342): at java.lang.reflect.Method.invoke(Method.java:511) 01-14 13:39:29.240: W/System.err(3342): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793) 01-14 13:39:29.250: W/System.err(3342): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560) 01-14 13:39:29.250: W/System.err(3342): at dalvik.system.NativeStart.main(Native Method) 01-14 13:39:29.460: W/Trace(3342): Unexpected value from nativeGetEnabledTags: 0 01-14 13:39:29.570: I/Choreographer(3342): Skipped 57 frames! The application may be doing too much work on its main thread. 01-14 13:39:29.570: W/Trace(3342): Unexpected value from nativeGetEnabledTags: 0 01-14 13:39:29.630: W/Trace(3342): Unexpected value from nativeGetEnabledTags: 0 01-14 13:39:29.660: W/Trace(3342): Unexpected value from nativeGetEnabledTags: 0 01-14 13:39:29.801: W/Trace(3342): Unexpected value from nativeGetEnabledTags: 0 01-14 13:39:29.811: W/Trace(3342): Unexpected value from nativeGetEnabledTags: 0 01-14 13:39:29.831: W/Trace(3342): Unexpected value from nativeGetEnabledTags: 0 01-14 13:39:29.841: W/Trace(3342): Unexpected value from nativeGetEnabledTags: 0 01-14 13:39:29.841: W/Trace(3342): Unexpected value from nativeGetEnabledTags: 0 01-14 13:39:29.921: W/Trace(3342): Unexpected value from nativeGetEnabledTags: 0 01-14 13:39:29.941: W/Trace(3342): Unexpected value from nativeGetEnabledTags: 0 01-14 13:39:29.960: I/Choreographer(3342): Skipped 43 frames! The application may be doing too much work on its main thread. 01-14 13:39:30.000: W/Trace(3342): Unexpected value from nativeGetEnabledTags: 0 01-14 13:39:30.010: W/Trace(3342): Unexpected value from nativeGetEnabledTags: 0 01-14 13:39:30.060: W/Trace(3342): Unexpected value from nativeGetEnabledTags: 0 01-14 13:39:30.060: W/Trace(3342): Unexpected value from nativeGetEnabledTags: 0 01-14 13:39:30.090: W/Trace(3342): Unexpected value from nativeGetEnabledTags: 0 01-14 13:39:30.090: W/Trace(3342): Unexpected value from nativeGetEnabledTags: 0 01-14 13:39:30.310: W/Trace(3342): Unexpected value from nativeGetEnabledTags: 0 01-14 13:39:30.370: W/Trace(3342): Unexpected value from nativeGetEnabledTags: 0 01-14 13:39:30.410: W/Trace(3342): Unexpected value from nativeGetEnabledTags: 0 01-14 13:39:30.440: W/Trace(3342): Unexpected value from nativeGetEnabledTags: 0 01-14 13:39:30.962: W/Trace(3342): Unexpected value from nativeGetEnabledTags: 0 01-14 13:39:30.962: W/Trace(3342): Unexpected value from nativeGetEnabledTags: 0 01-14 13:39:31.021: W/Trace(3342): Unexpected value from nativeGetEnabledTags: 0 01-14 13:39:31.021: W/Trace(3342): Unexpected value from nativeGetEnabledTags: 0
methode():
package com.example.gotteron;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;
import java.util.Arrays;
public class GetCode {
//Recupere le code HTML de la page
public int [] methode() throws IOException{
URL oracle = new URL("http://www.nationalleague.ch/NL/fr/");
URLConnection yc = oracle.openConnection();
BufferedReader in = new BufferedReader(new InputStreamReader(
yc.getInputStream()));
String inputLine;
String s1 = "";
while ((inputLine = in.readLine()) != null)
s1 = s1 + inputLine;
in.close();
//12 car 12 équipes
int tableauEquipes [] = new int [12];
//Variable numérique de l'emplacement dans le code HTML pour chaque équipe
//Le string représente l'équipe en HTML dans le tableau
// doit apparaître 1x dans le code
int Berne = s1.indexOf(">SC Bern</td>");
int Fribourg = s1.indexOf("Fribourg</td>");
int Geneve = s1.indexOf("Genève</td>");
int Zug = s1.indexOf("EV Zug</td>");
int ZSC = s1.indexOf("ZSC Lions</td>");
int Davos = s1.indexOf("HC Davos</td>");
int Lugano = s1.indexOf("HC Lugano</td>");
int Kloten = s1.indexOf("Kloten Flyers</td>");
int Bienne = s1.indexOf("EHC Biel</td>");
int Lakers = s1.indexOf("Lakers</td>");
int Ambri = s1.indexOf("Ambri-Piotta</td>");
int SCL = s1.indexOf("SCL Tigers</td>");
//Mettre variables dans tableau
tableauEquipes[0] = Berne;
tableauEquipes[1] = Fribourg;
tableauEquipes[2] = Geneve;
tableauEquipes[3] = Zug;
tableauEquipes[4] = ZSC;
tableauEquipes[5] = Davos;
tableauEquipes[6] = Lugano;
tableauEquipes[7] = Kloten;
tableauEquipes[8] = Bienne;
tableauEquipes[9] = Lakers;
tableauEquipes[10] = Ambri;
tableauEquipes[11] = SCL;
//Tri Tableau dans l'ordre croissant
Arrays.sort(tableauEquipes);
// Trouve la la place dans le classement de Berne
int tdbBerne = 0;
int tdbBerneDefinitif = 0;
for (int i = 0; i < tableauEquipes.length; i++) {
tdbBerne++;
if (tableauEquipes[i] == s1.indexOf(">SC Bern</td>")) {
System.out.println("Berne est" + tdbBerne);
}
}
tdbBerneDefinitif = tdbBerne;
// Trouve la la place dans le classement de Fribourg
int tdbFribourg = 0;
int tdbFribourgDefinitif = 0;
for (int i = 0; i < tableauEquipes.length; i++) {
tdbFribourg++;
if (tableauEquipes[i] == s1.indexOf("Fribourg</td>")) {
System.out.println("Fribourg est" + tdbFribourg);
tdbFribourgDefinitif = tdbFribourg;
}
}
System.out.println(tdbFribourgDefinitif);
// Trouve la la place dans le classement de Geneve
int tdbGeneve = 0;
int tdbGeneveDefinitif = 0;
for (int i = 0; i < tableauEquipes.length; i++) {
tdbGeneve++;
if (tableauEquipes[i] == s1.indexOf("Genève</td>")) {
System.out.println("Geneve est" + tdbGeneve);
}
}
tdbGeneveDefinitif = tdbGeneve;
// Trouve la la place dans le classement de Zug
int tdbZug = 0;
int tdbZugDefinitif = 0;
for (int i = 0; i < tableauEquipes.length; i++) {
tdbZug++;
if (tableauEquipes[i] == s1.indexOf("EV Zug</td>")) {
System.out.println("Zug est" + tdbZug);
}
}
tdbZugDefinitif = tdbZug;
// Trouve la la place dans le classement de ZSC
int tdbZSC = 0;
int tdbZSCDefinitif = 0;
for (int i = 0; i < tableauEquipes.length; i++) {
tdbZSC++;
if (tableauEquipes[i] == s1.indexOf("ZSC Lions</td>")) {
System.out.println("ZSC Lions est" + tdbZSC);
}
}
tdbZSCDefinitif = tdbZSC;
// Trouve la la place dans le classement de Davos
int tdbDavos = 0;
int tdbDavosDefinitif = 0;
for (int i = 0; i < tableauEquipes.length; i++) {
tdbDavos++;
if (tableauEquipes[i] == s1.indexOf("HC Davos</td>")) {
System.out.println("Davos est" + tdbDavos);
}
}
tdbDavosDefinitif = tdbDavos;
// Trouve la la place dans le classement de Lugano
int tdbLugano = 0;
int tdbLuganoDefinitif = 0;
for (int i = 0; i < tableauEquipes.length; i++) {
tdbLugano++;
if (tableauEquipes[i] == s1.indexOf("HC Lugano</td>")) {
System.out.println("Lugano est" + tdbLugano);
}
}
tdbLuganoDefinitif = tdbLugano;
// Trouve la la place dans le classement de Kloten Flyers
int tdbKloten = 0;
int tdbKlotenDefinitif = 0;
for (int i = 0; i < tableauEquipes.length; i++) {
tdbKloten++;
if (tableauEquipes[i] == s1.indexOf("Kloten Flyers</td>")) {
System.out.println("Kloten est" + tdbKloten);
}
}
tdbKlotenDefinitif = tdbKloten;
// Trouve la la place dans le classement de Bienne
int tdbBienne = 0;
int tdbBienneDefinitif = 0;
for (int i = 0; i < tableauEquipes.length; i++) {
tdbBienne++;
if (tableauEquipes[i] == s1.indexOf("EHC Biel</td>")) {
System.out.println("Bienne est" + tdbBienne);
}
}
tdbBienneDefinitif = tdbBienne;
// Trouve la la place dans le classement de Lakers
int tdbLakers = 0;
int tdbLakersDefinitif = 0;
for (int i = 0; i < tableauEquipes.length; i++) {
tdbLakers++;
if (tableauEquipes[i] == s1.indexOf("Lakers</td>")) {
System.out.println("Lakers est" + tdbLakers);
}
}
tdbLakersDefinitif = tdbLakers;
// Trouve la la place dans le classement de Ambri
int tdbAmbri = 0;
int tdbAmbriDefinitif = 0;
for (int i = 0; i < tableauEquipes.length; i++) {
tdbAmbri++;
if (tableauEquipes[i] == s1.indexOf("Ambri-Piotta</td>")) {
System.out.println("Ambri est" + tdbAmbri);
}
}
tdbAmbriDefinitif = tdbAmbri;
// Trouve la la place dans le classement de SCL
int tdbSCL = 0;
int tdbSCLDefinitif = 0;
for (int i = 0; i < tableauEquipes.length; i++) {
tdbSCL++;
if (tableauEquipes[i] == s1.indexOf("SCL Tigers</td>")) {
System.out.println("SCL est" + tdbSCL);
}
}
tdbSCLDefinitif = tdbSCL;
int [] classement = {tdbSCLDefinitif, tdbAmbriDefinitif, tdbLakersDefinitif, tdbBienneDefinitif, tdbKlotenDefinitif,
tdbLuganoDefinitif, tdbDavosDefinitif, tdbZSCDefinitif, tdbZugDefinitif, tdbGeneveDefinitif, tdbFribourgDefinitif,
tdbBerneDefinitif};
Arrays.sort(classement);
return classement;
}
}