Android应用程序错误

时间:2013-04-24 09:57:52

标签: android android-manifest

我在测试应用程序中构建了我的应用程序的一些元素,并且已经将元素复制到我的主应用程序中,但是当我运行它时,应用程序就会爆炸。

我觉得我的Manifest存在问题,但我无法确定它。这是我的表现: -

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


<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/CustomTheme">
   <activity
        android:name=".MainActivity"
        android:label="@string/app_name" 
        android:screenOrientation="portrait">
    <intent-filter>
            <action android:name="android.intent.action.MAIN" />

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

    <activity android:name=".CustomizedListView" 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=".DetailsActivity"
        android:label="@string/app_name" 
        android:screenOrientation="portrait">
     <intent-filter>
            <action android:name="android.intent.action.MAIN" />

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

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

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

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

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

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

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

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

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

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

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



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

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

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

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


  <meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaSyAioYkrj1Wl44z2LQvTCOw6GXPXdTroGng"/>      

</application>

 <permission
android:name="com.example.mapdemo.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-permission android:name="com.example.mapdemo.permission.MAPS_RECEIVE"/>

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />     
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

 <uses-feature
android:glEsVersion="0x00020000"
android:required="true"/>

<uses-sdk android:minSdkVersion="11" />

有人能看到问题吗?

我的LogCat中的这一行让我担心: -

04-24 11:42:16.769: D/dalvikvm(18849): Late-enabling CheckJNI
04-24 11:42:16.794: I/dalvikvm(18849): Turning on JNI app bug workarounds for target SDK version 11...
04-24 11:42:16.799: E/jdwp(18849): Failed sending reply to debugger: Broken pipe
04-24 11:42:16.799: D/dalvikvm(18849): Debugger has detached; object registry had 1 entries
04-24 11:42:16.904: D/AbsListView(18849): Get MotionRecognitionManager
04-24 11:42:16.914: D/AndroidRuntime(18849): Shutting down VM
04-24 11:42:16.914: W/dalvikvm(18849): threadid=1: thread exiting with uncaught exception (group=0x41b082a0)
04-24 11:42:16.914: E/AndroidRuntime(18849): FATAL EXCEPTION: main
04-24 11:42:16.914: E/AndroidRuntime(18849): java.lang.RuntimeException: Unable to start activity ComponentInfo{police.uk.greatermanchesterpoliceandroid/police.uk.greatermanchesterpoliceandroid.CustomizedListView}: android.os.NetworkOnMainThreadException
04-24 11:42:16.914: E/AndroidRuntime(18849):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2100)
04-24 11:42:16.914: E/AndroidRuntime(18849):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2125)
04-24 11:42:16.914: E/AndroidRuntime(18849):    at android.app.ActivityThread.access$600(ActivityThread.java:140)
04-24 11:42:16.914: E/AndroidRuntime(18849):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1227)
04-24 11:42:16.914: E/AndroidRuntime(18849):    at android.os.Handler.dispatchMessage(Handler.java:99)
04-24 11:42:16.914: E/AndroidRuntime(18849):    at android.os.Looper.loop(Looper.java:137)
04-24 11:42:16.914: E/AndroidRuntime(18849):    at android.app.ActivityThread.main(ActivityThread.java:4898)
04-24 11:42:16.914: E/AndroidRuntime(18849):    at java.lang.reflect.Method.invokeNative(Native Method)
04-24 11:42:16.914: E/AndroidRuntime(18849):    at java.lang.reflect.Method.invoke(Method.java:511)
04-24 11:42:16.914: E/AndroidRuntime(18849):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1008)
04-24 11:42:16.914: E/AndroidRuntime(18849):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:775)
04-24 11:42:16.914: E/AndroidRuntime(18849):    at dalvik.system.NativeStart.main(Native Method)
04-24 11:42:16.914: E/AndroidRuntime(18849): Caused by: android.os.NetworkOnMainThreadException
04-24 11:42:16.914: E/AndroidRuntime(18849):    at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1118)
04-24 11:42:16.914: E/AndroidRuntime(18849):    at java.net.InetAddress.lookupHostByName(InetAddress.java:385)
04-24 11:42:16.914: E/AndroidRuntime(18849):    at java.net.InetAddress.getAllByNameImpl(InetAddress.java:236)
04-24 11:42:16.914: E/AndroidRuntime(18849):    at java.net.InetAddress.getAllByName(InetAddress.java:214)
04-24 11:42:16.914: E/AndroidRuntime(18849):    at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:137)
04-24 11:42:16.914: E/AndroidRuntime(18849):    at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164)
04-24 11:42:16.914: E/AndroidRuntime(18849):    at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119)
04-24 11:42:16.914: E/AndroidRuntime(18849):    at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:360)
04-24 11:42:16.914: E/AndroidRuntime(18849):    at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:670)
04-24 11:42:16.914: E/AndroidRuntime(18849):    at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:509)
04-24 11:42:16.914: E/AndroidRuntime(18849):    at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
04-24 11:42:16.914: E/AndroidRuntime(18849):    at police.uk.greatermanchesterpoliceandroid.XMLParser.getXmlFromUrl(XMLParser.java:45)
04-24 11:42:16.914: E/AndroidRuntime(18849):    at police.uk.greatermanchesterpoliceandroid.CustomizedListView.onCreate(CustomizedListView.java:47)
04-24 11:42:16.914: E/AndroidRuntime(18849):    at android.app.Activity.performCreate(Activity.java:5206)
04-24 11:42:16.914: E/AndroidRuntime(18849):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094)
04-24 11:42:16.914: E/AndroidRuntime(18849):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2064)
04-24 11:42:16.914: E/AndroidRuntime(18849):    ... 11 more

