开发者

Why is this crashing? And How Do I Debug?

开发者 https://www.devze.com 2023-03-28 10:58 出处:网络
I\'ve always used Xcode in the past so now I\'m trying to learn Android and I\'m using Eclipse I follow开发者_StackOverflowed all the steps outlined in http://developer.android.com/resources/tutorial

I've always used Xcode in the past so now I'm trying to learn Android and I'm using Eclipse

I follow开发者_StackOverflowed all the steps outlined in http://developer.android.com/resources/tutorials/views/hello-tabwidget.html but when I actually run the code on my LG Revolution (Froyo 2.2.1), I am crashing.

I'm not sure how to debug but I don't know why this would even crash. Any help would be appreciated.

I used the same image for all 3 tabs (thats the only modification I made but I don't think it should crash)

Here is my code

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);
    }
}

here is my Manifest file

<?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>


See the information in http://code.google.com/p/android/issues/detail?id=4183 and implement the fixes by Ted in my original question - below is the manifest but there are other errors too:

<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>


Wild guess : did you add all of your activities into the manifest ? One activity equals one mention in the manifest.

When you create a projet your main activity is by default added to this file so the system know that is it ok to launch your main activity. Now, each time you add a new activity in your project you had to add this activity in the manifest :

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

If it is not that you add some break points by clicking on the left margin of your file then click on the debug button. Finally you open the debug perspective, and you navigate between your break points with F8.

Hope it helps, been there too :).

0

上一篇:

:下一篇

精彩评论

暂无评论...
验证码 换一张
取 消