code error while running program

Common bugs/problems with the Android SDK the Emulator and the ADT-Plugin.

code error while running program

Postby madhavanmaddy » Wed Dec 15, 2010 7:22 am

hi i am developing a code for youtube in android but recently i am reciving some errors in log cat here i am pasting it
Code: Select all
12-15 11:50:33.085: WARN/ExpatReader(250): DTD handlers aren't supported.
12-15 11:50:33.095: WARN/System.err(250): java.lang.NullPointerException
12-15 11:50:33.124: WARN/System.err(250):     at com.youtube.YouTubeLauncher$ResponseHandler.characters(YouTubeLauncher.java:392)
12-15 11:50:33.134: WARN/System.err(250):     at org.apache.harmony.xml.ExpatParser.text(ExpatParser.java:166)
12-15 11:50:33.134: WARN/System.err(250):     at org.apache.harmony.xml.ExpatParser.append(Native Method)
12-15 11:50:33.134: WARN/System.err(250):     at org.apache.harmony.xml.ExpatParser.parseFragment(ExpatParser.java:506)
12-15 11:50:33.134: WARN/System.err(250):     at org.apache.harmony.xml.ExpatParser.parseDocument(ExpatParser.java:467)
12-15 11:50:33.134: WARN/System.err(250):     at org.apache.harmony.xml.ExpatReader.parse(ExpatReader.java:329)
12-15 11:50:33.134: WARN/System.err(250):     at org.apache.harmony.xml.ExpatReader.parse(ExpatReader.java:286)
12-15 11:50:33.143: WARN/System.err(250):     at javax.xml.parsers.SAXParser.parse(SAXParser.java:361)
12-15 11:50:33.143: WARN/System.err(250):     at javax.xml.parsers.SAXParser.parse(SAXParser.java:240)
12-15 11:50:33.143: WARN/System.err(250):     at com.youtube.YouTubeLauncher.readSDCardFile(YouTubeLauncher.java:102)
12-15 11:50:33.143: WARN/System.err(250):     at com.youtube.YouTubeLauncher.<init>(YouTubeLauncher.java:80)
12-15 11:50:33.143: WARN/System.err(250):     at java.lang.reflect.Constructor.constructNative(Native Method)
12-15 11:50:33.153: WARN/System.err(250):     at java.lang.reflect.Constructor.newInstance(Constructor.java:446)
12-15 11:50:33.153: WARN/System.err(250):     at android.test.suitebuilder.TestMethod.instantiateTest(TestMethod.java:87)
12-15 11:50:33.153: WARN/System.err(250):     at android.test.suitebuilder.TestMethod.createTest(TestMethod.java:73)
12-15 11:50:33.153: WARN/System.err(250):     at android.test.suitebuilder.TestSuiteBuilder.addTest(TestSuiteBuilder.java:263)
12-15 11:50:33.164: WARN/System.err(250):     at android.test.suitebuilder.TestSuiteBuilder.build(TestSuiteBuilder.java:185)
12-15 11:50:33.164: WARN/System.err(250):     at android.test.InstrumentationTestRunner.onCreate(InstrumentationTestRunner.java:336)
12-15 11:50:33.164: WARN/System.err(250):     at android.app.ActivityThread.handleBindApplication(ActivityThread.java:3982)
12-15 11:50:33.164: WARN/System.err(250):     at android.app.ActivityThread.access$2900(ActivityThread.java:119)
12-15 11:50:33.164: WARN/System.err(250):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1901)
12-15 11:50:33.174: WARN/System.err(250):     at android.os.Handler.dispatchMessage(Handler.java:99)
12-15 11:50:33.174: WARN/System.err(250):     at android.os.Looper.loop(Looper.java:123)
12-15 11:50:33.174: WARN/System.err(250):     at android.app.ActivityThread.main(ActivityThread.java:4363)
12-15 11:50:33.184: WARN/System.err(250):     at java.lang.reflect.Method.invokeNative(Native Method)
12-15 11:50:33.184: WARN/System.err(250):     at java.lang.reflect.Method.invoke(Method.java:521)
12-15 11:50:33.184: WARN/System.err(250):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
12-15 11:50:33.184: WARN/System.err(250):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
12-15 11:50:33.184: WARN/System.err(250):     at dalvik.system.NativeStart.main(Native Method)
12-15 11:50:33.214: INFO/TestSuiteBuilder(250): Failed to create test.
12-15 11:50:33.214: INFO/TestSuiteBuilder(250): java.lang.reflect.InvocationTargetException
12-15 11:50:33.214: INFO/TestSuiteBuilder(250):     at com.youtube.YouTubeLauncher.<init>(YouTubeLauncher.java:80)
12-15 11:50:33.214: INFO/TestSuiteBuilder(250):     at java.lang.reflect.Constructor.constructNative(Native Method)
12-15 11:50:33.214: INFO/TestSuiteBuilder(250):     at java.lang.reflect.Constructor.newInstance(Constructor.java:446)
12-15 11:50:33.214: INFO/TestSuiteBuilder(250):     at android.test.suitebuilder.TestMethod.instantiateTest(TestMethod.java:87)
12-15 11:50:33.214: INFO/TestSuiteBuilder(250):     at android.test.suitebuilder.TestMethod.createTest(TestMethod.java:73)
12-15 11:50:33.214: INFO/TestSuiteBuilder(250):     at android.test.suitebuilder.TestSuiteBuilder.addTest(TestSuiteBuilder.java:263)
12-15 11:50:33.214: INFO/TestSuiteBuilder(250):     at android.test.suitebuilder.TestSuiteBuilder.build(TestSuiteBuilder.java:185)
12-15 11:50:33.214: INFO/TestSuiteBuilder(250):     at android.test.InstrumentationTestRunner.onCreate(InstrumentationTestRunner.java:336)
12-15 11:50:33.214: INFO/TestSuiteBuilder(250):     at android.app.ActivityThread.handleBindApplication(ActivityThread.java:3982)
12-15 11:50:33.214: INFO/TestSuiteBuilder(250):     at android.app.ActivityThread.access$2900(ActivityThread.java:119)
12-15 11:50:33.214: INFO/TestSuiteBuilder(250):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1901)
12-15 11:50:33.214: INFO/TestSuiteBuilder(250):     at android.os.Handler.dispatchMessage(Handler.java:99)
12-15 11:50:33.214: INFO/TestSuiteBuilder(250):     at android.os.Looper.loop(Looper.java:123)
12-15 11:50:33.214: INFO/TestSuiteBuilder(250):     at android.app.ActivityThread.main(ActivityThread.java:4363)
12-15 11:50:33.214: INFO/TestSuiteBuilder(250):     at java.lang.reflect.Method.invokeNative(Native Method)
12-15 11:50:33.214: INFO/TestSuiteBuilder(250):     at java.lang.reflect.Method.invoke(Method.java:521)
12-15 11:50:33.214: INFO/TestSuiteBuilder(250):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
12-15 11:50:33.214: INFO/TestSuiteBuilder(250):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
12-15 11:50:33.214: INFO/TestSuiteBuilder(250):     at dalvik.system.NativeStart.main(Native Method)
12-15 11:50:33.214: INFO/TestSuiteBuilder(250): Caused by: java.lang.NullPointerException
12-15 11:50:33.214: INFO/TestSuiteBuilder(250):     at com.youtube.YouTubeLauncher.processScript(YouTubeLauncher.java:89)
12-15 11:50:33.214: INFO/TestSuiteBuilder(250):     at com.youtube.YouTubeLauncher.readSDCardFile(YouTubeLauncher.java:111)
12-15 11:50:33.214: INFO/TestSuiteBuilder(250):     ... 19 more
12-15 11:50:33.223: INFO/ActivityThread(250): Publishing provider com.google.android.youtube.SuggestionProvider: com.google.android.youtube.SuggestionsProvider
12-15 11:50:33.234: INFO/TestRunner(250): started: testSuiteConstructionFailed(android.test.suitebuilder.TestSuiteBuilder$FailedToCreateTests)
12-15 11:50:33.254: INFO/TestRunner(250): failed: testSuiteConstructionFailed(android.test.suitebuilder.TestSuiteBuilder$FailedToCreateTests)
12-15 11:50:33.264: INFO/TestRunner(250): ----- begin exception -----
12-15 11:50:33.284: INFO/TestRunner(250): java.lang.RuntimeException: Exception during suite construction
12-15 11:50:33.284: INFO/TestRunner(250):     at android.test.suitebuilder.TestSuiteBuilder$FailedToCreateTests.testSuiteConstructionFailed(TestSuiteBuilder.java:239)
12-15 11:50:33.284: INFO/TestRunner(250):     at java.lang.reflect.Method.invokeNative(Native Method)
12-15 11:50:33.284: INFO/TestRunner(250):     at java.lang.reflect.Method.invoke(Method.java:521)
12-15 11:50:33.284: INFO/TestRunner(250):     at junit.framework.TestCase.runTest(TestCase.java:154)
12-15 11:50:33.284: INFO/TestRunner(250):     at junit.framework.TestCase.runBare(TestCase.java:127)
12-15 11:50:33.284: INFO/TestRunner(250):     at junit.framework.TestResult$1.protect(TestResult.java:106)
12-15 11:50:33.284: INFO/TestRunner(250):     at junit.framework.TestResult.runProtected(TestResult.java:124)
12-15 11:50:33.284: INFO/TestRunner(250):     at junit.framework.TestResult.run(TestResult.java:109)
12-15 11:50:33.284: INFO/TestRunner(250):     at junit.framework.TestCase.run(TestCase.java:118)
12-15 11:50:33.284: INFO/TestRunner(250):     at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:169)
12-15 11:50:33.284: INFO/TestRunner(250):     at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:154)
12-15 11:50:33.284: INFO/TestRunner(250):     at android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:430)
12-15 11:50:33.284: INFO/TestRunner(250):     at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1447)
12-15 11:50:33.284: INFO/TestRunner(250): Caused by: java.lang.reflect.InvocationTargetException
12-15 11:50:33.284: INFO/TestRunner(250):     at com.youtube.YouTubeLauncher.<init>(YouTubeLauncher.java:80)
12-15 11:50:33.284: INFO/TestRunner(250):     at java.lang.reflect.Constructor.constructNative(Native Method)
12-15 11:50:33.284: INFO/TestRunner(250):     at java.lang.reflect.Constructor.newInstance(Constructor.java:446)
12-15 11:50:33.284: INFO/TestRunner(250):     at android.test.suitebuilder.TestMethod.instantiateTest(TestMethod.java:87)
12-15 11:50:33.284: INFO/TestRunner(250):     at android.test.suitebuilder.TestMethod.createTest(TestMethod.java:73)
12-15 11:50:33.284: INFO/TestRunner(250):     at android.test.suitebuilder.TestSuiteBuilder.addTest(TestSuiteBuilder.java:263)
12-15 11:50:33.284: INFO/TestRunner(250):     at android.test.suitebuilder.TestSuiteBuilder.build(TestSuiteBuilder.java:185)
12-15 11:50:33.284: INFO/TestRunner(250):     at android.test.InstrumentationTestRunner.onCreate(InstrumentationTestRunner.java:336)
12-15 11:50:33.284: INFO/TestRunner(250):     at android.app.ActivityThread.handleBindApplication(ActivityThread.java:3982)
12-15 11:50:33.284: INFO/TestRunner(250):     at android.app.ActivityThread.access$2900(ActivityThread.java:119)
12-15 11:50:33.284: INFO/TestRunner(250):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1901)
12-15 11:50:33.284: INFO/TestRunner(250):     at android.os.Handler.dispatchMessage(Handler.java:99)
12-15 11:50:33.284: INFO/TestRunner(250):     at android.os.Looper.loop(Looper.java:123)
12-15 11:50:33.284: INFO/TestRunner(250):     at android.app.ActivityThread.main(ActivityThread.java:4363)
12-15 11:50:33.284: INFO/TestRunner(250):     at java.lang.reflect.Method.invokeNative(Native Method)
12-15 11:50:33.284: INFO/TestRunner(250):     at java.lang.reflect.Method.invoke(Method.java:521)
12-15 11:50:33.284: INFO/TestRunner(250):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
12-15 11:50:33.284: INFO/TestRunner(250):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
12-15 11:50:33.284: INFO/TestRunner(250):     at dalvik.system.NativeStart.main(Native Method)
12-15 11:50:33.284: INFO/TestRunner(250): Caused by: java.lang.NullPointerException
12-15 11:50:33.284: INFO/TestRunner(250):     at com.youtube.YouTubeLauncher.processScript(YouTubeLauncher.java:89)
12-15 11:50:33.284: INFO/TestRunner(250):     at com.youtube.YouTubeLauncher.readSDCardFile(YouTubeLauncher.java:111)
12-15 11:50:33.284: INFO/TestRunner(250):     ... 19 more
12-15 11:50:33.284: INFO/TestRunner(250): ----- end exception -----



