0

我在尝试开发的应用程序上输入一个活动/屏幕时遇到问题。似乎每次我按下按钮打开该活动时,应用程序都会崩溃。这是java文件:

public class login extends Activity{

// all kinds of functions //


protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.login);


    place();

    btn_clr.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view) {
            clearForm();
        }
        });

    btn_back.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view) {
            Intent myIntent = new Intent(view.getContext(), MainActivity.class);
            startActivityForResult(myIntent, 0);
            finish();
        }
        });

}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.login, menu);
    return true;
}

这是 layout.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=".login.java"
android:orientation="vertical" >

// setting all the buttons and texts //

< /RelativeLayout>

这是 menu.xml 文件

< menu xmlns:android="http://schemas.android.com/apk/res/android" >
< item

    android:id="@+id/menu_settings"
    android:orderInCategory="100"
    android:showAsAction="never"
    android:title="@string/log_str"/>

< /menu>

这是对活动的调用:

    btn_log.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view) {
            Intent myIntent = new Intent(view.getContext(), login.class);
            startActivityForResult(myIntent, 0);
            finish();
        }
        });

这两天让我很沮丧。先感谢您

4

1 回答 1

1

在这种情况下,理想的做法是尝试通过调试器查找错误。您可以使用的一个技巧是在每个异常上设置一个断点......这样,一旦抛出异常,它就会中断,您将能够在错误点检查错误和堆栈跟踪.

它在这个答案中进行了描述(具有讽刺意味的是,对于我不久前提出的一个问题:)):https ://stackoverflow.com/a/6342519/5416

在 Eclipse 中,切换到“调试”透视图。在“断点”视图中,您会注意到一个带有 J 和感叹号的小图标(在右上角,靠近视图的“最小化”按钮)。这是添加“异常”断点的触发器。

使用此对话框,您可以告诉调试器暂停以及捕获和未捕获的异常。

于 2013-04-10T17:50:26.693 回答