1

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

我感觉我的清单有问题,但我不能完全确定。这是我的清单:-

 <?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

4 回答 4

1

此错误指出您正在尝试在活动主线程上进行网络操作。不建议这样做,因为在您收到 ApplicationNotResponding 异常之前,您只有 5 秒的时间来响应交互。

请考虑将网络操作移动到后台线程,例如,通过 service 或AsyncTask

于 2013-04-24T10:29:00.183 回答
0

您正在使用

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

对于每一项活动。请删除此代码,但应在启动时首先调用的 Activity 除外。

欲了解更多信息,请阅读此处

更新:

你有这个问题:

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

于 2013-04-24T10:03:06.733 回答
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"/>

我刚改了包名

于 2013-04-24T10:03:29.250 回答
0

您放置的不止一个 <intent-filter> </intent-filter> 意味着它是您应用程序的起点,并且它必须只包含一个 Activity,并且您已将其放入每个 Activity 中。这是一个错误。<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" />
于 2013-04-24T10:05:36.693 回答