活動を始めたいので、この授業方法を選びました。インテント コンストラクターで ACTION NAME を直接渡すことで簡単に実行できることはわかっていますが、Android を学んでいるので、新しい方法を学ぼうとしています。他のクラスで同じコードを使用して別のアクティビティを開始し、そこで動作しましたが、ここでは次のエラーが発生しています。THREADクラスに何か関係があると思います。
エラーは次のとおりです。
The constructor Intent(new Thread(){}, Class) is undefined.
どうすればこれを解決できますか? コードは次のとおりです。
package com.umer.practice2;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
public class SplashScreen extends Activity{
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.splashscreen);
Thread timer= new Thread()
{
public void run()
{
try
{
sleep(5000);
}
catch(Exception e)
{
e.printStackTrace();
}
finally
{
Class ourclass = Class.forName("com.umer.practice2.StartingPoint");
Intent myintent= new Intent(this,ourclass); // error
startActivity(myintent);
}
}
};
timer.start();
}
@Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
finish();
}
}
強制終了エラーが発生しているクラス アクティビティのレイアウトを次に示します。
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="hint"
android:id="@+id/fdisp"
/>
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="How many times you eat in a day"
android:gravity="center"
android:id="@+id/but3"
/>
</LinearLayout>
これがクラス自体のコードです
package com.umer.practice2;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
public class MyClass extends Activity{
Button b3;
TextView disp;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
b3= (Button) findViewById(R.id.but3);
disp= (TextView) findViewById(R.id.fdisp);
b3.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
disp.setText("It depends ");
}
});
}
}