Why is there an error in my code? I’m calling two classes in same package. one is the “BatteryInformation.java” which extends Activity and its function is to get the Battery Info, the next one is “TaskKiller.java” which extends Activity also and its function is to kill running application. This two class has no error and i run it without this UI and it works well. can you please help me?
public class BatteryDoctorSaverActivity extends Activity {
TabHost tabHost;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
tabHost = (TabHost) findViewById(R.id.tabhost);
// Resources res = getResources(); // Resource object to get Drawables
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, BatteryInformation.class);
// Initialize a TabSpec for each tab and add it to the TabHost
spec = tabHost.newTabSpec("Battery Information").setIndicator("")
.setContent(intent);
tabHost.addTab(spec);
// Do the same for the other tabs
intent = new Intent().setClass(this, TaskKiller.class);
spec = tabHost.newTabSpec("Task Killer").setIndicator("TaskKiller")
.setContent(intent);
tabHost.addTab(spec);
tabHost.setCurrentTab(0);
}
}
And here is the LogCat:
01-23 10:30:55.949: D/AndroidRuntime(12278): Shutting down VM
01-23 10:30:55.949: W/dalvikvm(12278): threadid=1: thread exiting with uncaught exception (group=0x40018578)
01-23 10:30:55.949: E/AndroidRuntime(12278): FATAL EXCEPTION: main
01-23 10:30:55.949: E/AndroidRuntime(12278): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=batterydoctorsaver.thesis.BatteryInformation }
01-23 10:30:55.949: E/AndroidRuntime(12278): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1409)
01-23 10:30:55.949: E/AndroidRuntime(12278): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1379)
01-23 10:30:55.949: E/AndroidRuntime(12278): at android.app.Activity.startActivityForResult(Activity.java:2827)
01-23 10:30:55.949: E/AndroidRuntime(12278): at android.app.Activity.startActivity(Activity.java:2933)
01-23 10:30:55.949: E/AndroidRuntime(12278): at batterydoctorsaver.thesis.BatteryDoctorSaverActivity$1.onClick(BatteryDoctorSaverActivity.java:22)
01-23 10:30:55.949: E/AndroidRuntime(12278): at android.view.View.performClick(View.java:2485)
01-23 10:30:55.949: E/AndroidRuntime(12278): at android.view.View$PerformClick.run(View.java:9080)
01-23 10:30:55.949: E/AndroidRuntime(12278): at android.os.Handler.handleCallback(Handler.java:587)
01-23 10:30:55.949: E/AndroidRuntime(12278): at android.os.Handler.dispatchMessage(Handler.java:92)
01-23 10:30:55.949: E/AndroidRuntime(12278): at android.os.Looper.loop(Looper.java:130)
01-23 10:30:55.949: E/AndroidRuntime(12278): at android.app.ActivityThread.main(ActivityThread.java:3687)
01-23 10:30:55.949: E/AndroidRuntime(12278): at java.lang.reflect.Method.invokeNative(Native Method)
01-23 10:30:55.949: E/AndroidRuntime(12278): at java.lang.reflect.Method.invoke(Method.java:507)
01-23 10:30:55.949: E/AndroidRuntime(12278): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
01-23 10:30:55.949: E/AndroidRuntime(12278): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
01-23 10:30:55.949: E/AndroidRuntime(12278): at dalvik.system.NativeStart.main(Native Method)
can anyone help me with this. I’m stack with this UI for almost 2days. i didn’t know what to do. please help me. THANKS FOR THE HELP 🙂
@Lucifer Here is my AndroidManifest.xml file:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="batterydoctorsaver.thesis"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="10" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity
android:label="@string/app_name"
android:name=".BatteryDoctorSaverActivity" >
<intent-filter >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<activity
android:label="@string/app_name"
android:name=".BatteryInformation" >
<intent-filter >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<!-- <activity android:name = ".BatteryInformation"/> -->
</manifest>
@Lucifer here sir:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="batterydoctorsaver.thesis"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="10" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity
android:label="@string/app_name"
android:name=".BatteryDoctorSaverActivity" >
<intent-filter >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".BatteryInformation" />
<activity android:name=".TaskKiller" />
</application>
</manifest>
and here is my code in may BatterDoctorSaverActivity.java:
package batterydoctorsaver.thesis;
import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TabHost;
import batterydoctorsaver.thesis.BatteryInformation;
import batterydoctorsaver.thesis.TaskKiller;
public class BatteryDoctorSaverActivity extends TabActivity {
TabHost tabHost;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
tabHost = getTabHost();
tabHost.setup();
tabHost.addTab(tabHost.newTabSpec("tab1")
.setIndicator("Battery Information")
.setContent(new Intent(this, BatteryInformation.class)));
tabHost.addTab(tabHost.newTabSpec("tab2").setIndicator("Task Killer")
.setContent(new Intent(this, TaskKiller.class)));
// tabHost.addTab(tabHost.newTabSpec("tab3").setIndicator("Updates").setContent(
// new Intent(this, DownloadList.class)));
}
}
You need to add your activity to your AndroidManifest.xml file. All the activity must have an entry to that file.
remove this lines from your code,
instead use following lines.