gpt4 book ai didi

android,尝试打开某个 Activity 时应用程序崩溃

转载 作者:行者123 更新时间:2023-12-02 11:36:54 24 4
gpt4 key购买 nike

我在尝试开发的应用程序上输入一个 Activity/屏幕时遇到问题。似乎每次我按下按钮打开该 Activity 时,应用程序都会崩溃。这是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>

这是对 Activity 的调用:

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

郁闷了我两天。预先感谢您

最佳答案

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

这个答案中对此进行了描述(讽刺的是,针对我不久前问过的一个问题:)):https://stackoverflow.com/a/6342519/5416

In Eclipse, switch to the "debug" perspective. In the "Breakpoint" view, you will notice a little icon (at the top right, near the "minimize" button of the view) with a J and an exclamation point. This is the trigger to add "exception" breakpoints.

With this dialog, you can tell the debugger to suspend and caught and uncaught exceptions alike.

关于android,尝试打开某个 Activity 时应用程序崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15932830/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com