Caused by: java.lang.NullPointerException 问题
实现登录界面跳转到另一界面代码如下packagecom.yzr.ikichen03;importandroid.R.string;importandroid.suppor...
实现登录界面跳转到另一界面 代码如下
package com.yzr.ikichen03;
import android.R.string;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.app.ActionBar;
import android.support.v4.app.Fragment;
import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import android.os.Build;
public class MainActivity extends ActionBarActivity {
private long mExitTime;
private EditText user1 = null;
private EditText pwd1 = null;
private String user1_s = null;
private String pwd1_s = null;
private Button load = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
load=(Button)findViewById(R.id.button02);
load.setOnClickListener(new intelligenceSystemListener());
}
public boolean onKeyDown(int keyCode,KeyEvent event){
if (keyCode == KeyEvent.KEYCODE_BACK) {
if ((System.currentTimeMillis() - mExitTime) > 2000) {
// Object mHelperUtils;
Toast.makeText(this, "再按一次退出程序", Toast.LENGTH_SHORT).show();
mExitTime = System.currentTimeMillis();
} else {
Intent startMain = new Intent(Intent.ACTION_MAIN);
startMain.addCategory(Intent.CATEGORY_HOME);
startMain.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
finish();
startActivity(startMain);
System.exit(0);
}
return true;
}
return super.onKeyDown(keyCode, event);
}
public class intelligenceSystemListener implements android.view.View.OnClickListener{
public void onClick(View v){
user1=(EditText)findViewById(R.id.edittext01);
pwd1=(EditText)findViewById(R.id.edittext02);
user1_s=user1.getText().toString();
pwd1_s=pwd1.getText().toString();
if((!user1_s.equals(""))&&(!pwd1_s.equals("")))
{
Toast.makeText(MainActivity.this,"登录成功" , Toast.LENGTH_LONG);
Intent intent = new Intent();
intent.setClass(MainActivity.this,IntelligenceSystemActivity.class );
startActivity(intent);
}
else Toast.makeText(MainActivity.this, "登录失败", Toast.LENGTH_LONG);
}
}
}
在AVD中点开APP时提示程序不能打开
LogCat报错为:Caused by: java.lang.NullPointerException 展开
package com.yzr.ikichen03;
import android.R.string;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.app.ActionBar;
import android.support.v4.app.Fragment;
import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import android.os.Build;
public class MainActivity extends ActionBarActivity {
private long mExitTime;
private EditText user1 = null;
private EditText pwd1 = null;
private String user1_s = null;
private String pwd1_s = null;
private Button load = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
load=(Button)findViewById(R.id.button02);
load.setOnClickListener(new intelligenceSystemListener());
}
public boolean onKeyDown(int keyCode,KeyEvent event){
if (keyCode == KeyEvent.KEYCODE_BACK) {
if ((System.currentTimeMillis() - mExitTime) > 2000) {
// Object mHelperUtils;
Toast.makeText(this, "再按一次退出程序", Toast.LENGTH_SHORT).show();
mExitTime = System.currentTimeMillis();
} else {
Intent startMain = new Intent(Intent.ACTION_MAIN);
startMain.addCategory(Intent.CATEGORY_HOME);
startMain.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
finish();
startActivity(startMain);
System.exit(0);
}
return true;
}
return super.onKeyDown(keyCode, event);
}
public class intelligenceSystemListener implements android.view.View.OnClickListener{
public void onClick(View v){
user1=(EditText)findViewById(R.id.edittext01);
pwd1=(EditText)findViewById(R.id.edittext02);
user1_s=user1.getText().toString();
pwd1_s=pwd1.getText().toString();
if((!user1_s.equals(""))&&(!pwd1_s.equals("")))
{
Toast.makeText(MainActivity.this,"登录成功" , Toast.LENGTH_LONG);
Intent intent = new Intent();
intent.setClass(MainActivity.this,IntelligenceSystemActivity.class );
startActivity(intent);
}
else Toast.makeText(MainActivity.this, "登录失败", Toast.LENGTH_LONG);
}
}
}
在AVD中点开APP时提示程序不能打开
LogCat报错为:Caused by: java.lang.NullPointerException 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询