基本上,我的boidae列表活动不会从我的serpente列表活动中打开。我不知道为什么,但如果你能帮助我,我确实有日志猫和代码。三江源。
我的日志猫:
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
我的boidae课程:
/*
* 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。
三江源。
答案 0 :(得分:2)
更改以下行
Class ourclass = Class.forName("com.xeecros.reptilekeeper" + localposm);
将这一个改为
Class ourclass = Class.forName("com.xeecros.reptilekeeper." + localposm);
注意。缺少错误日志建议:
ClassNotFoundException: com.xeecros.reptilekeeperBoidae
答案 1 :(得分:1)
看看这个(在班级 Boidae 中):
String boaspecies[] = {"Charina bottae"};
....
String localposm = boaspecies[position];
...
Class ourclass = Class.forName("com.xeecros.reptilekeeper" + localposm);
这不起作用,因为 Charina bottae 不能是班级名称。
最后你错过了点(在班级 Boidae 和 Serpentes ):
Class ourclass = Class.forName("com.xeecros.reptilekeeper." + localposm);
干杯!