Java tabhost classnotfoundexception
在我的android应用程序中,我尝试实现tabhost。 实际上,我正在尝试androidhive的udapt教程 然而,我不断地得到致命的错误。 请帮助我修复此错误Java tabhost classnotfoundexception,java,android,android-tabhost,classnotfoundexception,Java,Android,Android Tabhost,Classnotfoundexception,在我的android应用程序中,我尝试实现tabhost。 实际上,我正在尝试androidhive的udapt教程 然而,我不断地得到致命的错误。 请帮助我修复此错误 public class AndroidTabAndListView extends TabActivity { // TabSpec Names private static final String INBOX_SPEC = "Inbox"; private static final String O
public class AndroidTabAndListView extends TabActivity {
// TabSpec Names
private static final String INBOX_SPEC = "Inbox";
private static final String OUTBOX_SPEC = "Outbox";
private static final String PROFILE_SPEC = "Profile";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TabHost tabHost = getTabHost();
TabSpec inboxSpec = tabHost.newTabSpec(INBOX_SPEC);
inboxSpec.setIndicator(INBOX_SPEC, getResources().getDrawable(R.drawable.icon_inbox));
Intent inboxIntent = new Intent(this, InboxActivity.class);
inboxSpec.setContent(inboxIntent);
TabSpec outboxSpec = tabHost.newTabSpec(OUTBOX_SPEC);
outboxSpec.setIndicator(OUTBOX_SPEC, getResources().getDrawable(R.drawable.icon_outbox));
Intent outboxIntent = new Intent(this, OutboxActivity.class);
outboxSpec.setContent(outboxIntent);
TabSpec profileSpec = tabHost.newTabSpec(PROFILE_SPEC);
profileSpec.setIndicator(PROFILE_SPEC, getResources().getDrawable(R.drawable.icon_profile));
Intent profileIntent = new Intent(this, Testactivity.class);
profileSpec.setContent(profileIntent);
tabHost.addTab(inboxSpec);
tabHost.addTab(outboxSpec);
tabHost.addTab(profileSpec);
}
}
布局
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
</LinearLayout>
</TabHost>
如果包名有问题,请确保所有类和Android清单引用相同的包名。selp.s104512.newvoter;但如果你为教程编写了一些代码,我会告诉AdapteOnewell Android正在寻找com.s104512.newvoter。检查您的AndroidManifest以查看
selp.s104512.newvoter
是否存在于任何地方。是的,这是一个问题:(更改为com,classnotfoundexeption已消失。
public class CandidateAdapter extends BaseAdapter{
Context ctx;
LayoutInflater lInflater;
ArrayList<Candidate> objects;
CandidateAdapter(Context context, ArrayList<Candidate> candidates) {
ctx = context;
objects = candidates;
lInflater = (LayoutInflater) ctx
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
public int getCount() {
return objects.size();
}
public Object getItem(int position) {
return objects.get(position);
}
public long getItemId(int position) {
return position;
}
Candidate getCandidate(int position) {
return ((Candidate) getItem(position));
}
public View getView(int position, View convertView, ViewGroup parent) {
// используем созданные, но не используемые view
View view = convertView;
if (view == null) {
view = lInflater.inflate(R.layout.inbox_list_item, parent, false);
}
Candidate p = getCandidate(position);
((TextView) view.findViewById(R.id.from)).setText(p.get_name());
((TextView) view.findViewById(R.id.subject)).setText(p.get_office());
return view;
}
}
public class InboxActivity extends ListActivity {
List<Candidate> candidates;
private DatabaseHandler db;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.inbox_list);
db = new DatabaseHandler(this);
candidates = db.getAllCandidates(1);
CandidateAdapter adapter = new CandidateAdapter(this,(ArrayList) candidates);
ListView lvMain = (ListView) findViewById(R.id.lvMain);
lvMain.setAdapter(adapter);
}
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ListView
android:id="@+id/lvMain"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<!-- From Label -->
<TextView
android:id="@+id/from"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingTop="8dip"
android:paddingLeft="8dip"
android:paddingBottom="4dip"
android:textSize="20dip"
android:textStyle="bold" />
<!-- Mail Subject -->
<TextView android:id="@+id/subject"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:paddingLeft="8dip"
android:paddingBottom="6dip"
android:textSize="15dip"
android:layout_below="@id/from"/>
<!-- Mail date -->
<TextView android:id="@+id/date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:padding="8dip"/>
</RelativeLayout>
12-15 23:27:47.529: W/dalvikvm(397): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
12-15 23:27:47.568: E/AndroidRuntime(397): FATAL EXCEPTION: main
12-15 23:27:47.568: E/AndroidRuntime(397): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.s1042512.newvoter/com.s1042512.newvoter.AndroidTabAndListView}: java.lang.ClassNotFoundException: com.s1042512.newvoter.AndroidTabAndListView in loader dalvik.system.PathClassLoader[/data/app/com.s1042512.newvoter-2.apk]
12-15 23:27:47.568: E/AndroidRuntime(397): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2585)
12-15 23:27:47.568: E/AndroidRuntime(397): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
12-15 23:27:47.568: E/AndroidRuntime(397): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
12-15 23:27:47.568: E/AndroidRuntime(397): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
12-15 23:27:47.568: E/AndroidRuntime(397): at android.os.Handler.dispatchMessage(Handler.java:99)
12-15 23:27:47.568: E/AndroidRuntime(397): at android.os.Looper.loop(Looper.java:123)
12-15 23:27:47.568: E/AndroidRuntime(397): at android.app.ActivityThread.main(ActivityThread.java:4627)
12-15 23:27:47.568: E/AndroidRuntime(397): at java.lang.reflect.Method.invokeNative(Native Method)
12-15 23:27:47.568: E/AndroidRuntime(397): at java.lang.reflect.Method.invoke(Method.java:521)
12-15 23:27:47.568: E/AndroidRuntime(397): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
12-15 23:27:47.568: E/AndroidRuntime(397): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
12-15 23:27:47.568: E/AndroidRuntime(397): at dalvik.system.NativeStart.main(Native Method)
12-15 23:27:47.568: E/AndroidRuntime(397): Caused by: java.lang.ClassNotFoundException: com.s1042512.newvoter.AndroidTabAndListView in loader dalvik.system.PathClassLoader[/data/app/com.s1042512.newvoter-2.apk]
12-15 23:27:47.568: E/AndroidRuntime(397): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:243)
12-15 23:27:47.568: E/AndroidRuntime(397): at java.lang.ClassLoader.loadClass(ClassLoader.java:573)
12-15 23:27:47.568: E/AndroidRuntime(397): at java.lang.ClassLoader.loadClass(ClassLoader.java:532)
12-15 23:27:47.568: E/AndroidRuntime(397): at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
12-15 23:27:47.568: E/AndroidRuntime(397): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2577)
12-15 23:27:47.568: E/AndroidRuntime(397): ... 11 more
12-15 23:27:55.818: I/Process(397): Sending signal. PID: 397 SIG: 9