【发布时间】:2011-08-16 05:58:57
【问题描述】:
我过去一直使用 Xcode,所以现在我正在尝试学习 Android,我正在使用 Eclipse
我遵循了http://developer.android.com/resources/tutorials/views/hello-tabwidget.html 中列出的所有步骤,但是当我在我的 LG Revolution (Froyo 2.2.1) 上实际运行代码时,我崩溃了。
我不确定如何调试,但我不知道为什么这甚至会崩溃。任何帮助将不胜感激。
我对所有 3 个选项卡都使用了相同的图像(这是我所做的唯一修改,但我认为它不会崩溃)
这是我的代码
package com.oneorangetree.shit;
import android.app.TabActivity;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.widget.TabHost;
public class HelloTabWidgetActivity extends TabActivity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// Resource object to get drawable
Resources res = getResources();
TabHost tabHost = getTabHost();
TabHost.TabSpec spec;
Intent intent;
intent = new Intent().setClass(this, ArtistsActivity.class);
spec = tabHost.newTabSpec("artists").setIndicator("Artists", res.getDrawable(R.drawable.ic_tab_artists)).setContent(intent);
tabHost.addTab(spec);
intent = new Intent().setClass(this, AlbumsActivity.class);
spec = tabHost.newTabSpec("albums").setIndicator("Albums", res.getDrawable(R.drawable.ic_tab_artists)).setContent(intent);
tabHost.addTab(spec);
intent = new Intent().setClass(this, SongsActivity.class);
spec = tabHost.newTabSpec("songs").setIndicator("Songs", res.getDrawable(R.drawable.ic_tab_artists)).setContent(intent);
tabHost.addTab(spec);
tabHost.setCurrentTab(2);
}
}
这是我的清单文件
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.oneorangetree.shit"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="8" />
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".HelloTabWidgetActivity"
android:label="@string/app_name"
android:theme="@android:style/Theme.NoTitleBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
【问题讨论】:
-
我可以保证在你发布一些代码之前你不会得到任何答案。
-
查找崩溃的最佳方法是检查 LogCat。那基本上是androids系统日志。您可以在
SDK/tools文件夹中的 ddms 应用程序中找到它,或者通过Window->Add view->other->LogCat在 eclipse 中找到它。那里应该有一个异常(以红色打印,带有 AndroidRuntime 标签)。拥有后,请发布并添加相关代码。 -
我的问题的答案将为您解答stackoverflow.com/questions/2209406/…
-
IOW,示例不完整 - 找到描述如何完成它的答案,您将启动并运行
-
@KevinDTimm - 你也许是对的。您能否发布您的 Manifest 文件作为答案,以便我接受并给予您信任?
标签: java android android-tabhost