• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Help required: Hello World App

umairrahim

Lurker
Jul 5, 2010
3
0
hi everybody,

sory for asking a silly question but i am just new in this Android stuff, i am trying to run a HelloWold App, the source code is:

package com.example;

import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;

public class HelloStudents extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
TextView tv = new TextView(this);
tv.setText("Hello, Android");
setContentView(tv);
}
}



But when i try to run this , i get this error:

123eju.jpg


I dont know the reason, may be something is wrong in this configuration at the initial settings of project:

1234cb.jpg


I suspect that i am doing something wrong in the field, package name, but i really dont know exactly what to write here, and what should be the value of SDK version field? For the time being i am leaving this field empty.

Waiting for positive suggestions, thanx in advance.
 
I think it would be beneficial if you posted a LogCat dump on here as that helps me pinpoint where my code is failing when running applications.

To open the LogCat window (I'm assuming you use Eclipse) go to...

Window -> Show View -> Other... -> Android -> LogCat

You should now have a small Window below your programming environment (e.g. the place where you right your code) next to other tabbed windows such as Console, etc.

At this point, try running your application and recreating the force closure issue. As you run your program, you should see the LogCat window populate itself with random debug messages. When your force close message hits, you should see a block or two of red text saying the error that was created (i.e. uncaught handler, exception signaling, etc.) and which line of code triggered it. If you skim through the lines that specify which line of java code caused the problem, you should look for the file that you created and which line of code in your code that is causing the problem.

If after this you can't find out the issue, feel free to ping me a PM and post your LogCat dump here and we'll see if we can analyze this issue for ya^^

By the way... quick question before I go... have you created the UI in a separate XML file? If so, mind posting your XML code as well?

- Daniel
 
Upvote 0
Here is my log file:


07-05 20:20:19.441: DEBUG/dalvikvm(661): GC freed 2856 objects / 175752 bytes in 128ms

07-05 20:20:24.432: DEBUG/dalvikvm(612): GC freed 2798 objects / 169520 bytes in 106ms

07-05 20:24:54.674: INFO/Process(715): Sending signal. PID: 715 SIG: 9

07-05 20:24:54.682: INFO/ActivityManager(563): Process com.example (pid 715) has died.

07-05 20:24:54.832: WARN/InputManagerService(563): Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@43684d98

07-05 20:36:01.033: DEBUG/dalvikvm(610): GC freed 9813 objects / 554520 bytes in 138ms

07-05 20:50:00.193: DEBUG/dalvikvm(563): GC freed 14953 objects / 707520 bytes in 197ms

07-05 20:51:32.112: DEBUG/dalvikvm(610): GC freed 9645 objects / 541248 bytes in 123ms
07-05 21:07:02.923: DEBUG/dalvikvm(610): GC freed 9289 objects / 524224 bytes in 105ms

07-05 21:09:02.042: DEBUG/jdwp(563): +++ peer disconnected
07-05
21:09:02.042: INFO/dalvikvm(563): Debugger has detached; object registry had 1 entries

07-05 21:09:02.042: DEBUG/jdwp(610): +++ peer disconnected

07-05 21:09:02.042: INFO/dalvikvm(610): Debugger has detached; object registry had 1 entries

07-05 21:09:02.042: DEBUG/jdwp(612): +++ peer disconnected

07-05 21:09:02.042: INFO/dalvikvm(612): Debugger has detached; object registry had 1 entries

07-05 21:09:02.042: DEBUG/jdwp(642): +++ peer disconnected

07-05 21:09:02.052: INFO/dalvikvm(642): Debugger has detached; object registry had 1 entries

07-05 21:09:02.052: DEBUG/jdwp(661): +++ peer disconnected

07-05 21:09:02.052: INFO/dalvikvm(661): Debugger has detached; object registry had 1 entries

07-05 21:09:02.052: DEBUG/jdwp(669): +++ peer disconnected

07-05 21:09:02.052: INFO/dalvikvm(669): Debugger has detached; object registry had 1 entries

07-05 21:09:02.071: DEBUG/jdwp(705): +++ peer disconnected
07-05
21:09:02.071: INFO/dalvikvm(705): Debugger has detached; object registry had 1 entries

07-05 21:09:35.402: INFO/jdwp(563): received file descriptor 30 from ADB

07-05 21:09:35.421: INFO/jdwp(610): received file descriptor 10 from ADB

07-05 21:09:35.433: WARN/System.err(563): Can't dispatch DDM chunk 46454154: no handler defined
07-05 21:09:35.433: WARN/System.err(563): Can't dispatch DDM chunk 4d505251: no handler defined

07-05 21:09:35.452: INFO/jdwp(612): received file descriptor 10 from ADB

07-05 21:09:35.484: INFO/jdwp(642): received file descriptor 20 from ADB

07-05 21:09:35.484: WARN/System.err(610): Can't dispatch DDM chunk 46454154: no handler defined

07-05 21:09:35.484: WARN/System.err(610): Can't dispatch DDM chunk 4d505251: no handler defined

07-05 21:09:35.493: WARN/System.err(612): Can't dispatch DDM chunk 46454154: no handler defined

07-05 21:09:35.493: WARN/System.err(612): Can't dispatch DDM chunk 4d505251: no handler defined

07-05 21:09:35.523: INFO/jdwp(661): received file descriptor 31 from ADB

07-05 21:09:35.523: WARN/System.err(642): Can't dispatch DDM chunk 46454154: no handler defined

07-05 21:09:35.523: WARN/System.err(642): Can't dispatch DDM chunk 4d505251: no handler defined

07-05 21:09:35.543: INFO/jdwp(669): received file descriptor 25 from ADB

07-05 21:09:35.543: WARN/System.err(661): Can't dispatch DDM chunk 46454154: no handler defined

07-05 21:09:35.543: WARN/System.err(661): Can't dispatch DDM chunk 4d505251: no handler defined

07-05 21:09:35.552: INFO/jdwp(705): received file descriptor 22 from ADB

07-05 21:09:35.562: WARN/System.err(669): Can't dispatch DDM chunk 46454154: no handler defined

07-05 21:09:35.562: WARN/System.err(669): Can't dispatch DDM chunk 4d505251: no handler defined

07-05 21:09:35.572: WARN/System.err(705): Can't dispatch DDM chunk 46454154: no handler defined

07-05 21:09:35.572: WARN/System.err(705): Can't dispatch DDM chunk 4d505251: no handler defined

07-05 21:07:02.923: DEBUG/dalvikvm(610): GC freed 9289 objects / 524224 bytes in 105ms

07-05 21:09:02.042: DEBUG/jdwp(563): +++ peer disconnected

07-05 21:09:02.042: INFO/dalvikvm(563): Debugger has detached; object registry had 1 entries

07-05 21:09:02.042: DEBUG/jdwp(610): +++ peer disconnected

07-05 21:09:02.042: INFO/dalvikvm(610): Debugger has detached; object registry had 1 entries

07-05 21:09:02.042: DEBUG/jdwp(612): +++ peer disconnected

07-05 21:09:02.042: INFO/dalvikvm(612): Debugger has detached; object registry had 1 entries



I am really sorry, but i am unable to figure out what is the problem, but i am sure, i am wrong with project settings at some step. Can you tell me what could be the possible problem?

No i dint create XML file for UI. Is it necessary for just runing a Hello world App?

By the way, thanx a lot for your such a quick response :)
 
Upvote 0
Hmmm... not sure if this will solve your problem but... try adding the following code before your TextView tv line:
super.onCreate(savedInstanceState);

Also, was the LogCat dump that you highlighted red?.. To be honest, that wasn't the block of code I was referring to (could be my fault for not explaining properly). Normally this part tells you the errors in a program:

http://www.warriorpoint.com/blog/wp-content/uploads/2009/05/02screen.png

Note the things in the red box. Of course, in Eclipse it's not a command prompt screen (I just mean the text)...

In any case, try adding that line as the first line of code within your onCreate function. :]
 
Upvote 0
Sorry for the late response. I was out the entire day... but I'm glad you were able to figure out what the issue was >.<

I'm not a Java expert but I think the instruction is needed to override the onCreate method in the Activity class (hence the "extends Activity" and "@Override" clauses). This means that when your application runs, it runs the onCreate method that you implement and not the template one that is provided in the Activity implementation (which is meant to be overriden). Hopefully that answers your question...

- Daniel
 
Upvote 0

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones