当前位置:   article > 正文

java实体类set方法报空指针异常_java – 在.setOnClickListener上的空指针异常

java中set的时候报空指针

我遇到一个点击监听器的登录模式提交按钮的问题.

这是错误.

Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.Button.setOnClickListener(android.view.View$OnClickListener)' on a null object reference

我有一个合理的理解,一个空指针异常是什么,我有一个类似于我的问题彻底搜索.我已经尝试以多种方式重新格式化点击监听器,确保我有正确的视图ID等.

package...

import...

public class MainActivity extends ActionBarActivity implements NavigationDrawerFragment.NavigationDrawerCallbacks {

//Variables

String currentPage = "";

Stack crumbs = new Stack();

//Fragment managing the behaviors,interactions and presentation of the navigation drawer.

private NavigationDrawerFragment mNavigationDrawerFragment;

// Used to store the last screen title. For use in {@link #restoreActionBar()}.

public CharSequence mTitle;

//temp

AuthenticateUserTokenResult authenticateUserTokenResult;

String loginErrorMessage = "";

String loginErrorTitle = "";

Boolean logonSuccessful = false;

Dialog loginDialog;

// Login EditTexts

EditText Username;

EditText CompanyID;

EditText Password;

Button Submit;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

mNavigationDrawerFragment = (NavigationDrawerFragment) getSupportFragmentManager().findFragmentById(R.id.navigation_drawer);

mTitle = getTitle(); // Set up the drawer.

mNavigationDrawerFragment.setUp(R.id.navigation_drawer,(DrawerLayout) findViewById(R.id.drawer_layout));

if(authenticateUserTokenResult == null) {

attemptLogin();

}

}

public void attemptLogin() {

loginDialog = new Dialog(this,android.R.style.Theme_Translucent_NoTitleBar);

loginDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);

loginDialog.setContentView(R.layout.login_modal);

loginDialog.setCancelable(false);

//loginDialog.setOnCancelListener(cancelListener);

loginDialog.show();

Submit = (Button)findViewById(R.id.Submit);

Submit.setOnClickListener(new View.OnClickListener() // the error is on this line (specifically the .setOnClickListener)

{

@Override

public void onClick(View v)

{

ClyxUserLogin user = new ClyxUserLogin();

Username = (EditText)findViewById(R.id.Username);

user.logon = Username.getText().toString();

CompanyID = (EditText)findViewById(R.id.CompanyID);

user.idCompany = Integer.parseInt(CompanyID.getText().toString());

Password = (EditText)findViewById(R.id.Password);

user.password = Password.getText().toString();

user.idApplication = 142;

authenticate(user);

}

});

}

显而易见,但与我认为的话题无关.

以下是对话框的XML文件,其上有按钮.

android:orientation="vertical"

android:layout_width="fill_parent"

android:layout_height="fill_parent"

android:background="#3366FF">

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_centerInParent="true"

android:background="#FFFFFF" >

android:id="@+id/LoginTitle"

android:layout_width="200dp"

android:layout_height="wrap_content"

android:gravity="center_horizontal"

android:layout_marginTop="10dp"

android:layout_marginStart="10dp"

android:textColor="#000000"

android:textSize="20sp"

android:text="Login" />

android:id="@+id/Username"

android:layout_width="200dp"

android:layout_height="wrap_content"

android:layout_below="@+id/LoginTitle"

android:layout_margin="10dp"

android:hint="Username" />

android:id="@+id/CompanyID"

android:layout_width="200dp"

android:layout_height="wrap_content"

android:layout_below="@+id/Username"

android:layout_alignStart="@+id/Username"

android:inputType="number"

android:hint="Company ID" />

android:id="@+id/Password"

android:layout_width="200dp"

android:layout_height="wrap_content"

android:layout_below="@+id/CompanyID"

android:layout_alignStart="@+id/Username"

android:layout_marginTop="10dp"

android:layout_marginBottom="10dp"

android:inputType="textPassword"

android:hint="Password" />

android:id="@+id/Submit"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_below="@+id/Password"

android:layout_marginBottom="10dp"

android:layout_centerHorizontal="true"

android:text="Login" />

任何帮助将不胜感激.

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Monodyee/article/detail/141673
推荐阅读
相关标签
  

闽ICP备14008679号