problem in running the Emulator

General topics about the Android-Platform itself.
Coding issues please to the subforum right below.

problem in running the Emulator

Postby lakshmanraob » Mon Apr 06, 2009 7:18 pm

Hi all,
I am new to Android and also for Eclipse.I am having facing the following problem.When i run my application say Hello Android for the first time it will display correctly.
As i do not know how to stop the application i forcefully stopped the application by clicking the close button of the emulator. it given the warning like thing in the console.
when i run the same application in the console there is no warnings or errors but the emulator is unable to launch


lakshman
lakshmanraob
Junior Developer
Junior Developer
 
Posts: 18
Joined: Mon Mar 23, 2009 8:11 pm

Top

Postby WarrenFaith » Tue Apr 07, 2009 7:47 am

Hello and welcome!

First you should understand the Activity-Life-Cycle.
To "stop" your Hello Android, you simply could push the home button of the emulator which send your Hello Android to background (more information in the Activity-Life-Cycle).

it given the warning like thing in the console.
when i run the same application in the console there is no warnings or errors but the emulator is unable to launch

What are the warnings?
How do you start your application in the console?
WarrenFaith
Moderator
Moderator
 
Posts: 227
Joined: Fri Mar 13, 2009 10:59 am
Location: Berlin, Germany

Postby lakshmanraob » Tue Apr 07, 2009 10:29 am

hi,
Thanks for the quick reply. As a bad practice i just stopped the application by clicking on the 'X' Button. Because of that it is unable to launch the application for the second time.
It is giving the alert on the emulator that sorry "hello world" application could not run. and it had the button to stop the application force fully.

IN the console following error i am getting

[2009-04-07 13:02:16 - DeviceMonitor]Error reading jdwp list: EOF
[2009-04-07 13:02:16 - DeviceMonitor]Connection Failure when starting to monitor device 'emulator-5554' : device (emulator-5554) request rejected: device offline


and in the emulator the application is not running

lakshman
lakshmanraob
Junior Developer
Junior Developer
 
Posts: 18
Joined: Mon Mar 23, 2009 8:11 pm

Postby WarrenFaith » Tue Apr 07, 2009 10:47 am

lakshmanraob wrote:hi,
Thanks for the quick reply. As a bad practice i just stopped the application by clicking on the 'X' Button. Because of that it is unable to launch the application for the second time.
It is giving the alert on the emulator that sorry "hello world" application could not run. and it had the button to stop the application force fully.

hm... if you deploy and start your emulator with eclipse, it should automatically reinstall the app and start it. so it should always be like "the first start". Try to deinstall the application over the application list in the settings of the emulator.

lakshmanraob wrote:IN the console following error i am getting

[2009-04-07 13:02:16 - DeviceMonitor]Error reading jdwp list: EOF
[2009-04-07 13:02:16 - DeviceMonitor]Connection Failure when starting to monitor device 'emulator-5554' : device (emulator-5554) request rejected: device offline
Well thats correct, if the emulator is not open, the installation of your application cant work.

If nothing help, start your emulator once with "-wipe-data" as parameter to reset everything.
WarrenFaith
Moderator
Moderator
 
Posts: 227
Joined: Fri Mar 13, 2009 10:59 am
Location: Berlin, Germany

Postby lakshmanraob » Tue Apr 07, 2009 11:16 am

hi

IN DDMS it is showing in the following way
IN the console following error i am getting

[2009-04-07 13:02:16 - DeviceMonitor]Error reading jdwp list: EOF
[2009-04-07 13:02:16 - DeviceMonitor]Connection Failure when starting to monitor device 'emulator-5554' : device (emulator-5554) request rejected: device offline


This is coming only when i close the emulator forcefully by clicking on the close button.

The console it is giving the information in the following way

<b>
[2009-04-07 15:32:04 - HelloAndroid] ------------------------------
[2009-04-07 15:32:04 - HelloAndroid] Android Launch!
[2009-04-07 15:32:04 - HelloAndroid] adb is running normally.
[2009-04-07 15:32:04 - HelloAndroid] Launching: com.test.lucky.HelloAndroid
[2009-04-07 15:32:04 - HelloAndroid] Automatic Target Mode: launching new emulator.
[2009-04-07 15:32:04 - HelloAndroid] Launching a new emulator.
[2009-04-07 15:32:06 - HelloAndroid] New emulator found: emulator-5554
[2009-04-07 15:32:06 - HelloAndroid] Waiting for HOME ('android.process.acore') to be launched...
[2009-04-07 15:33:40 - HelloAndroid] HOME is up on device 'emulator-5554'
[2009-04-07 15:33:40 - HelloAndroid] Uploading HelloAndroid.apk onto device 'emulator-5554'
[2009-04-07 15:33:40 - HelloAndroid] Installing HelloAndroid.apk...
[2009-04-07 15:33:46 - HelloAndroid] Success!
[2009-04-07 15:33:46 - HelloAndroid] Starting activity com.test.lucky.HelloAndroid on device
[2009-04-07 15:33:51 - HelloAndroid] ActivityManager: Starting: Intent { comp={com.test.lucky/com.test.lucky.HelloAndroid} }
[2009-04-07 15:34:26 - Emulator] emulator: emulator window was out of view and was recentred
[2009-04-07 15:34:26 - Emulator] </b>


can u just tell me what might be the problem...?

lakshman
lakshmanraob
Junior Developer
Junior Developer
 
Posts: 18
Joined: Mon Mar 23, 2009 8:11 pm

Postby WarrenFaith » Tue Apr 07, 2009 12:02 pm

there shouldnt be a problem.
of course you get an error if you forcefully close the emulator.

