Go Back   Android Forums > Android Development > Application Development
Application Development Dev lounge for our application developers.

Get excited for the Samsung Galaxy S5! Find everything you need and discuss it in our Galaxy S5 Forum!

test: Reply
 
LinkBack Thread Tools
Old July 5th, 2013, 05:32 AM   #1 (permalink)
New Member
Thread Author (OP)
 
Join Date: Jul 2013
Posts: 5
 
Device(s):
Carrier: Not Provided

Thanks: 0
Thanked 0 Times in 0 Posts
Default The application has stopped responding

Hi Friends i am new to android application development. I have just download adt bundle and created an android project.

I want to do some thing on the page loading(means when my application opens it should read the wifi data and display the data in the page controls like TextEdit.

Where should i put the code so that it works like a pageload event.
Plz suggest
Thank u all in advance

chandradeor is offline  
Reply With Quote
sponsored links
Old July 5th, 2013, 09:56 AM   #2 (permalink)
AF Contributor
 
LilBit's Avatar
 
Join Date: Sep 2012
Location: U.S.A.
Gender: Female
Posts: 5,823
 
Device(s): ZTE Warp N860 Custom Rom
Carrier: Encrypted

Thanks: 8,975
Thanked 3,300 Times in 2,144 Posts
Default

Hello chandradeor, Welcome to the forums.
Have a look around this forum, should find
some answers in here.
Application Development - Android Forums
LilBit is offline  
Reply With Quote
Old July 9th, 2013, 05:12 AM   #3 (permalink)
New Member
Thread Author (OP)
 
Join Date: Jul 2013
Posts: 5
 
Device(s):
Carrier: Not Provided

Thanks: 0
Thanked 0 Times in 0 Posts
Default The application has stopped responding

Hi frnds i am new to android application development using java

I want to receive multicast data on a android application when it loads. I want that whenever the Activity loads it should start receiving multicast data and display in the textbox. But when i run this code on any emulator or Real Android device it show an error The app has stopped responding and also it does not receives any dataBelow
is the code



[HIGH]package com.example.cdttiming;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.InetAddress;
import java.net.MulticastSocket;
import java.net.UnknownHostException;

import android.app.Activity;
import android.content.Context;
import android.net.wifi.WifiManager;
import android.os.Bundle;
import android.view.Menu;
import android.widget.EditText;


public class MainActivity extends Activity
{

@Override

protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
EditText Seconds;
Seconds =(EditText)findViewById(R.id.Seconds);

WifiManager wm = (WifiManager)getSystemService(Context.WIFI_SERVICE );
WifiManager.MulticastLock multicastLock = wm.createMulticastLock("mydebuginfo");
multicastLock.setReferenceCounted(true);
multicastLock.acquire();

InetAddress ia = null;
byte[] buffer = new byte[65535];
MulticastSocket ms = null;
int port = 4321;
try
{
ia = InetAddress.getByName("226.1.1.1");
DatagramPacket dp = new DatagramPacket(buffer, buffer.length,ia,port);
ms = new MulticastSocket(port);
ms.setReuseAddress(true);
ms.joinGroup(ia);


// while (true)
for(int i=0;i<10;i++)
{
ms.receive(dp);
String s = new String(dp.getData(),0,dp.getLength());
Seconds.setText(s);
}



}
catch (UnknownHostException e)
{
Seconds.setText(e.getMessage());

}
catch (IOException e)
{
Seconds.setText(e.getMessage());
}



}
[/HIGH]

Logcat output


[HIGH]
07-09 14:26:53.116: E/AndroidRuntime(383): FATAL EXCEPTION: main
07-09 14:26:53.116: E/AndroidRuntime(383): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.cdttiming/com.example.cdttiming.MainActivity}: android.os.NetworkOnMainThreadException
07-09 14:26:53.116: E/AndroidRuntime(383): at android.app.ActivityThread.performLaunchActivity(A ctivityThread.java:1815)
07-09 14:26:53.116: E/AndroidRuntime(383): at android.app.ActivityThread.handleLaunchActivity(Ac tivityThread.java:1831)
07-09 14:26:53.116: E/AndroidRuntime(383): at android.app.ActivityThread.access$500(ActivityThre ad.java:122)
07-09 14:26:53.116: E/AndroidRuntime(383): at android.app.ActivityThread$H.handleMessage(Activit yThread.java:1024)
07-09 14:26:53.116: E/AndroidRuntime(383): at android.os.Handler.dispatchMessage(Handler.java:99 )
07-09 14:26:53.116: E/AndroidRuntime(383): at android.os.Looper.loop(Looper.java:132)
07-09 14:26:53.116: E/AndroidRuntime(383): at android.app.ActivityThread.main(ActivityThread.jav a:4123)
07-09 14:26:53.116: E/AndroidRuntime(383): at java.lang.reflect.Method.invokeNative(Native Method)
07-09 14:26:53.116: E/AndroidRuntime(383): at java.lang.reflect.Method.invoke(Method.java:491)
07-09 14:26:53.116: E/AndroidRuntime(383): at com.android.internal.os.ZygoteInit$MethodAndArgsCa ller.run(ZygoteInit.java:841)
07-09 14:26:53.116: E/AndroidRuntime(383): at com.android.internal.os.ZygoteInit.main(ZygoteInit .java:599)
07-09 14:26:53.116: E/AndroidRuntime(383): at dalvik.system.NativeStart.main(Native Method)
07-09 14:26:53.116: E/AndroidRuntime(383): Caused by: android.os.NetworkOnMainThreadException
07-09 14:26:53.116: E/AndroidRuntime(383): at android.os.StrictMode$AndroidBlockGuardPolicy.onNe twork(StrictMode.java:1077)
07-09 14:26:53.116: E/AndroidRuntime(383): at dalvik.system.BlockGuard$WrappedNetworkSystem.recv (BlockGuard.java:332)
07-09 14:26:53.116: E/AndroidRuntime(383): at org.apache.harmony.luni.net.PlainDatagramSocketImp l.doRecv(PlainDatagramSocketImpl.java:165)
07-09 14:26:53.116: E/AndroidRuntime(383): at org.apache.harmony.luni.net.PlainDatagramSocketImp l.receive(PlainDatagramSocketImpl.java:174)
07-09 14:26:53.116: E/AndroidRuntime(383): at java.net.DatagramSocket.receive(DatagramSocket.jav a:391)
07-09 14:26:53.116: E/AndroidRuntime(383): at com.example.cdttiming.MainActivity.onCreate(MainAc tivity.java:50)
07-09 14:26:53.116: E/AndroidRuntime(383): at android.app.Activity.performCreate(Activity.java:4 397)
07-09 14:26:53.116: E/AndroidRuntime(383): at android.app.Instrumentation.callActivityOnCreate(I nstrumentation.java:1048)
07-09 14:26:53.116: E/AndroidRuntime(383): at android.app.ActivityThread.performLaunchActivity(A ctivityThread.java:1779)
07-09 14:26:53.116: E/AndroidRuntime(383): ... 11 more

[/HIGH]

plz tell me what is the problem. Thank u all in advance
chandradeor is offline  
Reply With Quote
Reply


Go Back   Android Forums > Android Development > Application Development
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -5. The time now is 03:21 AM.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.