我在尝试开发的应用程序上输入一个活动/屏幕时遇到问题。似乎每次我按下按钮打开该活动时,应用程序都会崩溃。这是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();
}
});
这两天让我很沮丧。先感谢您