I have a wierd problem. I have the following code:
if (fbIntent.hasExtra("Link")) {
try{
postData[0]= fbIntent.getStringExtra("Link");
} catch (Exception e) {Log.d("fbIntent error",e.getMessage() );}
}
fbIntent.hasExtra("Link") is true. So the compiler goes into the if statement. But I am not able to get the string using fbIntent.getStringExtra("Link"). This I know from debugging in eclipse. When I run it, I get :
01-21 14:12:01.030: ERROR/AndroidRuntime(311): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.examples.Kikin/com.examples.Kikin.FacebookLogin}: java.lang.NullPointerException: println needs a message
Please help me.
You need to initialize postData. Try something like String[] postData = new String[1]. Obviously, if you want use postData[1], [2], and [3], you'd need to say new String[4].
1) Your current issue is in
Log.d("fbIntent error", e.getMessage());
e.getMessage() may return null, so you get the java.lang.NullPointerException: println needs a message. Use e.toString() instead. Or the best way would be:
Log.e("some tag", "some comment", e);
2) When you fix this, you will be able to see the actual error to go further in fixing your root/real issue. So feel free to update your post with new log data.
Related
I'm trying to introduce the ACRA lib in my library project. When I set up the String for the toast, I get a "Attribute value must be a constant" error. Please see attached screen-shots
and the R.string.crash_toast_text:
Please note that these lines of code are from here
https://github.com/ACRA/acra/wiki/AdvancedUsage#toast-notification
Based on CommonsWare 18 answer, I made it work. Here is a sample code if anyone gets stuck in the same situation:
final ACRAConfiguration config = ACRA.getNewDefaultConfig(this);
try {
config.setMode(ReportingInteractionMode.TOAST);
} catch (ACRAConfigurationException e) {
e.printStackTrace();
}
config.setResToastText(R.string.crash_toast_text);
ACRA.init(this, config);
I need send all exception in my app to server or email, not crash. How can i do that?
try{
}catch(Exception e){
// here send e.getMessage() to server or email
}
Someone can help me?
Crashlytisc is the answer to you question. Your fatal exceptions will be logged to Crashlytics server implicitly while to log non-fatal exceptions you have to do it explicitly, like following;
try{
} catch(Exception e){
// Crashlytics.log(PRIORITY, TAG, MESSAGE);
Crashlytics.log(android.util.Log.ERROR, "TAG","Message");
}
That's what Exception Handling(your try catch is there for),Your App crashes when there is some Exception.Catch it in your try block and handle it in catch....You can write the java code of sending an email in the catch block.The exception generated will be passed as a an argument to the catch....
I am considering that you are not talking of NullPointerException or the other common UI exceptions .
See this for learning about Sending Email
As the question states I would like to know how to trace the cause of such a error.
During my research on this error I found various things using a inputstream. When it is called twice it gives the exception. However my code is not anything similar to those. I use a AndroidSaxParser inside a ViewPager. Each fragment executes a AsyncTask which parse a rss and loads the data into a ListView.
The problem occures at random times which makes it so difficult to trace what the problem causes. I also noticed that on a api 14+ device the problem doesn't occur at all. It only occurs at my api 8 device and probably at other devices < api 14.
The exact Expat error I get is :
ExpatParser$ParseException at line 1 column 0 no element found
The code at which the LogCat points is simply the code which starts the parser however nothing is null or different from times it does execute correctly.
try
{
Xml.parse(this.getInputStream(), Xml.Encoding.UTF_8, root.getContentHandler());
}
catch (Exception e)
{
Log.e("parser", "PARSER CRASHED");
Log.e("expat", "inputStream " + this.getInputStream() + " xml " + Xml.Encoding.UTF_8 + " contentHandler " + root.getContentHandler());
Log.w("the feed", "" + rssFeed);
throw new RuntimeException(e);
}
The trace :
errors
The inputStream you are using is empty when you are parsing it.First read the whole inputStream and then parse the content.
I tried to use
try {
new TwitterFactory(new ConfigurationBuilder()
.setOAuthConsumerKey(TWITTER_KEY)
.setOAuthConsumerSecret(TWITTER_SECRET)
.setOAuthAccessToken(TWITTER_TOKEN)
.setOAuthAccessTokenSecret(TWITTER_TOKEN_SECRET)
.build()).getInstance().updateStatus("HELLO WORLD!");
} catch (TwitterException e) {
e.printStackTrace();
}
But as soon as I run it, it gives me this error:
this might be a possible answer: In order to get access acquire AccessToken using xAuth, you must apply by sending an email to api#twitter.com — all other applications will receive an HTTP 401 error. from here but his answer is not complete (does not have steps to follow)
How to fix this? Thanks!
I'm trying to invoke a webservice and parse the returned XML, so my invoke URL is :
http://192.168.1.12/cr.ws/CarCategories.asmx/CarCategoryComparatorRQ?IdUser=1076&IdCurrency=1&IdLanguage=1&IdCarCategory=0&IdPickupRentCarAgencies=3&IdReturnRentCarAgencies=3&PickupDate=6/4/2011&ReturnDate=9/4/2011&Supplier=Prima%20Rent%20a%20Car&b=prima
in my browser I get the desired response :
<CarCategoryComparatorRS>
<CarCategory>
<IdCar>22</IdCar>
<IdCarCategory>22</IdCarCategory>
<Supplier>AvantGarde Rent a Car</Supplier>
<PickupRentCarAgencies>Tunis; Aéroport de Tunis-Carthage</PickupRentCarAgencies>
<IdPickupRentCarAgencies>5</IdPickupRentCarAgencies>
<ReturnRentCarAgencies>Tunis; Aéroport de Tunis-Carthage</ReturnRentCarAgencies>
<IdReturnRentCarAgencies>5</IdReturnRentCarAgencies>
<IdUser>705</IdUser>
<Title>Catégorie A [ex:Kia Rio;Renault Symbol]</Title>
<IdCurrency>1</IdCurrency>
<ImageUrl>Car-22-20090521-125545.jpg</ImageUrl>
<MemberReductionValue>0</MemberReductionValue>
<Rate>150</Rate>
<DelayRate>0</DelayRate>
<ReductionValue>135</ReductionValue>
<DayRate>45</DayRate>
<Reduction>10%</Reduction>
<AccompteValue>67.500</AccompteValue>
<Accompte>50</Accompte>
<TotalRate>0000135000</TotalRate>
</CarCategory>
</CarCategoryComparatorRS>
But this function trows java.io.FileNotFoundException
protected InputStream getInputStream() {
try {
return feedUrl.openConnection().getInputStream();
} catch (IOException e) {
throw new RuntimeException(e);
}
Please help me, I wasted couple hours searching but nothing :(
Thanks.
The error is caused by the spaces in this param :"Supplier=Prima Rent a Car", so i replaced this param by UrlEncoder.encode("Supplier=Prima Rent a Car") and it worked.
If you type that URL in your device's browser address bar do you get anything?
It looks like you are trying to request an address on a local machine or LAN. Are you requesting this on the android device? My guess is you need to run your server on the machine on a different interface or open up connections to the required port.
I think your url is being interpreted as a file url.
What about logging your url before you call openConnection as a sanity check:
Log.e("MyApp", feedUrl);
On second thought, could you post the logcat output? I'm skeptical as to how your code could ever throw a FileNotFoundException.