アプリのタイマーを作成しましたが、listActivity から開こうとするとクラッシュして例外がスローされ続けます
コードは以下にあり、重要なものだけを掲載しました
ツール.java
package com.example.taekwondobuddy.util;
import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
public class Tools extends ListActivity{
String classes[] = {"Counter","Accelermeter","Time"} ;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setListAdapter(new ArrayAdapter<String>(Tools.this, android.R.layout.simple_list_item_1, classes));
}
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
// TODO Auto-generated method stub
super.onListItemClick(l, v, position, id);
String cheese = classes[position];
try{
Class ourclass = Class.forName("com.example.taekwondobuddy.util." + cheese);
Intent ourIntent = new Intent(Tools.this, ourclass);
startActivity(ourIntent);
} catch(ClassNotFoundException e){
e.printStackTrace();
}
}
}
time.java
package com.example.taekwondobuddy.util;
import java.util.Timer;
import java.util.TimerTask;
import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
public class Time extends Activity {
TextView mTextView;
Button mButtonStart;
Button mButtonStop;
int mCount;
Timer mTimer;
Handler mHandler = new Handler();
Runnable TheDelegatedTimerTask = new Runnable() {
@Override
public void run() {
mCount++;
mTextView.setText("Count=" + mCount);
}
};
protected class TheTimerTask extends TimerTask {
@Override
public void run() {
// What we want to say is
// mCount++;
// mTextView.setText("Count="+mCount);
// But this gives
// "Only the original thread that created a view hierarchy can touch its views."
mHandler.post(TheDelegatedTimerTask);
}
}
protected void timerStart() {
if (mTimer == null) {
mTimer = new Timer();
mTimer.schedule(new TheTimerTask(), 0, 100); // 100 milli seconds
}
}
protected void timerStop() {
if (mTimer != null) {
mTimer.cancel();
mTimer = null;
}
}
OnClickListener mButtonStart_OnClick = new OnClickListener() {
@Override
public void onClick(View v) {
mCount = 0;
timerStart();
}
};
OnClickListener mButtonStop_OnClick = new OnClickListener() {
@Override
public void onClick(View v) {
timerStop();
}
};
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.timer);
mTextView = (TextView) findViewById(R.id.textview);
mButtonStart = (Button) findViewById(R.id.buttonstart);
mButtonStop = (Button) findViewById(R.id.buttonstop);
mButtonStart.setOnClickListener(mButtonStart_OnClick);
mButtonStop.setOnClickListener(mButtonStop_OnClick);
}
}
timer.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<TextView
android:id="@+id/textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="26dp"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge" />
<Button
android:id="@+id/buttonstart"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textview"
android:layout_below="@+id/textview"
android:layout_marginTop="50dp"
android:text="Start" />
<Button
android:id="@+id/buttonstop"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/buttonstart"
android:layout_centerVertical="true"
android:text="Stop" />
</RelativeLayout
何が問題なのですか?
編集
エラーログ
10-31 02:44:52.053: E/AndroidRuntime(304): FATAL EXCEPTION: main
10-31 02:44:52.053: E/AndroidRuntime(304): android.content.ActivityNotFoundException: Unable to find explicit activity class {com.example.taekwondobuddy.util/com.example.taekwondobuddy.util.Time}; have you declared this activity in your AndroidManifest.xml?
10-31 02:44:52.053: E/AndroidRuntime(304): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1404)
10-31 02:44:52.053: E/AndroidRuntime(304): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1378)
10-31 02:44:52.053: E/AndroidRuntime(304): at android.app.Activity.startActivityForResult(Activity.java:2817)
10-31 02:44:52.053: E/AndroidRuntime(304): at android.app.Activity.startActivity(Activity.java:2923)
10-31 02:44:52.053: E/AndroidRuntime(304): at com.example.taekwondobuddy.util.Tools.onListItemClick(Tools.java:30)
10-31 02:44:52.053: E/AndroidRuntime(304): at android.app.ListActivity$2.onItemClick(ListActivity.java:321)
10-31 02:44:52.053: E/AndroidRuntime(304): at android.widget.AdapterView.performItemClick(AdapterView.java:284)
10-31 02:44:52.053: E/AndroidRuntime(304): at android.widget.ListView.performItemClick(ListView.java:3382)
10-31 02:44:52.053: E/AndroidRuntime(304): at android.widget.AbsListView$PerformClick.run(AbsListView.java:1696)
10-31 02:44:52.053: E/AndroidRuntime(304): at android.os.Handler.handleCallback(Handler.java:587)
10-31 02:44:52.053: E/AndroidRuntime(304): at android.os.Handler.dispatchMessage(Handler.java:92)
10-31 02:44:52.053: E/AndroidRuntime(304): at android.os.Looper.loop(Looper.java:123)
10-31 02:44:52.053: E/AndroidRuntime(304): at android.app.ActivityThread.main(ActivityThread.java:4627)
10-31 02:44:52.053: E/AndroidRuntime(304): at java.lang.reflect.Method.invokeNative(Native Method)
10-31 02:44:52.053: E/AndroidRuntime(304): at java.lang.reflect.Method.invoke(Method.java:521)
10-31 02:44:52.053: E/AndroidRuntime(304): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
10-31 02:44:52.053: E/AndroidRuntime(304): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
10-31 02:44:52.053: E/AndroidRuntime(304): at dalvik.system.NativeStart.main(Native Method)