Hallo Leute,
ich habe mit der Programmierung von AndroidApps erst am Wochenende angefangen, daher verzeiht mir bitte, falls ich nicht gleich alle Informationen bereitstellen kann.
Und zwar hab ich das Problem, dass bei Android 4.0.3 das App absürtzt sobald es das Recht zum Verbinden mit dem Internet braucht.
Ich hab mir sogar ein Example runtergeladen um wirklich sicher zusein, dass es am Internet permission liegt.
Der Examplecode:
Java
package sarl.test.wi;
import java.io.IOException;
import java.net.InetAddress;
import java.net.UnknownHostException;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
public class testActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TextView info = (TextView)findViewById(R.id.info_text);
InetAddress in;
in=null;
//Definimos la ip de la cual haremos el ping
try {
in = InetAddress.getByName("google.at");
} catch (UnknownHostException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//Definimos un tiempo en el cual ha de responder
try {
if(in.isReachable(5000)){
info.setText("Responde OK");}
else{
info.setText("No responde: Time out");
}
} catch (IOException e) {
// TODO Auto-generated catch block
info.setText(e.toString());
}
}
}
Alles anzeigen
Was kommt? -
LogCat:
Code
03-19 22:28:45.950: D/AndroidRuntime(556): Shutting down VM
03-19 22:28:45.962: W/dalvikvm(556): threadid=1: thread exiting with uncaught exception (group=0x409c01f8)
03-19 22:28:45.970: E/AndroidRuntime(556): FATAL EXCEPTION: main
03-19 22:28:45.970: E/AndroidRuntime(556): java.lang.RuntimeException: Unable to start activity ComponentInfo{sarl.test.wi/sarl.test.wi.testActivity}: android.os.NetworkOnMainThreadException
03-19 22:28:45.970: E/AndroidRuntime(556): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956)
03-19 22:28:45.970: E/AndroidRuntime(556): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
03-19 22:28:45.970: E/AndroidRuntime(556): at android.app.ActivityThread.access$600(ActivityThread.java:123)
03-19 22:28:45.970: E/AndroidRuntime(556): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
03-19 22:28:45.970: E/AndroidRuntime(556): at android.os.Handler.dispatchMessage(Handler.java:99)
03-19 22:28:45.970: E/AndroidRuntime(556): at android.os.Looper.loop(Looper.java:137)
03-19 22:28:45.970: E/AndroidRuntime(556): at android.app.ActivityThread.main(ActivityThread.java:4424)
03-19 22:28:45.970: E/AndroidRuntime(556): at java.lang.reflect.Method.invokeNative(Native Method)
03-19 22:28:45.970: E/AndroidRuntime(556): at java.lang.reflect.Method.invoke(Method.java:511)
03-19 22:28:45.970: E/AndroidRuntime(556): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
03-19 22:28:45.970: E/AndroidRuntime(556): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
03-19 22:28:45.970: E/AndroidRuntime(556): at dalvik.system.NativeStart.main(Native Method)
03-19 22:28:45.970: E/AndroidRuntime(556): Caused by: android.os.NetworkOnMainThreadException
03-19 22:28:45.970: E/AndroidRuntime(556): at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1099)
03-19 22:28:45.970: E/AndroidRuntime(556): at java.net.InetAddress.lookupHostByName(InetAddress.java:391)
03-19 22:28:45.970: E/AndroidRuntime(556): at java.net.InetAddress.getAllByNameImpl(InetAddress.java:242)
03-19 22:28:45.970: E/AndroidRuntime(556): at java.net.InetAddress.getByName(InetAddress.java:295)
03-19 22:28:45.970: E/AndroidRuntime(556): at sarl.test.wi.testActivity.onCreate(testActivity.java:22)
03-19 22:28:45.970: E/AndroidRuntime(556): at android.app.Activity.performCreate(Activity.java:4465)
03-19 22:28:45.970: E/AndroidRuntime(556): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
03-19 22:28:45.970: E/AndroidRuntime(556): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
03-19 22:28:45.970: E/AndroidRuntime(556): ... 11 more
Alles anzeigen
AndroidMainfest.xml
Code
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="sarl.test.wi"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="15" />
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity
android:name=".testActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Alles anzeigen
Fehlerbeschreibung: Das App stürzt bei "in = InetAddress.getByName("google.at");" ab,