Do I understand you right, that you are not able to restart the emulator and start your HelloAndroid application?
Than please tell me exactly, how you try to start the application (using eclipse?)
WarrenFaith
Moderator
Moderator
 
Posts: 227
Joined: Fri Mar 13, 2009 10:59 am
Location: Berlin, Germany

Top

Postby lakshmanraob » Tue Apr 07, 2009 12:06 pm

I am starting the emulator by

clicking on the run -> runConfiguration -> by selecting the launch default Activity and then by clicking run.

can u please tell me the way to stop the emulator, i am just stopping the emulator by clicking close button (which is a bad practice but i do not know the other option)

lakshman
lakshmanraob
Junior Developer
Junior Developer
 
Posts: 18
Joined: Mon Mar 23, 2009 8:11 pm

Postby WarrenFaith » Tue Apr 07, 2009 12:22 pm

Is there another way? Not that I know.... and I don't think that it is bad practice...

What exactly is your problem with HelloAndroid?
WarrenFaith
Moderator
Moderator
 
Posts: 227
Joined: Fri Mar 13, 2009 10:59 am
Location: Berlin, Germany

Postby lakshmanraob » Tue Apr 07, 2009 12:40 pm

when i launch the application it is giving the following error in the emulator. i have taken the screen shot and attached that to this message please see the attachment..



lakshman
Attachments
sample.PNG
for better understanding i am giving this image file
sample.PNG (131.42 KiB) Viewed 5686 times
lakshmanraob
Junior Developer
Junior Developer
 
Posts: 18
Joined: Mon Mar 23, 2009 8:11 pm

Postby WarrenFaith » Tue Apr 07, 2009 2:09 pm

Ok, what does LogCat say?
Window -> Show View -> Other -> Android -> LogCat
WarrenFaith
Moderator
Moderator
 
Posts: 227
Joined: Fri Mar 13, 2009 10:59 am
Location: Berlin, Germany

Postby lakshmanraob » Tue Apr 07, 2009 2:41 pm

Hi,
Thank you very much for giving me the valuable guidance. The problem is with the code i written in the HelloWorld application

The following code is giving the problem

TextView myTextView = (TextView)findViewById(R.id.myTextView);

I tried to access the myTextView which is present in the main.xml in the following way

<TextView
android:id = "@+id/myTextView"
android:layout_width = "fill_parent"
android:layout_height = "wrap_content"
android:text = "from xml file hello world"
/>


but that is coming as Null because of that it is giving the error.
Any way thank you very much for your valuable guidance. can you just tell me how to access the content from the main.xml

Thank you once again
lakshman
lakshmanraob
Junior Developer
Junior Developer
 
Posts: 18
Joined: Mon Mar 23, 2009 8:11 pm

Postby WarrenFaith » Tue Apr 07, 2009 3:05 pm

have you called the method setContentView(R.layout.main) ?
This method says your activity, which xml it should use....

If yes, can you post your full activity class please?
WarrenFaith
Moderator
Moderator
 
Posts: 227
Joined: Fri Mar 13, 2009 10:59 am
Location: Berlin, Germany

Postby lakshmanraob » Tue Apr 07, 2009 3:14 pm

The activity class is as follows


public class HelloAndroid extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//setContentView(R.layout.main);

try{
TextView myTextView = (TextView)findViewById(R.id.myTextView);
if(myTextView!=null)
setContentView(R.id.myTextView);
else{
myTextView = new TextView(this);
myTextView.setText("lakshman");
setContentView(myTextView);
}
//setContentView(R.layout.main);
}catch(Exception e){
System.out.println("start.."+e);
}
}
}


The R.id.myTextView i want to access but it is not displaying that thing
lakshmanraob
Junior Developer
Junior Developer
 
Posts: 18
Joined: Mon Mar 23, 2009 8:11 pm

Postby WarrenFaith » Tue Apr 07, 2009 3:32 pm

Ah ok, you have a misunderstanding :)

setContentView needs a layout. If your layout file is main.xml, than you have call it once like setContentView(R.layout.main). Just remove the // before the line.

When you have called this method, the activity knows which elements are available and now findViewById() will return the correct element you defined in your main.xml with this id...

Second, don't recall this method. And never with a parameter like R.id.whatever

Try this:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. public class HelloAndroid extends Activity {
  2.  
  3.   /** Called when the activity is first created. */
  4.  
  5.   @Override
  6.  
  7.   public void onCreate(Bundle savedInstanceState) {
  8.  
  9.     super.onCreate(savedInstanceState);
  10.  
  11.     setContentView(R.layout.main);
  12.  
  13.  
  14.  
  15.     TextView myTextView = (TextView)findViewById(R.id.myTextView);
  16.  
  17.     myTextView.setText("lakshman");
  18.  
  19.   }
  20.  
  21. }
Parsed in 0.032 seconds, using GeSHi 1.0.8.4
WarrenFaith
Moderator
Moderator
 
Posts: 227
Joined: Fri Mar 13, 2009 10:59 am
Location: Berlin, Germany

Postby lakshmanraob » Tue Apr 07, 2009 5:39 pm

so how i can access the element in main.xml.

The main.xml file is like this way


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
/>
<TextView
android:id = "@+id/myTextView"
android:layout_width = "fill_parent"
android:layout_height = "wrap_content"
android:text = "from xml file hello world"
/>
</LinearLayout>

i just wanted to acces the second textView tag in my program. how can i do that?


lakshmanraob
Junior Developer
Junior Developer
 
Posts: 18
Joined: Mon Mar 23, 2009 8:11 pm

Top
Next

Return to General

Who is online

Users browsing this forum: No registered users and 6 guests