このプログラムを作成しましたが、このプログラムを実行すると、logCatにlog.e()が表示されず、textViewにメッセージが表示されないため、プログラムはrun()メソッドを読み取ることができません。なんで?
MainActivity.java:
public class MainActivity extends Activity{
private TextView textModifiedThread;
private int threadModifiedInt=4;
private Point threadModifiedPoint=new Point(20,10);
boolean activeThread=true;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Log.e("CREATE", "READ");
textModifiedThread=(TextView)findViewById(R.id.textId);
Thread currentThread=new Thread(){
public void Run(){
Log.e("RUN", "READ");
try{
threadModifiedInt=20;
threadModifiedPoint.set(30, 40);
int timeCounter=100;
while(activeThread&&(timeCounter>0)){
try {
sleep(100);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if(timeCounter%10==0){
threadHandler.sendEmptyMessage((int)timeCounter/10);
Log.e("WHile", "Read");
}
timeCounter--;
}
}finally{
finish();
}
}
};
currentThread.start();
}
@Override
public boolean onTouchEvent(MotionEvent event){
if(event.getAction()==MotionEvent.ACTION_DOWN){
activeThread=false;
Log.e("TOUCH", "READ");
}
return super.onTouchEvent(event);
}
private Handler threadHandler=new Handler(){
public void handleMessage(android.os.Message msg){
textModifiedThread.setText("test int is "+threadModifiedInt+"\ntest point is "+threadModifiedPoint.toString()+"\ncounter is "+Integer.toString(msg.what));
Log.e("ERROR", "Read this");
}
};
}
activity_main.xml:
<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android">
<TextView
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:id="@+id/textId"/>
</LinearLayout>