So I’ve just got myself an Android device and wanted to have a go at some Android development, to create myself a simple task manager. The idea was to implement the tab UI seen all around android, so I stumbled across this: http://developer.android.com/resources/tutorials/views/hello-tabwidget.html
All good. From this point on I need to apologise because I’m going to be unspecific because I don’t know where the problem is. What happens is pretty simple. I run my application, I get a dialog box saying “com.app.appname was forced to close”. That’s it. I don’t see the UI.
So, without further ado, I have implemented:
Overview.java:
public class Overview extends TabActivity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Resources res = getResources(); // Resource object to get Drawables
TabHost tabHost = getTabHost(); // The activity TabHost
TabHost.TabSpec spec; // Resusable TabSpec for each tab
Intent intent; // Reusable Intent for each tab
intent = new Intent().setClass(this, ViewTasks.class);
spec = tabHost.newTabSpec("tasks").setIndicator("Tasks",
res.getDrawable(R.drawable.ic_tab_artists))
.setContent(intent);
tabHost.addTab(spec);
intent = new Intent().setClass(this, ViewGoals.class);
spec = tabHost.newTabSpec("goals").setIndicator("Goals",
res.getDrawable(R.drawable.ic_tab_artists))
.setContent(intent);
tabHost.addTab(spec);
tabHost.setCurrentTab(0);
}
}
main.xml (res/layout)
<?xml version="1.0" encoding="utf-8"?>
<TabHost
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5dp">
<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"
android:padding="5dp" />
</LinearLayout>
</TabHost>
Manifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="the.correct.package.name"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="@drawable/icon" android:label="@string/app_name" android:name="vxataskmaster">
<activity android:name="Overview" android:label="@string/app_name" android:theme="@android:style/Theme.NoTitleBar" android:enabled="true" android:screenOrientation="unspecified">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<action android:name="android.intent.action.EDIT" />
<action android:name="android.intent.action.PICK" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity android:name="ViewGoals" android:label="@string/app_name" android:theme="@android:style/Theme.NoTitleBar" android:enabled="true" android:screenOrientation="unspecified">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<action android:name="android.intent.action.EDIT" />
<action android:name="android.intent.action.PICK" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity android:name="ViewTasks" android:label="@string/app_name" android:theme="@android:style/Theme.NoTitleBar" android:enabled="true" android:screenOrientation="unspecified">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<action android:name="android.intent.action.EDIT" />
<action android:name="android.intent.action.PICK" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
<uses-sdk android:minSdkVersion="8" />
</manifest>
As far as I can tell, I have modified the original example to use a few classes of my own. These classes just implement the hello world messages seen on the tutorial site.
So, what am I doing wrong, please? I can’t seem to get anything sensible out of the debugger… it doesn’t point to anything in my code, whether run on the emulator or my device.
I apologise for pasting large chunks of code. If I had an idea of where the problem lay, I would have cut it down, but I don’t…!
Thanks.
Edited: logcat says this:
11-27 22:51:32.871: ERROR/AndroidRuntime(10662): java.lang.RuntimeException: Unable to instantiate application correct.root.package.taskmaster.ataskmaster: java.lang.ClassNotFoundException: correct.root.package.taskmaster.ataskmaster in loader dalvik.system.PathClassLoader[/data/app/correct.root.package.taskmaster-1.apk]
Like Falmarri suggested you might be missing the Activities in your AndroidManifest.xml. ViewGoals and ViewGoals are Activities right? If so, add them to the manifest like you did Overview.
LogCat is the Android log util that is integrated with Eclipse. Go to Debug view and you should see it there.