android中的java.lang.nullpointerexception [英] java.lang.nullpointerexception in android
本文介绍了android中的java.lang.nullpointerexception的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨所有:)
当我尝试午餐登录活动时我有这个例外
01-12 21:04:28.994:E / AndroidRuntime(1442):java.lang.RuntimeException:无法启动活动ComponentInfo {com.msagroup.sbhmg / com.msagroup.sbhmg.LogIn}:java.lang。 NullPointerException
这里是我的.XML文件:
hi all :)
I have this exception when I try to lunch log in activity in android
01-12 21:04:28.994: E/AndroidRuntime(1442): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.msagroup.sbhmg/com.msagroup.sbhmg.LogIn}: java.lang.NullPointerException
here is my .XML file:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<EditText
android:id="@+id/etmail"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginTop="41dp"
android:inputType="textEmailAddress"
android:text="@string/email" >
<requestFocus />
</EditText>
<EditText
android:id="@+id/etpassword"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/etmail"
android:layout_marginTop="16dp"
android:inputType="textPassword"
android:text="@string/password"/>
<Button
android:id="@+id/btnlogin"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/etpassword"
android:layout_marginTop="16dp"
android:text="@string/login" />
<TextView
android:id="@+id/tvcomment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:text="@string/empty" />
</RelativeLayout>
< br $>
和.Java文件:
and .Java file:
package com.msagroup.sbhmg;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class LogIn extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.login);
Button _gotousermain = (Button) findViewById(R.id.btngotoenglishmain);
EditText _etmail = (EditText) findViewById(R.id.etmail);
EditText _etpassword = (EditText) findViewById(R.id.etmail);
final String _email = _etmail.getText().toString();
final String _pass = _etpassword.getText().toString();
final TextView _tvcomm = (TextView) findViewById(R.id.tvcomment);
_gotousermain.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
if(_email == "msay@live.com" && _pass == "123")
{
startActivity(new Intent(LogIn.this, ArMain.class));
}
else
{
if(_email == "msay@live.com" && _pass == "123")
{
startActivity(new Intent(LogIn.this, ArMain.class));
}
else
{
_tvcomm.setText("Invalid Info. !");
}
}
}
});
}
}
谢谢大家:)
thank you all :)
推荐答案
我发现了问题
这是一个愚蠢的问题:\
IDbtngotoenglishmain
at
Button _gotousermain =(Button )findViewById(R.id.btngotoenglishmain);
在xml文件中不存在
谢谢大家:)
I found the problem
it was a stupid one :\
the ID "btngotoenglishmain"
at
Button _gotousermain = (Button) findViewById(R.id.btngotoenglishmain);
is not exists at the xml file
thank you all :)
这篇关于android中的java.lang.nullpointerexception的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文