我有问题。我有这个清单:
<?xml version="1.0" encoding="utf-8"?>
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="Svět Androida"
android:theme="@style/MyMaterialTheme">
<uses-sdk
android:minSdkVersion="15"
android:targetSdkVersion="22"/>
<activity
android:name=".welcomescreen"
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=".MainActivity">
</activity>
<activity
android:name=".Cteni"
android:parentActivityName=".MainActivity" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".MainActivity" />
</activity>
</application>
和应用程序工作正常,但当我想生成apk。它说
uses-sdk必须是manifest的子项
所以我改为:
<?xml version="1.0" encoding="utf-8"?>
<uses-permission android:name="android.permission.INTERNET" />
<uses-sdk
android:minSdkVersion="15"
android:targetSdkVersion="22"/>
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="Svět Androida"
android:theme="@style/MyMaterialTheme">
<activity
android:name=".welcomescreen"
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=".MainActivity">
</activity>
<activity
android:name=".Cteni"
android:parentActivityName=".MainActivity" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".MainActivity" />
</activity>
</application>
我成功生成了apk但当我启动应用时它会停止,因为它无法连接到互联网。
编辑:
清单上的链接:
这是带错误的日志:
08-04 11:15:02.966 2888-2888/? E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: simaproject.com.svetandroida, PID: 2888
java.lang.RuntimeException: Unable to start activity ComponentInfo{simaproject.com.svetandroida/simaproject.com.svetandroida.MainActivity}: android.os.NetworkOnMainThreadException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2325)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
at android.app.ActivityThread.access$800(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
Caused by: android.os.NetworkOnMainThreadException
at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1147)
at java.net.InetAddress.lookupHostByName(InetAddress.java:418)
at java.net.InetAddress.getAllByNameImpl(InetAddress.java:252)
at java.net.InetAddress.getAllByName(InetAddress.java:215)
at com.android.okhttp.HostResolver$1.getAllByName(HostResolver.java:29)
at com.android.okhttp.internal.http.RouteSelector.resetNextInetSocketAddress(RouteSelector.java:232)
at com.android.okhttp.internal.http.RouteSelector.next(RouteSelector.java:124)
at com.android.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:272)
at com.android.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:211)
at com.android.okhttp.internal.http.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:382)
at com.android.okhttp.internal.http.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:332)
at com.android.okhttp.internal.http.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:199)
at java.net.URL.openStream(URL.java:470)
at simaproject.com.svetandroida.MainActivity.nactiData(MainActivity.java:78)
at simaproject.com.svetandroida.MainActivity.onCreate(MainActivity.java:57)
at android.app.Activity.performCreate(Activity.java:5990)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
at android.app.ActivityThread.access$800(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
请帮忙。感谢。
答案 0 :(得分:0)
错误信息很简单:
uses-sdk must be child of manifest
您的清单文件格式错误且缺少<manifest>
。请参阅文档:https://developer.android.com/guide/topics/manifest/manifest-intro.html
答案 1 :(得分:0)
如果您使用Android Studio删除此行
<uses-sdk
android:minSdkVersion="15"
android:targetSdkVersion="22"/>
因为它出现在build.gradle(Module:app)中的y Gradle Scripts中
答案 2 :(得分:0)
你的错误不是权限,你的错误就是这个&#34;引起:android.os.NetworkOnMainThreadException&#34;这意味着你尝试在主线程中做一些事情,如果你咨询一个web服务或者在asynktask中做了什么