我一直在编写一个应用程序,在我想做测试的时候,eclipse Logcat 给了我以下日志,我不知道为什么会这样,手机和模拟器给出“不幸的是你的应用程序已停止”消息:
07-26 19:47:03.880: W/dalvikvm(834): threadid=1: thread exiting with uncaught exception (group=0x40a71930)
07-26 19:47:03.910: E/AndroidRuntime(834): FATAL EXCEPTION: main
07-26 19:47:03.910: E/AndroidRuntime(834): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.xanmaya.kapschfinal/com.xanmaya.kapschfinal.MainActivity}: java.lang.NullPointerException
07-26 19:47:03.910: E/AndroidRuntime(834): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2106)
07-26 19:47:03.910: E/AndroidRuntime(834): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
07-26 19:47:03.910: E/AndroidRuntime(834): at android.app.ActivityThread.access$600(ActivityThread.java:141)
07-26 19:47:03.910: E/AndroidRuntime(834): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
07-26 19:47:03.910: E/AndroidRuntime(834): at android.os.Handler.dispatchMessage(Handler.java:99)
07-26 19:47:03.910: E/AndroidRuntime(834): at android.os.Looper.loop(Looper.java:137)
07-26 19:47:03.910: E/AndroidRuntime(834): at android.app.ActivityThread.main(ActivityThread.java:5041)
07-26 19:47:03.910: E/AndroidRuntime(834): at java.lang.reflect.Method.invokeNative(Native Method)
07-26 19:47:03.910: E/AndroidRuntime(834): at java.lang.reflect.Method.invoke(Method.java:511)
07-26 19:47:03.910: E/AndroidRuntime(834): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
07-26 19:47:03.910: E/AndroidRuntime(834): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
07-26 19:47:03.910: E/AndroidRuntime(834): at dalvik.system.NativeStart.main(Native Method)
07-26 19:47:03.910: E/AndroidRuntime(834): Caused by: java.lang.NullPointerException
07-26 19:47:03.910: E/AndroidRuntime(834): at android.app.Activity.findViewById(Activity.java:1839)
07-26 19:47:03.910: E/AndroidRuntime(834): at com.xanmaya.kapschfinal.MainActivity.<init>(MainActivity.java:36)
07-26 19:47:03.910: E/AndroidRuntime(834): at java.lang.Class.newInstanceImpl(Native Method)
07-26 19:47:03.910: E/AndroidRuntime(834): at java.lang.Class.newInstance(Class.java:1319)
07-26 19:47:03.910: E/AndroidRuntime(834): at android.app.Instrumentation.newActivity(Instrumentation.java:1054)
07-26 19:47:03.910: E/AndroidRuntime(834): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2097)
07-26 19:47:03.910: E/AndroidRuntime(834): ... 11 more
这是代码:
package com.xanmaya.kapschfinal;
import android.net.Uri;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
Button btnEnviar = (Button) findViewById(R.id.btnEnviar);
btnEnviar.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
}}
);
return true;
}
EditText etModulo = (EditText) findViewById(R.id.etModulo);
EditText etAmpli = (EditText) findViewById(R.id.etAmpli);
EditText etAntena = (EditText) findViewById(R.id.etAntena);
EditText etCable = (EditText) findViewById(R.id.etCable);
EditText etFecha = (EditText) findViewById(R.id.etFecha);
EditText etlugar = (EditText) findViewById(R.id.etlugar);
EditText etenvia = (EditText) findViewById(R.id.etenvia);
CheckBox checkampli = (CheckBox) findViewById(R.id.checkampli);
CheckBox checkantena = (CheckBox) findViewById(R.id.checkantena);
CheckBox checkmodulo = (CheckBox) findViewById(R.id.checkmodulo);
CheckBox checkcable = (CheckBox) findViewById(R.id.checkcable);
{
Intent emailIntent = new Intent(Intent.ACTION_SENDTO);
emailIntent.setData(Uri.parse("mailto:"));
emailIntent.putExtra(Intent.EXTRA_EMAIL, "villasantdesign@gmail.com");
emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Resumen");
emailIntent.putExtra(Intent.EXTRA_TEXT, etModulo.getText()); etAntena.getText(); etCable.getText(); etlugar.getText(); etFecha.getText(); etAmpli.getText();}{;
Intent emailIntent = new Intent(Intent.ACTION_SENDTO);
emailIntent.setType("message/rfc822");
startActivity(Intent.createChooser(emailIntent, "btnEnviar"));}}`code:
非常感谢您的帮助!谢谢!