将我的主类重命名为“Main”,将我的主xml重命名为“main”后,我可以启动我的应用程序。 我一直得到这个logcat:
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 & 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开头
答案 0 :(得分:1)
它似乎仍在尝试启动活动“ComponentInfo”。如果您更改了所有文件,但未更改包名称,则可能是在旧版本的基础上安装新应用程序,旧启动程序指向旧活动,该活动已不再存在。
简而言之:尝试删除旧应用程序并重新安装。
答案 1 :(得分:0)
Main.java第116行有一个NullPointerException
(您的活动)。应该很容易找到自己,或者在这里发布Main.java的代码。
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)
答案 2 :(得分:0)
我通过创建一个新项目修复它并将我的所有文件复制到该项目但我没有替换主类或布局而是复制并粘贴了这两个类的内部代码但保留了类名。这样,班级名称是正确的。