plz plz do help me
madhavanmaddy
Junior Developer
Junior Developer
 
Posts: 24
Joined: Wed Dec 15, 2010 7:04 am

Top

Re: code error while running program

Postby blundell » Wed Dec 15, 2010 10:21 am

NullPointerException, YouTubeLauncher.java class, line 392
User avatar
blundell
Master Developer
Master Developer
 
Posts: 1610
Joined: Tue Nov 18, 2008 12:58 pm
Location: UK

Re: code error while running program

Postby madhavanmaddy » Thu Dec 16, 2010 6:34 am

hey can you give me reason why this kind of error comes in code

that will be really helpful

tnks
madhavanmaddy
Junior Developer
Junior Developer
 
Posts: 24
Joined: Wed Dec 15, 2010 7:04 am

Re: code error while running program

Postby blundell » Thu Dec 16, 2010 10:10 am

Wow, if that's the case you need to go back to Java101 and learn about Null Pointers

http://www.cs.man.ac.uk/~johns/npe.html

Null pointer exceptions

Of the things which can go wrong at runtime in Java programs, null pointer exceptions are by far the most common. Recall that all values in Java programs are either scalars or references to objects, and that all variables have default values, which in the case of object references is null. Object references are like pointers in C, but are much more constrained: a C pointer can point to an arbitrary store location, while a Java object reference can point to an object of known type, or be null. When making a method call:

