Java setText生成应用程序错误

Java setText生成应用程序错误,java,android,exception,Java,Android,Exception,我有一个简单的Android应用程序 main.xml 在android emulator中执行接收消息后,应用程序测试意外停止。请稍后再试,但是为什么您没有正确地重写onCreate(…)方法。应该是这样的 // NOTE: Use @Override and also the method is 'protected' and not 'public' @Override protected void onCreate(Bundle savedInstanceState) { sup

我有一个简单的Android应用程序 main.xml


在android emulator中执行接收消息
后,应用程序测试意外停止。请稍后再试,但是为什么您没有正确地重写onCreate(…)
方法。应该是这样的

// NOTE: Use @Override and also the method is 'protected' and not 'public'
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    TextView t = (TextView) findViewById(R.id.id_txt);
    t.setText("gone");
}

您需要从设备或模拟器获取日志:“adb logcat”应该可以做到这一点,日志中将有一个堆栈跟踪。或者您可以在设备连接的情况下在Eclipse中使用“显示视图->其他->Android->日志猫”视图。日志猫显示
09-28 19:44:59.724:ERROR/dalvikvm(1727):无法打开堆栈跟踪文件“/data/anr/traces.txt”:权限被拒绝
那么如何更改权限?您是否记得在清单中声明您的活动?如果您谈论的是
AndroidManifest.xml
文件,我没有做任何操作。请写下应该做的事情请包括更多日志文件和AndroidManifest.xml文件的副本。它的默认结构为be eclipseWell eclipse,这使它不正确。。。
package test.android;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

public class TestActivity extends Activity {

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        TextView t = (TextView) findViewById(R.id.id_txt);
        t.setText("gone");
    }
}
// NOTE: Use @Override and also the method is 'protected' and not 'public'
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    TextView t = (TextView) findViewById(R.id.id_txt);
    t.setText("gone");
}