将主类重命名为“ Main”,并将主xml重命名为“ main”后,我可以启动我的应用程序。
我不断收到这个日志:

08-28 21:46:27.563: D/AndroidRuntime(264): Shutting down VM
08-28 21:46:27.563: W/dalvikvm(264): threadid=3: thread exiting with uncaught exception (group=0x4001b188)
08-28 21:46:27.563: E/AndroidRuntime(264): Uncaught handler: thread main exiting due to uncaught exception
08-28 21:46:27.623: E/AndroidRuntime(264): java.lang.RuntimeException: Unable to start activity ComponentInfo{noc.support/noc.support.Main}: java.lang.NullPointerException
08-28 21:46:27.623: E/AndroidRuntime(264):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2496)
08-28 21:46:27.623: E/AndroidRuntime(264):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2512)
08-28 21:46:27.623: E/AndroidRuntime(264):  at android.app.ActivityThread.access$2200(ActivityThread.java:119)
08-28 21:46:27.623: E/AndroidRuntime(264):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1863)
08-28 21:46:27.623: E/AndroidRuntime(264):  at android.os.Handler.dispatchMessage(Handler.java:99)
08-28 21:46:27.623: E/AndroidRuntime(264):  at android.os.Looper.loop(Looper.java:123)
08-28 21:46:27.623: E/AndroidRuntime(264):  at android.app.ActivityThread.main(ActivityThread.java:4363)
08-28 21:46:27.623: E/AndroidRuntime(264):  at java.lang.reflect.Method.invokeNative(Native Method)
08-28 21:46:27.623: E/AndroidRuntime(264):  at java.lang.reflect.Method.invoke(Method.java:521)
08-28 21:46:27.623: E/AndroidRuntime(264):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
08-28 21:46:27.623: E/AndroidRuntime(264):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
08-28 21:46:27.623: E/AndroidRuntime(264):  at dalvik.system.NativeStart.main(Native Method)
08-28 21:46:27.623: E/AndroidRuntime(264): Caused by: java.lang.NullPointerException
08-28 21:46:27.623: E/AndroidRuntime(264):  at noc.support.Main.onCreate(Main.java:116)
08-28 21:46:27.623: E/AndroidRuntime(264):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
08-28 21:46:27.623: E/AndroidRuntime(264):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2459)
08-28 21:46:27.623: E/AndroidRuntime(264):  ... 11 more
08-28 21:46:27.653: I/dalvikvm(264): threadid=7: reacting to signal 3
08-28 21:46:27.663: I/dalvikvm(264): Wrote stack trace to '/data/anr/traces.txt'
08-28 21:47:07.853: I/Process(264): Sending signal. PID: 264 SIG: 9


表现:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="noc.support"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk android:minSdkVersion="7" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />


    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" android:debuggable="true">

        <service android:name=".BootListnerService" android:label="Boot Service">
            <intent-filter>
                <action android:name="noc.support.BootListnerService" />
            </intent-filter>
        </service>

        <receiver
            android:name=".BootListnerServiceReceiver"
            android:enabled="true"
            android:exported="true"
            android:label="BootListnerServiceReceiver">
            <intent-filter>
                <action android:name="android.intent.action.BOOT_COMPLETED" />
            </intent-filter>
        </receiver>


        <activity
            android:name=".Main"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <activity android:name=".Register" android:label="Register"></activity>

        <activity android:name=".Settings" android:label="Settings"></activity>

        <activity android:name=".ServersStatus" android:label="Servers Status"></activity>

    </application>

</manifest>


这是main.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/emailLable"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/textView1"
        android:layout_marginTop="40dp"
        android:text="Email:"
        android:textAppearance="?android:attr/textAppearanceMedium" android:layout_marginLeft="5dp"/>

    <EditText
        android:id="@+id/emailField"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:ems="10" android:layout_marginLeft="5dp" android:layout_marginRight="5dp"
        android:inputType="textEmailAddress" />

    <TextView
        android:id="@+id/passwordLable"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/editText1"
        android:layout_marginTop="36dp"
        android:text="Password:"
        android:textAppearance="?android:attr/textAppearanceMedium" android:layout_marginLeft="5dp"/>


    <EditText
        android:id="@+id/passwordField"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:ems="10"
        android:inputType="textPassword"
        android:layout_marginLeft="5dp" android:layout_marginRight="5dp"/>

    <CheckBox
        android:id="@+id/rememberEmailPasswordCheckBox"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Remember my email &amp; password" />

    <CheckBox
        android:id="@+id/loginAutomaticallyCheckBox"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Login automatically" />

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" android:paddingLeft="5dp" android:paddingRight="5dp" android:layout_marginTop="40dp">


        <Button
            android:id="@+id/addButton"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1.05"
            android:text="Add" />




        <Button
            android:id="@+id/refreshButton"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="0.86"
            android:text="Refresh" />

    </LinearLayout>

</LinearLayout>


我究竟做错了什么?

没有人有任何想法。

我用谷歌搜索,但找不到解决方法。

当我更改“ setContentView(R.layout.main);”时到任何其他布局都可以正常工作,但是我需要此类以main.xml开头

最佳答案

看来它仍在尝试启动活动“ ComponentInfo”。如果更改了所有文件,但未更改软件包名称,则可能是在旧应用程序的顶部安装了新应用程序,而旧启动器指向的旧活动已不存在。

简而言之:尝试删除旧应用程序并重新安装。

10-07 12:40
查看更多