我有这个源代码,我试图让它工作,我从在线教程。 它的问题是我得到一个错误: “不幸的是,MainScreen已经停止了”;
现在,我在网上寻找可能的解决方案并发现它可能在AndroidManifest.xml中,并且我将ap的名称更改为com.example.androidhive并且没有机会了......
以下是代码:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.androidhive"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="8" />
<application
android:configChanges="keyboardHidden|orientation"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity
android:name=".MainScreenActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<!-- All Product Activity -->
<activity
android:name=".AllProductsActivity"
android:label="All Products" >
</activity>
<!-- Add Product Activity -->
<activity
android:name=".NewProductActivity"
android:label="Add New Product" >
</activity>
<!-- Edit Product Activity -->
<activity
android:name=".EditProductActivity"
android:label="Edit Product" >
</activity>
</application>
<!-- Internet Permissions -->
<uses-permission android:name="android.permission.INTERNET" />
</manifest>
谢谢..
日志
05-06 08:29:03.940: E/AndroidRuntime(757): FATAL EXCEPTION: AsyncTask #1
05-06 08:29:03.940: E/AndroidRuntime(757): java.lang.RuntimeException: An error occured while executing doInBackground()
05-06 08:29:03.940: E/AndroidRuntime(757): at android.os.AsyncTask$3.done(AsyncTask.java:299)
05-06 08:29:03.940: E/AndroidRuntime(757): at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
05-06 08:29:03.940: E/AndroidRuntime(757): at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
05-06 08:29:03.940: E/AndroidRuntime(757): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
05-06 08:29:03.940: E/AndroidRuntime(757): at java.util.concurrent.FutureTask.run(FutureTask.java:137)
05-06 08:29:03.940: E/AndroidRuntime(757): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
05-06 08:29:03.940: E/AndroidRuntime(757): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
05-06 08:29:03.940: E/AndroidRuntime(757): at java.lang.Thread.run(Thread.java:856)
05-06 08:29:03.940: E/AndroidRuntime(757): Caused by: java.lang.NullPointerException
05-06 08:29:03.940: E/AndroidRuntime(757): at com.example.androidhive.AllProductsActivity$LoadAllProducts.doInBackground(AllProductsActivity.java:130)
05-06 08:29:03.940: E/AndroidRuntime(757): at com.example.androidhive.AllProductsActivity$LoadAllProducts.doInBackground(AllProductsActivity.java:1)
05-06 08:29:03.940: E/AndroidRuntime(757): at android.os.AsyncTask$2.call(AsyncTask.java:287)
05-06 08:29:03.940: E/AndroidRuntime(757): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
05-06 08:29:03.940: E/AndroidRuntime(757): ... 4 more
答案 0 :(得分:0)
您的日志猫显示NullPointerException
05-06 08:29:03.940: E/AndroidRuntime(757): Caused by: java.lang.NullPointerException
它似乎在No: - AllProductsAct.java的130个asyncTask的doInBackground方法中。检查该行应该有一个尚未分配的变量。
05-06 08:29:03.940: E/AndroidRuntime(757): at com.example.androidhive.AllProductsActivity$LoadAllProducts.doInBackground(AllProductsActivity.java:130)
也发布你的代码。