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

标签 android android-activity crash screen

我在尝试开发的应用程序上输入一个 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/

相关文章:

android - 防止或避免 Android 应用程序中的多次点击(Kotlin 语言)

xcode - Xcode 5.0在10.9崩溃

Android 语音转文本问题

android - Intent.FLAG_ACTIVITY_CLEAR_TOP 即使应用程序在后台也会导致 Activity 弹出?

android - 将 AppCompat 工具栏与 FrameLayout 一起使用

android - 从另一个类调用 Activity - Android

ios - 我的 UE4 演示应用程序在启动后崩溃

java - 使用显式 Intent 时应用程序崩溃

android - 语音或语音识别器是否有可能从说话者那里获取输入(来电语音)?

android - 使用随机数生成显示数组列表中的图像