2013-04-23 66 views
0

基本上,我的博愛活動列表活動不會從我的活動列表中打開。我不知道爲什麼,但如果你能幫助我,我確實有日誌貓和代碼。謝謝。我的列表活動無法打開

我的日誌貓:

04-23 19:49:28.327: W/System.err(958): java.lang.ClassNotFoundException: com.xeecros.reptilekeeperBoidae 
04-23 19:49:28.327: W/System.err(958): at java.lang.Class.classForName(Native Method) 
04-23 19:49:28.366: W/System.err(958): at java.lang.Class.forName(Class.java:217) 
04-23 19:49:28.366: W/System.err(958): at java.lang.Class.forName(Class.java:172) 
04-23 19:49:28.366: W/System.err(958): at com.xeecros.reptilekeeper.Serpentes.onListItemClick(Serpentes.java:28) 
04-23 19:49:28.366: W/System.err(958): at android.app.ListActivity$2.onItemClick(ListActivity.java:319) 
04-23 19:49:28.366: W/System.err(958): at android.widget.AdapterView.performItemClick(AdapterView.java:298) 
04-23 19:49:28.366: W/System.err(958): at android.widget.AbsListView.performItemClick(AbsListView.java:1100) 
04-23 19:49:28.366: W/System.err(958): at android.widget.AbsListView$PerformClick.run(AbsListView.java:2749) 
04-23 19:49:28.376: W/System.err(958): at android.widget.AbsListView$1.run(AbsListView.java:3423) 
04-23 19:49:28.376: W/System.err(958): at android.os.Handler.handleCallback(Handler.java:725) 
04-23 19:49:28.376: W/System.err(958): at android.os.Handler.dispatchMessage(Handler.java:92) 
04-23 19:49:28.376: W/System.err(958): at android.os.Looper.loop(Looper.java:137) 
04-23 19:49:28.376: W/System.err(958): at android.app.ActivityThread.main(ActivityThread.java:5041) 
04-23 19:49:28.387: W/System.err(958): at java.lang.reflect.Method.invokeNative(Native Method) 
04-23 19:49:28.387: W/System.err(958): at java.lang.reflect.Method.invoke(Method.java:511) 
04-23 19:49:28.387: W/System.err(958): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793) 
04-23 19:49:28.387: W/System.err(958): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560) 
04-23 19:49:28.396: W/System.err(958): at dalvik.system.NativeStart.main(Native Method) 
04-23 19:49:28.396: W/System.err(958): Caused by: java.lang.NoClassDefFoundError: com/xeecros/reptilekeeperBoidae 
04-23 19:49:28.396: W/System.err(958): ... 18 more 
04-23 19:49:28.406: W/System.err(958): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.xeecros.reptilekeeperBoidae" on path: /data/app/com.xeecros.reptilekeeper-1.apk 
04-23 19:49:28.406: W/System.err(958): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:65) 
04-23 19:49:28.406: W/System.err(958): at java.lang.ClassLoader.loadClass(ClassLoader.java:501) 
04-23 19:49:28.406: W/System.err(958): at java.lang.ClassLoader.loadClass(ClassLoader.java:461) 
04-23 19:49:28.416: W/System.err(958): ... 18 more 

我蟒科類:

/* 
* This class is a list to contain 
* all of the classes for the individual species. 
*/ 


package com.xeecros.reptilekeeper; 

import android.app.ListActivity; 
import android.content.Intent; 
import android.os.Bundle; 
import android.view.View; 
import android.widget.ArrayAdapter; 
import android.widget.ListView; 

public class Boidae extends ListActivity { 

    String boaspecies[] = {"Charina bottae"}; 


    @Override 
    protected void onCreate(Bundle savedInstanceState) { 

     super.onCreate(savedInstanceState); 
     setListAdapter(new ArrayAdapter<String>(Boidae.this, 
       android.R.layout.simple_list_item_1, boaspecies)); 
    } 

    @Override 
    protected void onListItemClick(ListView l, View v, int position, long id) { 

     super.onListItemClick(l, v, position, id); 
     String localposm = boaspecies[position]; 
     try{ 
      Class ourclass = Class.forName("com.xeecros.reptilekeeper" + localposm); 
      Intent bintent = new Intent(Boidae.this, ourclass); 
      startActivity(bintent); 
      }catch (ClassNotFoundException e){ 
       e.printStackTrace(); 
      } 
    } 





} 

我serpente類:

package com.xeecros.reptilekeeper; 

import android.app.ListActivity; 
import android.content.Intent; 
import android.os.Bundle; 
import android.view.View; 
import android.widget.ArrayAdapter; 
import android.widget.ListView; 

public class Serpentes extends ListActivity { 

    String snakefam[] = {"Boidae", "Colubridae", 
      "Elapidae", "Pythonidae", "Viperidae"}; 
    @Override 
    protected void onCreate(Bundle savedInstanceState) { 

     super.onCreate(savedInstanceState); 
     setListAdapter(new ArrayAdapter<String>(Serpentes.this, 
       android.R.layout.simple_list_item_1, snakefam)); 
    } 

    @Override 
    protected void onListItemClick(ListView l, View v, int position, long id) { 

     super.onListItemClick(l, v, position, id); 
     String localposm = snakefam[position]; 
     try{ 
     Class ourclass = Class.forName("com.xeecros.reptilekeeper" + localposm); 
     Intent sintent = new Intent(Serpentes.this, ourclass); 
     startActivity(sintent); 
     }catch (ClassNotFoundException e){ 
      e.printStackTrace(); 
     } 
    } 

} 

另外,我有一個問題要問:我如何改變列表的外觀,因爲我不能使用XML,因爲它是一個ArrayAdapter。

謝謝。

回答

2

變化通過把這個代替

Class ourclass = Class.forName("com.xeecros.reptilekeeper." + localposm); 

注意以下行

Class ourclass = Class.forName("com.xeecros.reptilekeeper" + localposm); 

。失蹤的錯誤日誌表明它:

ClassNotFoundException: com.xeecros.reptilekeeperBoidae 
+0

那裏的愚蠢錯誤謝謝你,但你也知道我會如何改變外觀。 – tridianprime 2013-04-23 19:57:46

+0

我確實對此有點懷疑,但那並沒有想到。下次不好意思。 – tridianprime 2013-04-23 19:58:58

+0

你是什麼意思?你總是可以提出有關外觀的新問題。 – Benoit 2013-04-23 19:59:09

1

看這(在類蟒科):

String boaspecies[] = {"Charina bottae"}; 
.... 
String localposm = boaspecies[position]; 
... 
Class ourclass = Class.forName("com.xeecros.reptilekeeper" + localposm); 

這可不行,因爲Charina bottae不能是一個類名。

最後你錯過了點(在課堂蟒科蛇亞):

Class ourclass = Class.forName("com.xeecros.reptilekeeper." + localposm); 

乾杯!

+0

不錯的地方Boidae班也有錯誤,但問題是無法啓動Boidae班。無論如何+1更多的錯誤 – Benoit 2013-04-23 20:03:34