x.m()
there are therefore only two things that can go wrong: x might refer to a different object to that we intended, or it could be null. Fortunately, the latter is much more common in practice. The procedure for debugging null pointer exceptions is very simple:
Identify the line where it occurred.
Ask "what objects (or arrays) are being referenced on this line". One of them is null and it's usually obvious which.
Figure out why it's null.
Usually the thing which is null is an instance variable, and it's null because of some cockup with the constructor. This can occur in many ways: I've seen all of the cases below occur in practice, most of them many times. Suppose we have a simple class:
public class Widget {
private int value;

public Widget(int v) { value = v; }

public int getValue() { return value; }
}
and another class which uses it:
public class Oops {

private Widget theWidget;

public static void main(String[] args) {
Oops myInstance = new Oops();
System.out.println(myInstance.theWidget.getValue());
}
}
Obviously, when we run this we get a nullPointerException (1), because theWidget has its default value of null, courtesy of the default constructor for class Oops. (In principle, there are four things on the line which could be null - four dots - but we can hopefully rule out System and System.out, and we just created myInstance, so it has to be theWidget).
So we need to provide an appropriate constructor, which will either take a Widget as a parameter, or create one. In the former case, we ought to use a meaningful name for the parameter, and it's tedious to keep inventing meaningful names, so let's use the same name as the instance variable:

