Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » General (non-technical) » Polish users » Problem z przejściem z android 2.2 na 4.1(Aplikacja nie działa na nowszych androidach)
Problem z przejściem z android 2.2 na 4.1 [message #1229599] Thu, 09 January 2014 19:54 Go to next message
Pawel N is currently offline Pawel N
Messages: 3
Registered: January 2014
Junior Member
Witam.

Jestem początkujący w pisaniu w java i na android ale napisałem aplikacje która obsługuje zewnętrzną bazę danych przez internet oraz umożliwia sterowanie głosowe.
Napisałem aplikację pod androida 2.2 i wszystko fajnie działa. Niestety teraz próbuje odpalić to na androidach 4. i pojawiają się same błędy. Czy są jakieś istotne różnice w programowaniu na te systemy?

Otrzymuje takie logi:
01-09 20:52:21.106: E/Trace(6856): error opening trace file: No such file or directory (2)
01-09 20:52:21.716: D/dalvikvm(6856): GC_CONCURRENT freed 2881K, 43% free 4457K/7692K, paused 16ms+1ms, total 54ms
01-09 20:52:21.757: D/dalvikvm(6856): GC_FOR_ALLOC freed 647K, 49% free 3972K/7692K, paused 31ms, total 31ms
01-09 20:52:21.757: I/dalvikvm-heap(6856): Grow heap (frag case) to 5.240MB for 656116-byte allocation
01-09 20:52:21.787: D/dalvikvm(6856): GC_CONCURRENT freed <1K, 41% free 4612K/7692K, paused 3ms+1ms, total 31ms
01-09 20:52:21.827: D/dalvikvm(6856): GC_FOR_ALLOC freed 641K, 47% free 4134K/7692K, paused 16ms, total 20ms
01-09 20:52:21.837: I/dalvikvm-heap(6856): Grow heap (frag case) to 5.398MB for 656116-byte allocation
01-09 20:52:21.867: D/dalvikvm(6856): GC_CONCURRENT freed <1K, 36% free 4935K/7692K, paused 5ms+2ms, total 33ms
01-09 20:52:21.927: D/dalvikvm(6856): GC_CONCURRENT freed 641K, 34% free 5101K/7692K, paused 9ms+2ms, total 28ms
01-09 20:52:21.927: D/dalvikvm(6856): WAIT_FOR_CONCURRENT_GC blocked 13ms
01-09 20:52:21.967: D/dalvikvm(6856): GC_CONCURRENT freed 641K, 32% free 5265K/7692K, paused 5ms+1ms, total 18ms
01-09 20:52:21.967: D/dalvikvm(6856): WAIT_FOR_CONCURRENT_GC blocked 9ms
01-09 20:52:21.997: D/dalvikvm(6856): GC_FOR_ALLOC freed 1282K, 38% free 4787K/7692K, paused 11ms, total 14ms
01-09 20:52:22.047: D/dalvikvm(6856): GC_CONCURRENT freed <1K, 28% free 5590K/7692K, paused 8ms+5ms, total 27ms
01-09 20:52:22.047: D/dalvikvm(6856): WAIT_FOR_CONCURRENT_GC blocked 14ms
01-09 20:52:22.097: D/dalvikvm(6856): GC_FOR_ALLOC freed 1281K, 34% free 5111K/7692K, paused 20ms, total 35ms
01-09 20:52:22.187: D/dalvikvm(6856): GC_CONCURRENT freed <1K, 24% free 5916K/7692K, paused 8ms+1ms, total 43ms
01-09 20:52:22.187: D/dalvikvm(6856): WAIT_FOR_CONCURRENT_GC blocked 35ms
01-09 20:52:22.297: D/dalvikvm(6856): GC_CONCURRENT freed 1405K, 27% free 5675K/7692K, paused 8ms+25ms, total 67ms
01-09 20:52:22.367: D/AndroidRuntime(6856): Shutting down VM
01-09 20:52:22.367: W/dalvikvm(6856): threadid=1: thread exiting with uncaught exception (group=0x40aff930)
01-09 20:52:22.367: E/AndroidRuntime(6856): FATAL EXCEPTION: main
01-09 20:52:22.367: E/AndroidRuntime(6856): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.edom/com.edom.MainActivity}: android.os.NetworkOnMainThreadException
01-09 20:52:22.367: E/AndroidRuntime(6856): 	at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2307)
01-09 20:52:22.367: E/AndroidRuntime(6856): 	at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2357)
01-09 20:52:22.367: E/AndroidRuntime(6856): 	at android.app.ActivityThread.access$600(ActivityThread.java:153)
01-09 20:52:22.367: E/AndroidRuntime(6856): 	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1247)
01-09 20:52:22.367: E/AndroidRuntime(6856): 	at android.os.Handler.dispatchMessage(Handler.java:99)
01-09 20:52:22.367: E/AndroidRuntime(6856): 	at android.os.Looper.loop(Looper.java:137)
01-09 20:52:22.367: E/AndroidRuntime(6856): 	at android.app.ActivityThread.main(ActivityThread.java:5226)
01-09 20:52:22.367: E/AndroidRuntime(6856): 	at java.lang.reflect.Method.invokeNative(Native Method)
01-09 20:52:22.367: E/AndroidRuntime(6856): 	at java.lang.reflect.Method.invoke(Method.java:511)
01-09 20:52:22.367: E/AndroidRuntime(6856): 	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:795)
01-09 20:52:22.367: E/AndroidRuntime(6856): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:562)
01-09 20:52:22.367: E/AndroidRuntime(6856): 	at dalvik.system.NativeStart.main(Native Method)
01-09 20:52:22.367: E/AndroidRuntime(6856): Caused by: android.os.NetworkOnMainThreadException
01-09 20:52:22.367: E/AndroidRuntime(6856): 	at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1117)
01-09 20:52:22.367: E/AndroidRuntime(6856): 	at java.net.InetAddress.lookupHostByName(InetAddress.java:385)
01-09 20:52:22.367: E/AndroidRuntime(6856): 	at java.net.InetAddress.getAllByNameImpl(InetAddress.java:236)
01-09 20:52:22.367: E/AndroidRuntime(6856): 	at java.net.InetAddress.getAllByName(InetAddress.java:214)
01-09 20:52:22.367: E/AndroidRuntime(6856): 	at libcore.net.http.HttpConnection.<init>(HttpConnection.java:70)
01-09 20:52:22.367: E/AndroidRuntime(6856): 	at libcore.net.http.HttpConnection.<init>(HttpConnection.java:50)
01-09 20:52:22.367: E/AndroidRuntime(6856): 	at libcore.net.http.HttpConnection$Address.connect(HttpConnection.java:340)
01-09 20:52:22.367: E/AndroidRuntime(6856): 	at libcore.net.http.HttpConnectionPool.get(HttpConnectionPool.java:87)
01-09 20:52:22.367: E/AndroidRuntime(6856): 	at libcore.net.http.HttpConnection.connect(HttpConnection.java:128)
01-09 20:52:22.367: E/AndroidRuntime(6856): 	at libcore.net.http.HttpEngine.openSocketConnection(HttpEngine.java:316)
01-09 20:52:22.367: E/AndroidRuntime(6856): 	at libcore.net.http.HttpEngine.connect(HttpEngine.java:311)
01-09 20:52:22.367: E/AndroidRuntime(6856): 	at libcore.net.http.HttpEngine.sendSocketRequest(HttpEngine.java:290)
01-09 20:52:22.367: E/AndroidRuntime(6856): 	at libcore.net.http.HttpEngine.sendRequest(HttpEngine.java:240)
01-09 20:52:22.367: E/AndroidRuntime(6856): 	at libcore.net.http.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:282)
01-09 20:52:22.367: E/AndroidRuntime(6856): 	at libcore.net.http.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:177)
01-09 20:52:22.367: E/AndroidRuntime(6856): 	at com.edom.MainActivity.urlGet(MainActivity.java:366)
01-09 20:52:22.367: E/AndroidRuntime(6856): 	at com.edom.MainActivity.onCreate(MainActivity.java:118)
01-09 20:52:22.367: E/AndroidRuntime(6856): 	at android.app.Activity.performCreate(Activity.java:5104)
01-09 20:52:22.367: E/AndroidRuntime(6856): 	at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
01-09 20:52:22.367: E/AndroidRuntime(6856): 	at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2261)
01-09 20:52:22.367: E/AndroidRuntime(6856): 	... 11 more
Re: Problem z przejściem z android 2.2 na 4.1 [message #1229759 is a reply to message #1229599] Fri, 10 January 2014 06:50 Go to previous messageGo to next message
Pawel N is currently offline Pawel N
Messages: 3
Registered: January 2014
Junior Member
Po eliminacjach kolejnych fragmentów kodu doszedłem że problem leży w tym fragmencie

   CharSequence uri = "strona_www/_db3131385.csv"; 
   String st=urlGet(String.valueOf(uri));


Czy android 4.2 potrzebuje jakiś innych uprawnień dla dostępu do internetu czy błąd jest po prostu w kodzie?

Re: Problem z przejściem z android 2.2 na 4.1 [message #1230004 is a reply to message #1229759] Fri, 10 January 2014 19:37 Go to previous messageGo to next message
Pawel N is currently offline Pawel N
Messages: 3
Registered: January 2014
Junior Member
Jakiś problem jest z tym kodem. Moglibyście zerknąć?
Wywala się na: InputStream inputStream = urlConnection.getInputStream();

	public String urlGet(String urlString){
	      
	     URLConnection urlConnection = null;
	        URL url = null;
	        String string = null;
	         
	        try {
	   url = new URL(urlString);
	   urlConnection = url.openConnection();
	    
	   InputStream inputStream = urlConnection.getInputStream();
	   InputStreamReader inputStreamReader = new InputStreamReader(inputStream);
	   BufferedReader reader = new BufferedReader(inputStreamReader);
	    
	       
	   StringBuffer stringBuffer = new StringBuffer();
	    
	   while((string = reader.readLine()) != null){
	    stringBuffer.append(string + "\n");
	   }
	   inputStream.close(); 
	    
	   string = stringBuffer.toString();
	    
	   reader=null;
	   stringBuffer=null;
	    
	  } catch (MalformedURLException e) {
	   e.printStackTrace();
	  } catch (IOException e) {
	   e.printStackTrace();
	  }  
	   
	        
	        
	    
	  return string;
	    }
	
	private CharSequence Parse(String myString){      
	 CharSequence title = myString.subSequence(myString.indexOf("<title>")+7,myString.indexOf("</title>"));
	 return title;
	} 


Re: Problem z przejściem z android 2.2 na 4.1 [message #1232289 is a reply to message #1230004] Thu, 16 January 2014 16:05 Go to previous messageGo to next message
Tomasz Zarna is currently offline Tomasz Zarna
Messages: 165
Registered: July 2009
Senior Member
Kod jak kod, wygląda ok. Co to znaczy "wywala się"?
Re: Problem z przejściem z android 2.2 na 4.1 [message #1388370 is a reply to message #1232289] Thu, 26 June 2014 10:40 Go to previous message
Miłosz Lorenc is currently offline Miłosz Lorenc
Messages: 1
Registered: June 2014
Junior Member
Temat stary, ale może się komuś przyda - należy zwracać uwagę na wyjątki, które ewidnentie się pojawiają.

Quote:
FATAL EXCEPTION: main
01-09 20:52:22.367: E/AndroidRuntime(6856): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.edom/com.edom.MainActivity}: android.os.NetworkOnMainThreadException


Z wyższą wersją androida nie można wykonywać operacji sieciowych w wątku UI, tzn., że do obsługi sieci należy wykorzystać osobny wątek, w postaci new Thread, lub AsyncTask.
Previous Topic:Problem z programem
Next Topic:Problem
Goto Forum:
  


Current Time: Thu Oct 30 18:34:32 GMT 2014

Powered by FUDForum. Page generated in 0.01890 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software