4 个答案:

答案 0 :(得分:1)

此错误指出您正在尝试在活动主线程上执行网络操作。不推荐使用,因为你只有5秒的时间来响应交互,你会得到ApplicationNotResponding异常。

请考虑将网络操作移至后台线程,例如通过服务或AsyncTask

答案 1 :(得分:0)

您正在使用

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

每项活动。除了应该在开始时首先调用的Activity之外,请删除此代码。

有关详细信息,请参阅here

<强>更新

您遇到了这个问题:

Caused by: android.os.NetworkOnMainThreadException
   at police.uk.greatermanchesterpoliceandroid.XMLParser.getXmlFromUrl(XMLParser.java:45)
   at police.uk.greatermanchesterpoliceandroid.CustomizedListView.onCreate(CustomizedListView.java:47)

请检查XMLParser或CustomizedListView上的代码,并将网络操作移到后台线程中。最好的方法是AsyncTask

答案 2 :(得分:0)

更改您的权限
<permission
android:name="com.example.mapdemo.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-permission android:name="com.example.mapdemo.permission.MAPS_RECEIVE"/>

<permission
    android:name="police.uk.greatermanchesterpoliceandroid.permission.MAPS_RECEIVE"
    android:protectionLevel="signature" />
<uses-permission android:name="police.uk.greatermanchesterpoliceandroid.permission.MAPS_RECEIVE"/>

我刚刚更改了包名

答案 3 :(得分:0)

你已经放了一个以上<intent-filter> </intent-filter>意味着它是你的应用程序的起点,它必须只包含一个活动,你已经把它放在每个活动中..这是一个错误。将<intent-filter> </intent-filter>放在您希望在Android中开始活动的位置。希望此帮助

让我让你的工作轻松,,,:)

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


<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/CustomTheme">
   <activity
        android:name=".MainActivity"
        android:label="@string/app_name" 
        android:screenOrientation="portrait">
    <intent-filter>
            <action android:name="android.intent.action.MAIN" />

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

    <activity android:name=".CustomizedListView" android:label="@string/app_name">

    </activity>

     <activity
        android:name=".DetailsActivity"
        android:label="@string/app_name" 
        android:screenOrientation="portrait">

        </activity>

      <activity
        android:name=".FileCache"
        android:label="@string/app_name" 
        android:screenOrientation="portrait">

        </activity>

       <activity
        android:name=".ImageLoader"
        android:label="@string/app_name" 
        android:screenOrientation="portrait">

        </activity>

        <activity
        android:name=".LazyAdapter"
        android:label="@string/app_name" 
        android:screenOrientation="portrait">

        </activity>

         <activity
        android:name=".MemoryCache"
        android:label="@string/app_name" 
        android:screenOrientation="portrait">

        </activity>

          <activity
        android:name=".Utils"
        android:label="@string/app_name" 
        android:screenOrientation="portrait">

        </activity>



            <activity
        android:name=".XMLParser"
        android:label="@string/app_name" 
        android:screenOrientation="portrait">

        </activity>

    <activity
        android:name=".ac2"
        android:label="@string/app_name" 
        android:screenOrientation="portrait">

        </activity>


  <meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaSyAioYkrj1Wl44z2LQvTCOw6GXPXdTroGng"/>      

</application>

 <permission
android:name="com.example.mapdemo.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-permission android:name="com.example.mapdemo.permission.MAPS_RECEIVE"/>

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />     
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

 <uses-feature
android:glEsVersion="0x00020000"
android:required="true"/>

<uses-sdk android:minSdkVersion="11" />