2011-08-15 39 views
1

我一直使用的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> 
+3

我可以保证,在您发布一些你会得到没有答案码。 – Peaches491

+2

查找崩溃的最佳方法是检查LogCat。那基本上是androids系统日志。你可以在'SDK/tools'文件夹的ddms应用程序中找到它,或者通过'Window-> Add view-> other-> LogCat'在eclipse中找到它。应该有一个例外(用标签AndroidRuntime以红色打印)。收到后,请将其张贴并添加相关代码。 – 2011-08-15 18:54:30

+0

我的问题的答案将为您解答这个问题http://stackoverflow.com/questions/2209406/issues-with-android-tabhost-example – KevinDTimm

回答

1

http://code.google.com/p/android/issues/detail?id=4183的信息和我原来的问题落实Ted的修正 - 下面是明显的,但也有其他错误太:

<activity android:name=".AlbumsActivity" 
      android:label="@string/app_name" 
      android:theme="@android:style/Theme.NoTitleBar"> 
</activity> 
<activity android:name=".ArtistsActivity" 
      android:label="@string/app_name" 
      android:theme="@android:style/Theme.NoTitleBar"> 
</activity> 
<activity android:name=".SongsActivity" 
      android:label="@string/app_name" 
      android:theme="@android:style/Theme.NoTitleBar"> 
</activity> 
1

狂猜:你是否将所有的活动添加到清单中?一个活动等于清单中提到的一个活动。

当您创建一个projet时,您的主要活动默认添加到此文件中,以便系统知道启动您的主要活动是否正常。现在,每次你在你的项目中添加一个新的活动时间,你必须添加在清单本次活动:

<activity android:name=".HelloTabWidget" android:label="@string/app_name" 
     android:theme="@android:style/Theme.NoTitleBar"> 

如果不是,你点击你的文件的左边空白处添加一些破发点,然后单击在调试按钮上。最后,打开调试视图,然后使用F8在中断点之间导航。

希望它有帮助,一直在那里:)。