Android Studio开发错误

时间:2014-03-28 03:44:25

标签: android android-studio

我有教程视频中的代码,在运行时会自动关闭应用程序。我试图调试它并得到以下错误 -

03-27 23:42:14.538    1330-1330/com.testing W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0xb3ababa8)
03-27 23:42:14.598    1330-1330/com.testing E/AndroidRuntime﹕ FATAL EXCEPTION: main
    Process: com.testing, PID: 1330
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.testing/com.testing.MainActivity}: java.lang.NullPointerException
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
            at android.app.ActivityThread.access$800(ActivityThread.java:135)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:136)
            at android.app.ActivityThread.main(ActivityThread.java:5017)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:515)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
            at dalvik.system.NativeStart.main(Native Method)
     Caused by: java.lang.NullPointerException
            at com.testing.MainActivity.onCreate(MainActivity.java:35)
            at android.app.Activity.performCreate(Activity.java:5231)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
            at android.app.ActivityThread.access$800(ActivityThread.java:135)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:136)
            at android.app.ActivityThread.main(ActivityThread.java:5017)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:515)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
            at dalvik.system.NativeStart.main(Native Method)

  package com.testing;

    import android.support.v7.app.ActionBarActivity;
    import android.support.v7.app.ActionBar;
    import android.support.v4.app.Fragment;
    import android.os.Bundle;
    import android.text.Editable;
    import android.text.TextWatcher;
    import android.view.LayoutInflater;
    import android.view.Menu;
    import android.view.MenuItem;
    import android.view.View;
    import android.view.ViewGroup;
    import android.os.Build;
    import android.widget.Button;
    import android.widget.EditText;
    import android.widget.TabHost;

    public class MainActivity extends ActionBarActivity {

        EditText Nome, Phone, Email;


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


            Nome = (EditText) findViewById(R.id.txtNome);
            Phone = (EditText) findViewById(R.id.txtPhone);
            Email = (EditText) findViewById(R.id.txtEmail);
            TabHost tabHost = (TabHost) findViewById(R.id.tabHost);

            tabHost.setup();

            TabHost.TabSpec tabSpec = tabHost.newTabSpec("Creator");
            tabSpec.setContent(R.id.tabCreator);
            tabSpec.setIndicator("Creator");
            tabHost.addTab(tabSpec);

            tabSpec = tabHost.newTabSpec("list");
            tabSpec.setContent(R.id.tabContact);
            tabSpec.setIndicator("list");
            tabHost.addTab(tabSpec);

            final Button addBtn = (Button) findViewById(R.id.bntEnviar);
        }


        @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);
            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);
        }

}

我做错了什么?

我的aplication文件位于调试文件下,只需向下滑动条。

1 个答案:

答案 0 :(得分:0)

你有一个空指针异常,意思是,你试图使用一个你可能没有初始化的对象。

如果您发布活动课程,这将非常有用。