我一直使用的Xcode过去那么现在我想学习Android和我使用Eclipse这是为什么会崩溃?如何调试?
我跟着http://developer.android.com/resources/tutorials/views/hello-tabwidget.html列出的所有步骤,但是当我真正在我的LG革命运行的代码( 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>
我可以保证,在您发布一些你会得到没有答案码。 – Peaches491
查找崩溃的最佳方法是检查LogCat。那基本上是androids系统日志。你可以在'SDK/tools'文件夹的ddms应用程序中找到它,或者通过'Window-> Add view-> other-> LogCat'在eclipse中找到它。应该有一个例外(用标签AndroidRuntime以红色打印)。收到后,请将其张贴并添加相关代码。 – 2011-08-15 18:54:30
我的问题的答案将为您解答这个问题http://stackoverflow.com/questions/2209406/issues-with-android-tabhost-example – KevinDTimm