App android崩溃

时间:2014-03-07 17:09:46

标签: android

我不明白为什么当我运行调试时应用程序崩溃了。有谁能告诉我哪里错了?

  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();
   }
}

我用这个应用程序读了一个在线数据库,我在互联网上找到了这个例子。感谢。

 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

2 个答案:

答案 0 :(得分:0)

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

您已在清单中声明liuk.presences.LiukPresencesActivity。您发布的代码为com.example.locali.MainActivity。确保完全限定的类名(包名称)在清单和代码中一致。

答案 1 :(得分:-1)

您似乎忘记在AndroidManifest.xml文件中声明您的活动

你应该在应用程序标记的清单xml文件中有这样的(或类似于你的活动名称的文本)文本

<activity android:name="liuk.presences.LiukPresencesActivity" />