-4

我有这个源代码,我试图让它工作,我从在线教程中获取它。它的问题是我收到一个错误:“不幸的是 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
4

1 回答 1

0

你的日志猫显示NullPointerException

05-06 08:29:03.940: E/AndroidRuntime(757): Caused by: java.lang.NullPointerException

它似乎在第 130 行,AllProductsAct.java 的 asyncTask 的 doInBackground 方法。检查该行应该有一个尚未分配的变量。

05-06 08:29:03.940: E/AndroidRuntime(757):  at com.example.androidhive.AllProductsActivity$LoadAllProducts.doInBackground(AllProductsActivity.java:130)

也发布您的代码。

于 2013-05-06T08:53:32.570 回答