-2

I do not understand why when I run the debug the application crashes. can anyone tell me where am I wrong?

  package com.example.locali;

 import java.io.BufferedReader;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.InputStreamReader;
 import java.util.Vector;

 import liuk.presences.R;



 import org.apache.http.HttpEntity;
 import org.apache.http.HttpResponse;
 import org.apache.http.StatusLine;
 import org.apache.http.client.ClientProtocolException;
 import org.apache.http.client.HttpClient;
 import org.apache.http.client.methods.HttpGet;
 import org.apache.http.impl.client.DefaultHttpClient;
 import org.json.JSONArray;
 import org.json.JSONObject;


 import android.os.Bundle;
 import android.app.Activity;

 import android.view.Menu;
 import android.widget.ArrayAdapter;
 import android.widget.ListAdapter;
 import android.widget.ListView;
 import android.widget.Toast;


 public class MainActivity extends Activity {
   /** Called when the activity is first created. */
   @Override
   public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
      ListView listView = (ListView) findViewById(R.id.mylist);
      Vector v = new Vector();



      String readTwitterFeed = readTwitterFeed();
      try {
         JSONArray jsonArray = new JSONArray(readTwitterFeed);

         for (int i = 0; i < jsonArray.length(); i++) 
         {
            JSONObject jsonObject = jsonArray.getJSONObject(i);
            v.add(jsonArray.getJSONObject(i).getString("Nome") +" "+ jsonArray.getJSONObject(i).getString("Cognome"));
         }
      } catch (Exception e) {
         Toast.makeText(this, "Exception" + e,Toast.LENGTH_LONG).show();
         e.printStackTrace();
      }
      ListAdapter listaContatti = new ArrayAdapter(this, android.R.layout.simple_list_item_1, v);
      listView.setAdapter(listaContatti);

      //Toast.makeText(this, "END OF APPLICATION",Toast.LENGTH_LONG).show();
   } //end onCreate

   public String readTwitterFeed() {
      StringBuilder builder = new StringBuilder();
      HttpClient client = new DefaultHttpClient();
      HttpGet httpGet = new HttpGet("http://locali.altervista.org/php/locali.php");

      try {
         HttpResponse response = client.execute(httpGet);
         StatusLine statusLine = response.getStatusLine();
         int statusCode = statusLine.getStatusCode();
         if (statusCode == 200) {

            HttpEntity entity = response.getEntity();
            InputStream content = entity.getContent();
            BufferedReader reader = new BufferedReader(new InputStreamReader(content));
            String line;
            while ((line = reader.readLine()) != null) 
            {
               builder.append(line);
            } //end while
         } else {
            Toast.makeText(this, "Failed to download file",Toast.LENGTH_LONG).show();
         }
      } catch (ClientProtocolException e) {
         e.printStackTrace();
      } catch (IOException e) {
         e.printStackTrace();
      }
      return builder.toString();
   }
}

I read an online database with this application and I found this example on the internet. Thanks.

 03-07 18:21:10.490: D/AndroidRuntime(10119): Shutting down VM
 03-07 18:21:10.490: W/dalvikvm(10119): threadid=1: thread exiting with uncaught   exception (group=0x41da6da0)
 03-07 18:21:10.500: E/AndroidRuntime(10119): FATAL EXCEPTION: main
 03-07 18:21:10.500: E/AndroidRuntime(10119): Process: liuk.presences, PID: 10119
 03-07 18:21:10.500: E/AndroidRuntime(10119): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{liuk.presences/liuk.presences.LiukPresencesActivity}: java.lang.ClassNotFoundException: Didn't find class "liuk.presences.LiukPresencesActivity" on path: DexPathList[[zip file "/data/app/liuk.presences-2.apk"],nativeLibraryDirectories= [/data/app-lib/liuk.presences-2, /vendor/lib, /system/lib]]
03-07 18:21:10.500: E/AndroidRuntime(10119):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2231)
03-07 18:21:10.500: E/AndroidRuntime(10119):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2363)
03-07 18:21:10.500: E/AndroidRuntime(10119):    at android.app.ActivityThread.access$900(ActivityThread.java:161)
03-07 18:21:10.500: E/AndroidRuntime(10119):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1265)
03-07 18:21:10.500: E/AndroidRuntime(10119):    at android.os.Handler.dispatchMessage(Handler.java:102)
03-07 18:21:10.500: E/AndroidRuntime(10119):    at android.os.Looper.loop(Looper.java:157)
03-07 18:21:10.500: E/AndroidRuntime(10119):    at android.app.ActivityThread.main(ActivityThread.java:5356)
03-07 18:21:10.500: E/AndroidRuntime(10119):    at java.lang.reflect.Method.invokeNative(Native Method)
03-07 18:21:10.500: E/AndroidRuntime(10119):    at java.lang.reflect.Method.invoke(Method.java:515)
03-07 18:21:10.500: E/AndroidRuntime(10119):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265)
03-07 18:21:10.500: E/AndroidRuntime(10119):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
03-07 18:21:10.500: E/AndroidRuntime(10119):    at dalvik.system.NativeStart.main(Native Method)
03-07 18:21:10.500: E/AndroidRuntime(10119): Caused by: java.lang.ClassNotFoundException: Didn't find class "liuk.presences.LiukPresencesActivity" on path: DexPathList[[zip file "/data/app/liuk.presences-2.apk"],nativeLibraryDirectories=[/data/app-lib/liuk.presences-2, /vendor/lib, /system/lib]]
03-07 18:21:10.500: E/AndroidRuntime(10119):    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:67)
03-07 18:21:10.500: E/AndroidRuntime(10119):    at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
03-07 18:21:10.500: E/AndroidRuntime(10119):    at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
03-07 18:21:10.500: E/AndroidRuntime(10119):    at android.app.Instrumentation.newActivity(Instrumentation.java:1079)
03-07 18:21:10.500: E/AndroidRuntime(10119):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2222)
03-07 18:21:10.500: E/AndroidRuntime(10119):    ... 11 more
03-07 18:21:12.772: I/Process(10119): Sending signal. PID: 10119 SIG: 9
user3313188
  • 21
  • 1
  • 8
  • 3
    guessing `NetworkOnMainThreadException` – Raghunandan Mar 07 '14 at 17:10
  • possible duplicate of [android.os.NetworkOnMainThreadException](http://stackoverflow.com/questions/6343166/android-os-networkonmainthreadexception) – codeMagic Mar 07 '14 at 17:13
  • [See this answer](http://stackoverflow.com/questions/18964329/eclipse-logcat-debugging/18964524#18964524) about reading your logcat. It will take you much further in diagnosing your problems and understanding the most relevant parts of your code to post. – codeMagic Mar 07 '14 at 17:14

2 Answers2

0
java.lang.ClassNotFoundException: Didn't find class "liuk.presences.LiukPresencesActivity"

You have declared liuk.presences.LiukPresencesActivity in your manifest. The code you posted has com.example.locali.MainActivity. Make sure the fully qualified class names (with package names) agree in manifest and code.

laalto
  • 150,114
  • 66
  • 286
  • 303
-1

It seems you forgot to declare your activity in AndroidManifest.xml file

You should have such (or something like this with your activity name) text in your manifest xml file in application tag

<activity android:name="liuk.presences.LiukPresencesActivity" />
Sergey Pekar
  • 8,555
  • 7
  • 47
  • 54