android语句在TextView中的setText之后不执行
我正在用android开发一个小应用程序。我的activity_main由三个东西按钮组成:TextView和ImageView 这是主要活动的代码android语句在TextView中的setText之后不执行,android,textview,Android,Textview,我正在用android开发一个小应用程序。我的activity_main由三个东西按钮组成:TextView和ImageView 这是主要活动的代码 package com.example.shiv.facedetection; import android.app.Activity; import android.content.Intent; import android.graphics.Bitmap; import android.media.FaceDetector; import
package com.example.shiv.facedetection;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.media.FaceDetector;
import android.media.FaceDetector.Face;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void onthetapbuttonclick(View View){
Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(intent, 0);
}
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// TODO Auto-generated method stub
super.onActivityResult(requestCode, resultCode, data);
try{
Bitmap bp = (Bitmap) data.getExtras().get("data");
ImageView iv = (ImageView)findViewById(R.id.iv1);
Bitmap bitmap565 = bp.copy(Bitmap.Config.RGB_565, true);
if((1==(bitmap565.getWidth()%2))){
bitmap565 = Bitmap.createScaledBitmap(bitmap565,
bitmap565.getWidth()+1, bitmap565.getHeight(), false);
}
FaceDetector fd = new FaceDetector(bitmap565.getWidth(),bitmap565.getHeight(), 4);
Face[] faces =new Face[4];
int i =fd.findFaces(bitmap565, faces);
TextView tv =(TextView)findViewById(R.id.text1);
if(i>0){
iv.setImageBitmap(bp);
System.out.println("face ////////////////detectecd");
tv.setText("faces detected "+i);
}
else{
iv.setImageBitmap(bp);
System.out.println("no face ////////////////detectecd");
tv.setText("No face detected");
System.out.print("hello world");
}
}catch(Exception e ){
System.out.println("exception occured");
}
}
}
主要活动是
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
>
<Button
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:text="click to take the photo"
android:id="@+id/button"
android:onClick="onthetapbuttonclick"/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/text1"
android:text="status"/>
<ImageView
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:id="@+id/iv1"
android:contentDescription="taken photo"
/>
</LinearLayout>
现在的问题是,当我点击图片时,一切都很好。
如果检测到一个人脸,则它将在TextView中显示检测到的人脸+人脸数量,并在ImageView中设置单击的pic,如果未检测到人脸,则将打印未检测到的人脸,但之后不会执行任何语句。
e、 “无脸检测”中的g正在打印,但“hello world”没有打印。
我已尝试使用线程更新TextView。但问题依然存在
我已经对它进行了多次测试,包括针对linux和windows的android studio。请帮忙你说的是日志,不是吗?当然。。。。系统打印语句将显示在日志cati中。我已使用println对其进行了正确测试,甚至从终端过滤了带有规则表达式的logcat
adb logcat | grep-i“hello world”
是否打印任何内容?不,这是最奇怪的情况