gpt4 book ai didi

java - Android 代码在后端出现错误。但我不知道代码哪里出了问题

转载 作者:行者123 更新时间:2023-12-01 11:57:09 25 4
gpt4 key购买 nike

我不知道我的代码出了什么问题。它不会显示该页面,并且我确定错误出现在 Java 代码中的某个位置。因为我检查布局及其工作是否完美,直到我放置后端。但我就是不知道错误在哪里。所以请有人帮助我。

package calculator.apk;

import android.support.v7.app.ActionBarActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Toast;

public class signMeup extends ActionBarActivity {

Button sign;
EditText name,birthD,birthM,birthY,pass;
String fname,passWord,bdate,bmonth,byear,gender;
CheckBox checkgen;
RadioButton female, male;
RadioGroup group;

int inputField;


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_signup);

name = (EditText) findViewById (R.id.editText1);
birthD = (EditText) findViewById (R.id.editText2);
birthM = (EditText) findViewById (R.id.editText3);
birthY = (EditText) findViewById (R.id.editText4);
pass = (EditText) findViewById (R.id.editText5);
male =(RadioButton) findViewById (R.id.radioButton1);
female =(RadioButton) findViewById (R.id.radioButton2);
group = (RadioGroup)findViewById(R.id.radioGroup);

sign.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
try{
fname = name.getText().toString();
checkInput (fname);
bdate = birthD.getText().toString();
checkInput(bdate);
bmonth = birthM.getText().toString();
checkInput(bmonth);
byear = birthY.getText().toString();
checkInput(byear);
passWord = pass.getText().toString();
checkInput(passWord);
checkRadioButton();


Intent intent = new Intent(getBaseContext(), profile.class);
intent.putExtra("fName", fname);
intent.putExtra("bDate", bdate);
intent.putExtra("bMonth", bmonth);
intent.putExtra("bYear", byear);
intent.putExtra("pWord", passWord);
intent.putExtra("genDer", gender);

startActivity(intent);
}
catch (Exception e) {
// do nothing
}

}
});
}

public void checkRadioButton()
{

int index = group.getCheckedRadioButtonId();
if(index==-1){
inputField++;
}
else{
//Checking for Male
if(male.isChecked()){
gender="Male";
Toast.makeText(getApplicationContext(), "You selected Male.", Toast.LENGTH_SHORT).show();
}
//Checking for Female
else if(female.isChecked()){
gender="Female";
Toast.makeText(getApplicationContext(), "You selected Female.", Toast.LENGTH_SHORT).show();
}
}
}

public void checkInput(String input)
{
if(input.matches("")){
inputField++;
}
}


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

@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}

最佳答案

在下面的行中,您将得到 NULL POINTER EXCEPTION

sign.setOnClickListener(new View.OnClickListener() {

因为您从未像其他属性一样初始化您的按钮标志

sign = (Button)findViewById(R.id.yourButtonId);

关于java - Android 代码在后端出现错误。但我不知道代码哪里出了问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28368399/

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