【问题标题】:Why application crashes when starting activity?为什么应用程序在启动活动时崩溃?
【发布时间】:2015-09-20 00:28:43
【问题描述】:

我对 eclipse 和 android 完全陌生。我正在尝试使用按钮开始一项新活动。每当我单击按钮时,应用程序就会崩溃。请帮忙。

layout-->activity_main.xml中的代码如下:

<Button
            android:id="@+id/logComplaint"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_alignLeft="@+id/linearLayout1"
            android:layout_gravity="fill"
            android:onClick="getComplaint"
            android:text="@string/logComplaint" />

MainActivity.java中的代码如下:

// --- When LogComplaint button is clicked---      
    public void getComplaint (View V){
        //---Change Form View Log Complaint form---
        Intent nextComplaint = new Intent(getApplicationContext(), LogComplaint.class);
        startActivity (nextComplaint);
    }

AndroidManifest.xml 中的代码是:

<activity android:name=".logComplaint"></activity>

最后,新类中的代码是:

import android.app.Activity;
    import android.os.Bundle;
    import android.view.View;
    import android.widget.AdapterView;
    import android.widget.AdapterView.OnItemSelectedListener;

public class LogComplaint extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.logcomplaintform);  
    }   
}

【问题讨论】:

  • 请把日志也贴出来
  • 你的堆栈跟踪在哪里?确保在清单中使用 LogComplaint
  • android:name=".logComplaint"LogComplaint.class 你不觉得他们不一样吗?

标签: java android eclipse button android-activity


【解决方案1】:

在您的 Manifest 活动声明部分将活动名称从 logComplaint 更改为 LogComplaint

【讨论】:

    【解决方案2】:

    尝试换行:

    <activity android:name=".logComplaint"></activity>
    

    到:

    <activity android:name="your.package.name.LogComplaint"/>
    

    【讨论】:

      【解决方案3】:

      尝试使用-

      Intent nextComplaint = new Intent(MainActivity.this, LogComplaint.class);
      startActivity (nextComplaint);
      instead of  
      Intent nextComplaint = new Intent(getApplicationContext(), LogComplaint.class);
      startActivity (nextComplaint);
      

      还要确保您已在清单文件中声明了 LogComplaint 活动。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-06-02
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多