4ndr01d61r7
Lurker
I am an Android developer amateur and I went to Android Developers site to learn more about Android development. I completed the previous tutorials and I am now in Tab Layout. When I got to run the program. It says FORCE CLOSE. I don't know where part of the program I did wrong. The tutorial site never gave in depth description of the code and there were missing blocks which I found out by surfing over the net. I know there are some who has the same problem as mine. I hope this will be solved soon for me to be able to proceed to the next chapter. Thank you in advance.
Here is my code :
src folder :
- com dot android dot HelloTabWidget
- comdotandroiddotHelloTabWidget/HelloTabWidgetActivitydotjava
- /src/comdotandroiddotHelloTabWidget/AlbumsActivitydotjava
- /src/comdotandroiddotHelloTabWidget/ArtistsActivitydotjava
- /src/comdotandroiddotHelloTabWidget/SongsActivitydotjava
- /res/drawable/ic_tabs_albumsdotxml
- /res/drawable/ic_tabs_artistsdotxml
- /res/drawable/ic_tabs_songsdotxml
- /layout/maindotxml
AndroidManifestdotxml
Here is my code :
src folder :
- com dot android dot HelloTabWidget
- comdotandroiddotHelloTabWidget/HelloTabWidgetActivitydotjava
Code:
package com.android.HelloTabWidget;
import android.app.TabActivity;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.util.Log;
import android.widget.TabHost;
public class HelloTabWidgetActivity extends TabActivity {
private String TAG="HelloTabWidget";
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
// Create an Intent to launch an Activity for the tab (to be reused)
intent = new Intent().setClass(this,ArtistsActivity.class);
Log.v(TAG,"---artist activity is called---");
// Initialize a TabSpec for each tab and add it to the TabHost
spec = tabHost.newTabSpec("artists").setIndicator("Artists",res.getDrawable(R.drawable.ic_tab_artists)).setContent(intent);
tabHost.addTab(spec);
// Do the same for the other tabs
intent = new Intent().setClass(this,AlbumsActivity.class);
Log.v(TAG,"---album activity is called---");
spec = tabHost.newTabSpec("albums").setIndicator("Albums",res.getDrawable(R.drawable.ic_tab_albums)).setContent(intent);
tabHost.addTab(spec);
intent = new Intent().setClass(this, SongsActivity.class);
Log.v(TAG,"---song activity is called---");
spec = tabHost.newTabSpec("songs").setIndicator("Songs",res.getDrawable(R.drawable.ic_tab_songs)).setContent(intent);
tabHost.addTab(spec);
}
}
- /src/comdotandroiddotHelloTabWidget/AlbumsActivitydotjava
Code:
package com.android.HelloTabWidget;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.widget.TextView;
public class AlbumsActivity extends Activity{
private String TAG="AlbumsActivity";
@Override
public void onCreate(Bundle savedInstance)
{
super.onCreate(savedInstance);
TextView textview_album=new TextView(this);
textview_album.setText("This is album activity");
setContentView(textview_album);
Log.v(TAG,"---in album activity---");
}
}
- /src/comdotandroiddotHelloTabWidget/ArtistsActivitydotjava
Code:
package com.android.HelloTabWidget;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.widget.TextView;
public class ArtistsActivity extends Activity {
private String TAG="ArtistsActivity";
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TextView textview=new TextView(this);
textview.setText("This is Artist Activity");
setContentView(textview);
Log.v(TAG,"---in artist activity---");
}
}
- /src/comdotandroiddotHelloTabWidget/SongsActivitydotjava
Code:
package com.android.HelloTabWidget;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.widget.TextView;
public class SongsActivity extends Activity{
private String TAG="SongsActivity";
@Override
public void onCreate(Bundle savedInstance)
{
super.onCreate(savedInstance);
TextView textview_song=new TextView(this);
textview_song.setText("This is song activity");
setContentView(textview_song);
Log.v(TAG,"---in songs activity---");
}
}
- /res/drawable/ic_tabs_albumsdotxml
Code:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- When selected, use grey -->
<item android:drawable="@drawable/ic_tab_albums_grey"
android:state_selected="true" />
<!-- When not selected, use white-->
<item android:drawable="@drawable/ic_tab_albums_white" />
</selector>
- /res/drawable/ic_tabs_artistsdotxml
Code:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- When selected, use grey -->
<item android:drawable="@drawable/ic_tab_artists_grey"
android:state_selected="true" />
<!-- When not selected, use white-->
<item android:drawable="@drawable/ic_tab_artists_white" />
</selector>
- /res/drawable/ic_tabs_songsdotxml
Code:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- When selected, use grey -->
<item android:drawable="@drawable/ic_tab_songs_grey"
android:state_selected="true" />
<!-- When not selected, use white-->
<item android:drawable="@drawable/ic_tab_songs_white" />
</selector>
- /layout/maindotxml
Code:
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<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>
AndroidManifestdotxml
Code:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.android.HelloTabWidget"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="8"/>
<application android:icon="@drawable/ic_launcher" android:label="@string/app_name">
<activity android:name=".HelloTabWidget" 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>
<activity android:name=".AlbumsActivity" android:label="@string/app_name"></activity>
<activity android:name=".ArtistsActivity" android:label="@string/app_name"></activity>
<activity android:name=".SongsActivity" android:label="@string/app_name" ></activity>
</application>
</manifest>