public Oops(Widget theWidget) {
theWidget = theWidget;
}
nullPointerException (2). Oh, of course, we forgot to change the main program, the default constructor's still getting called.

...
Oops myInstance = new Oops(new Widget(42));
...
NullPointerException (3) Eh? The problem is that both sides of the assignement
theWidget = theWidget;
refer to the parameter, not to the instance variable, which isn't touched. One solution - actually the one I use, is to explicitly say 'this.' on the left hand side. I used to think this was completely safe, but:
public Oops(Widget theWiget) {
this.theWidget = theWidget;
}
nullPointerException (4) Que? This time, because of the mis-spelling of the parameter name, both sides of the assignment refer to the instance variable, and it still doesn't get set properly.

Possibly the safest way is to use the same names, but decorate one or the other by some systematic convention like a leading underscore. (I think it's better to decorate the parameter, because that will probably only be referred to once, but some people prefer to decorate instance variables.)

public Oops(Widget _theWidget) {
this.theWidget = _theWidget;
}
The this. is now redundant, but I find it clearer to leave it in. The only thing which can go wrong now is if the parameter is null:

...
Oops myInstance = new Oops(null);
...
nullPointerException (5). In general, the caller of a constructor (or a method in general) is responsible for providing sensible parameters, and you shouldn't assume null is ok unless the documentation explicitly says so.
Now suppose we create the widget in the constructor:

public Oops() {
Widget theWidget = new Widget(42);
}
...
Oops myInstance = new Oops();
...
nullPointerException (6). This time, the left hand side of the assignement is a local variable in the constructor, and again the instance variable isn't touched.
Finally, my favourite:

public void Oops() {
this.theWidget = new Widget(42);
}
...
Oops myInstance = new Oops();
...
nullPointerException (7). I'll give you the option of figuring this one out for yourself. The answer is here.
These all look like pretty dumb mistakes when presented this way, but remember that normally there's a lot of other code around to confuse the issue.
User avatar
blundell
Master Developer
Master Developer
 
Posts: 1610
Joined: Tue Nov 18, 2008 12:58 pm
Location: UK

Top

Return to SDK/ADT/Emulator Problems

Who is online

Users browsing this forum: No registered users and 11 guests