Fatal Exception: AsyncTask #1 - exception

I have a Fatal Exception: AsyncTask #1 in the following part, but dont know why.
/**
* getting Charts from URL
* */
protected String doInBackground(String... args) {
// Building Parameters
ArrayList<NameValuePair> params = new ArrayList<NameValuePair>();
// getting JSON string from URL
JSONObject json = jParser.makeHttpRequest(url_read, "POST", params);
// Check your log cat for JSON response
Log.d("Charts: ", json.toString());
try {
// Checking for SUCCESS TAG
int success = json.getInt(TAG_SUCCESS);
if (success == 1) {
// products found
// Getting Array of Products
JSONArray charts = json.getJSONArray(TAG_CHARTS);
// looping through All Products
for(int i=0;i<charts.length();i++) {
JSONObject json_data = charts.getJSONObject(i);
String id = json_data.getString("id");
String interpret = json_data.getString("interpret");
String titel = json_data.getString("titel");
String album = json_data.getString("album");
String albumcover = json_data.getString("albumcover");
String likes = json_data.getString("likes");
HashMap<String, String> map = new HashMap<String, String>();
map.put(TAG_ID, id);
map.put(TAG_INTERPRET, interpret);
map.put(TAG_TITEL, titel);
map.put(TAG_ALBUM, album);
map.put(TAG_ALBUMCOVER, albumcover);
map.put(TAG_LIKES, likes);
songslist.add(map);
}
} else {
// no products found
// Launch Add New product Activity
Intent i = new Intent(getApplicationContext(),
CreateSong.class);
// Closing all previous activities
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(i);
}
} catch (JSONException e) {
e.printStackTrace();
}
return null;
}
This is my first question. Hope you know what to do. I get the data from a Database and put them into a JSON Array and then into a Hashmap, but it seems that the error comes by the JSON.
EDIT: LOG CAT
07-11 23:20:48.320: D/CLIPBOARD(13241): Hide Clipboard dialog at Starting input: finished by someone else... !
07-11 23:20:52.510: D/dalvikvm(13241): GC_FOR_ALLOC freed 139K, 3% free 9004K/9223K, paused 13ms
07-11 23:20:52.650: E/JSON Parser(13241): Error parsing data org.json.JSONException: Value <!DOCTYPE of type java.lang.String cannot be converted to JSONObject
07-11 23:20:52.650: W/dalvikvm(13241): threadid=11: thread exiting with uncaught exception (group=0x40c331f8)
07-11 23:20:52.675: E/AndroidRuntime(13241): FATAL EXCEPTION: AsyncTask #1
07-11 23:20:52.675: E/AndroidRuntime(13241): java.lang.RuntimeException: An error occured while executing doInBackground()
07-11 23:20:52.675: E/AndroidRuntime(13241): at android.os.AsyncTask$3.done(AsyncTask.java:278)
07-11 23:20:52.675: E/AndroidRuntime(13241): at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
07-11 23:20:52.675: E/AndroidRuntime(13241): at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
07-11 23:20:52.675: E/AndroidRuntime(13241): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
07-11 23:20:52.675: E/AndroidRuntime(13241): at java.util.concurrent.FutureTask.run(FutureTask.java:137)
07-11 23:20:52.675: E/AndroidRuntime(13241): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
07-11 23:20:52.675: E/AndroidRuntime(13241): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
07-11 23:20:52.675: E/AndroidRuntime(13241): at java.lang.Thread.run(Thread.java:856)
07-11 23:20:52.675: E/AndroidRuntime(13241): Caused by: java.lang.NullPointerException
07-11 23:20:52.675: E/AndroidRuntime(13241): at de.andreasgloeckner.ShowCharts$LoadAllProducts.doInBackground(ShowCharts.java:172)
07-11 23:20:52.675: E/AndroidRuntime(13241): at de.andreasgloeckner.ShowCharts$LoadAllProducts.doInBackground(ShowCharts.java:1)
07-11 23:20:52.675: E/AndroidRuntime(13241): at android.os.AsyncTask$2.call(AsyncTask.java:264)
07-11 23:20:52.675: E/AndroidRuntime(13241): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
07-11 23:20:52.675: E/AndroidRuntime(13241): ... 4 more

You have a NullPointerException in your code (ShowCharts.java, line 172). Now figure out which line is that . You are accessing on a null object obviously or just share line 172 here. It could be songslist object. I don't see initialization in the code block you shared.
Caused by: java.lang.NullPointerException
07-11 23:20:52.675: E/AndroidRuntime(13241): at de.andreasgloeckner.ShowCharts$LoadAllProducts.doInBackground(ShowCharts.java:172)

from inside the doInBackground method , you cant change or touch any UI element , so you cant call another activity , what you have to do is to call the another activity from inside the onPostExecute method from your Asynctask

Related

DriveClient and DriveResourceClient always throwing FATAL EXCEPTION

I got a successful GoogleSignInAccount object, and I need to get both DriveClient and DriveResourceClient of this account, I'm actualy doing in this way:
GoogleSignInAccount account = GoogleSignIn.getLastSignedInAccount(this);
if(account != null){
DriveClient driveClient = Drive.getDriveClient(this,account);
DriveResourceClient driveResourceClient = Drive.getDriveResourceClient(this,account);
}
But, when I try to perform simple tasks like:
DriveFolder root = driveResourceClient.getRootFolder().getResult();
I get this error:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.myorg.myapp, PID: 21980
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.myorg.myapp/com.myorg.myapp.DriveUpload2}: java.lang.IllegalStateException: Task is not yet complete
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.access$900(ActivityThread.java:150)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: java.lang.IllegalStateException: Task is not yet complete
at com.google.android.gms.common.internal.Preconditions.checkState(Unknown Source)
at com.google.android.gms.tasks.zzu.zzb(Unknown Source)
at com.google.android.gms.tasks.zzu.getResult(Unknown Source)
at com.myorg.myapp.DriveUpload2.signIn(DriveUpload2.java:94)
at com.myorg.myapp.DriveUpload2.onCreate(DriveUpload2.java:139)
at android.app.Activity.performCreate(Activity.java:6406)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1108)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) 
at android.app.ActivityThread.access$900(ActivityThread.java:150) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:148) 
at android.app.ActivityThread.main(ActivityThread.java:5417) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
All scope configurations on Google Console Credentials page are correct, and required scope like Drive.SCOPE_FILE and Drive.SCOPE_APPFOLDER have already been requested during the creation of GoogleSignInOptions.

elephantbird registered still showing error 2998

grunt> register '/home/piyush/Desktop/pro/json-simple-1.1.1.jar'
grunt> register '/home/piyush/Desktop/pro/elephant-bird-pig-4.1.jar'
grunt> register '/home/piyush/Desktop/pro/elephant-bird-hadoop-compat-4.1.jar'
grunt> register '/home/piyush/Desktop/pro/elephant-bird-core-4.1.jar'
grunt> load_tweets = LOAD '/home/piyush/Desktop/pro/quattr.txt' USING com.twitter.elephantbird.pig.load.JsonLoader('-nestedLoad') AS myMap;
2017-01-26 07:16:29,631 [main] ERROR org.apache.pig.tools.grunt.Grunt - ERROR 2998: Unhandled internal error. org/slf4j/LoggerFactory
grunt> load1_tweets = LOAD '/home/piyush/Desktop/pro/product.txt' USING com.twitter.elephantbird.pig.load.JsonLoader('-nestedLoad') AS myMap;
2017-01-26 07:17:47,740 [main] ERROR org.apache.pig.tools.grunt.Grunt - ERROR 2998: Unhandled internal error. Could not initialize class com.twitter.elephantbird.pig.load.JsonLoader
I registered all required jar files and then load two different json. Both show error 2998 with load1_tweets an additional error that Could not initialize class as shown above. How to reslove this error.
Getting following error in the logfile:
Pig Stack Trace
---------------
ERROR 2998: Unhandled internal error. org/slf4j/LoggerFactory
java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory
at com.twitter.elephantbird.pig.load.LzoBaseLoadFunc.<clinit>(LzoBaseLoadFunc.java:36)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:348)
at org.apache.pig.impl.PigContext.resolveClassName(PigContext.java:651)
at org.apache.pig.parser.LogicalPlanBuilder.validateFuncSpec(LogicalPlanBuilder.java:1336)
at org.apache.pig.parser.LogicalPlanBuilder.buildFuncSpec(LogicalPlanBuilder.java:1324)
at org.apache.pig.parser.LogicalPlanGenerator.func_clause(LogicalPlanGenerator.java:5184)
at org.apache.pig.parser.LogicalPlanGenerator.load_clause(LogicalPlanGenerator.java:3515)
at org.apache.pig.parser.LogicalPlanGenerator.op_clause(LogicalPlanGenerator.java:1625)
at org.apache.pig.parser.LogicalPlanGenerator.general_statement(LogicalPlanGenerator.java:1102)
at org.apache.pig.parser.LogicalPlanGenerator.statement(LogicalPlanGenerator.java:560)
at org.apache.pig.parser.LogicalPlanGenerator.query(LogicalPlanGenerator.java:421)
at org.apache.pig.parser.QueryParserDriver.parse(QueryParserDriver.java:191)
at org.apache.pig.PigServer$Graph.validateQuery(PigServer.java:1791)
at org.apache.pig.PigServer$Graph.registerQuery(PigServer.java:1764)
at org.apache.pig.PigServer.registerQuery(PigServer.java:707)
at org.apache.pig.tools.grunt.GruntParser.processPig(GruntParser.java:1075)
at org.apache.pig.tools.pigscript.parser.PigScriptParser.parse(PigScriptParser.java:505)
at org.apache.pig.tools.grunt.GruntParser.parseStopOnError(GruntParser.java:231)
at org.apache.pig.tools.grunt.GruntParser.parseStopOnError(GruntParser.java:206)
at org.apache.pig.tools.grunt.Grunt.run(Grunt.java:66)
at org.apache.pig.Main.run(Main.java:564)
at org.apache.pig.Main.main(Main.java:176)
Caused by: java.lang.ClassNotFoundException: org.slf4j.LoggerFactory
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 23 more

Grails: Value out of sequence: expected mode to be OBJECT or ARRAY when writing

I'm trying to parse a JSON object using grails.converters.JSON, but this errors appears.
The code
def str = '{"a": "b"}'
def json = new JSON(str)
or
def map = [:]
map.a = "b"
def json = map as JSON
json = new JSON(json.toString())
are returning this following error:
2016-11-22 14:21:34.592 ERROR --- [nio-8080-exec-9] o.g.web.errors.GrailsExceptionResolver : JSONException occurred when processing request: [GET] /test/index
Value out of sequence: expected mode to be OBJECT or ARRAY when writing '{"a":"b"}' but was INIT. Stacktrace follows:
java.lang.reflect.InvocationTargetException: null
at org.grails.core.DefaultGrailsControllerClass$ReflectionInvoker.invoke(DefaultGrailsControllerClass.java:210)
at org.grails.core.DefaultGrailsControllerClass.invoke(DefaultGrailsControllerClass.java:187)
at org.grails.web.mapping.mvc.UrlMappingsInfoHandlerAdapter.handle(UrlMappingsInfoHandlerAdapter.groovy:90)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:963)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:897)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:861)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846)
at org.springframework.boot.web.filter.ApplicationContextHeaderFilter.doFilterInternal(ApplicationContextHeaderFilter.java:55)
at org.grails.web.servlet.mvc.GrailsWebRequestFilter.doFilterInternal(GrailsWebRequestFilter.java:77)
at org.grails.web.filters.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:67)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.RuntimeException: org.grails.web.converters.exceptions.ConverterException: org.grails.web.json.JSONException: Value out of sequence: expected mode to be OBJECT or ARRAY when writing '{"a":"b"}' but was INIT
at org.grails.web.converters.AbstractConverter.toString(AbstractConverter.java:111)
at grails3.TestController$$EQ3IkyX7.index(TestController.groovy:25)
... 14 common frames omitted
Caused by: org.grails.web.converters.exceptions.ConverterException: org.grails.web.json.JSONException: Value out of sequence: expected mode to be OBJECT or ARRAY when writing '{"a":"b"}' but was INIT
at grails.converters.JSON.value(JSON.java:193)
at grails.converters.JSON.render(JSON.java:119)
at org.grails.web.converters.AbstractConverter.toString(AbstractConverter.java:109)
... 15 common frames omitted
Caused by: org.grails.web.json.JSONException: Value out of sequence: expected mode to be OBJECT or ARRAY when writing '{"a":"b"}' but was INIT
at org.grails.web.json.JSONWriter.append(JSONWriter.java:142)
at org.grails.web.json.JSONWriter.value(JSONWriter.java:353)
at grails.converters.JSON.value(JSON.java:162)
... 17 common frames omitted
Grails version: 3.2.3
Java version: 1.8u45 and 1.8u111
This statement itself converts the map to JSON.
def val = [a: 101, b: '100'] as JSON
You don't need the do this json = new JSON(json.toString()) anymore

Google search with Retrofit

I am trying to learn Retrofit and want to use it for Google search. I have written following code:
public class RetrofitSample {
private static final String URL = "https://www.google.com";
interface Google {
#GET("/search?q=retrofit")
String search();
}
public static void main(String... args) {
RestAdapter restAdapter = new RestAdapter.Builder()
.setEndpoint(URL)
.build();
Google goog = restAdapter.create(Google.class);
String result = goog.search();
System.out.println(result);
}
}
When I run this code I am getting following error:
Exception in thread "main" retrofit.RetrofitError: com.google.gson.JsonSyntaxException: com.google.gson.stream.MalformedJsonException: Use JsonReader.setLenient(true) to accept malformed JSON at line 1 column 12 path $
at retrofit.RetrofitError.conversionError(RetrofitError.java:33)
at retrofit.RestAdapter$RestHandler.invokeRequest(RestAdapter.java:383)
at retrofit.RestAdapter$RestHandler.invoke(RestAdapter.java:240)
at $Proxy0.search(Unknown Source)
at RetrofitSample.main(RetrofitSample.java:25)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134)
Caused by: retrofit.converter.ConversionException: com.google.gson.JsonSyntaxException: com.google.gson.stream.MalformedJsonException: Use JsonReader.setLenient(true) to accept malformed JSON at line 1 column 12 path $
at retrofit.converter.GsonConverter.fromBody(GsonConverter.java:67)
at retrofit.RestAdapter$RestHandler.invokeRequest(RestAdapter.java:367)
... 8 more
Caused by: com.google.gson.JsonSyntaxException: com.google.gson.stream.MalformedJsonException: Use JsonReader.setLenient(true) to accept malformed JSON at line 1 column 12 path $
at com.google.gson.Gson.assertFullConsumption(Gson.java:786)
at com.google.gson.Gson.fromJson(Gson.java:776)
at retrofit.converter.GsonConverter.fromBody(GsonConverter.java:63)
... 9 more
Caused by: com.google.gson.stream.MalformedJsonException: Use JsonReader.setLenient(true) to accept malformed JSON at line 1 column 12 path $
at com.google.gson.stream.JsonReader.syntaxError(JsonReader.java:1573)
at com.google.gson.stream.JsonReader.checkLenient(JsonReader.java:1423)
at com.google.gson.stream.JsonReader.doPeek(JsonReader.java:546)
at com.google.gson.stream.JsonReader.peek(JsonReader.java:429)
at com.google.gson.Gson.assertFullConsumption(Gson.java:782)
... 11 more
Do I have to use Google search API (costum search) or is Google search returning som other type as result?
Thanks in advance.

ESB Mule Client staring with xml-properties fails

I use Mule 3.x
I have a code that tests MuleClient connectivity.
This test is ok and works proper way:
public void testHello() throws Exception
{
MuleClient client = new MuleClient(muleContext);
MuleMessage result = client.send("http://127.0.0.1:8080/hello", "some data", null);
assertNotNull(result);
assertNull(result.getExceptionPayload());
assertFalse(result.getPayload() instanceof NullPayload);
//TODO Assert the correct data has been received
assertEquals("hello", result.getPayloadAsString());
}
But this tes is not ok - it fail with an connection exceptions:
public void testHello_with_Spring() throws Exception {
MuleClient client = new MuleClient("mule-config-test.xml");
client.getMuleContext().start();
//it fails here
MuleMessage result = client.send("http://127.0.0.1:8080/hello", "some data", null);
assertNotNull(result);
assertNull(result.getExceptionPayload());
assertFalse(result.getPayload() instanceof NullPayload);
//TODO Assert the correct data has been received
assertEquals("hello", result.getPayloadAsString());
}
The 'mule-config-test.xml' is used in both tests, the path for this file is ok, i checked.
This is error message I have in the end:
Exception stack is:
1. Address already in use (java.net.BindException) java.net.PlainSocketImpl:-2 (null)
2. Failed to bind to uri "http://127.0.0.1:8080/hello" (org.mule.transport.ConnectException)
org.mule.transport.tcp.TcpMessageReceiver:81
(http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/transport/ConnectException.html)
-------------------------------------------------------------------------------- Root Exception stack trace: java.net.BindException: Address already in
use at java.net.PlainSocketImpl.socketBind(Native Method) at
java.net.PlainSocketImpl.bind(PlainSocketImpl.java:383) at
java.net.ServerSocket.bind(ServerSocket.java:328)
+ 3 more (set debug level logging or '-Dmule.verbose.exceptions=true' for everything)
[10-05 16:33:37] ERROR HttpConnector [main]:
org.mule.transport.ConnectException: Failed to bind to uri
"http://127.0.0.1:8080/hello" [10-05 16:33:37] ERROR ConnectNotifier
[main]: Failed to connect/reconnect: HttpConnector {
name=connector.http.mule.default lifecycle=stop this=7578a7d9
numberOfConcurrentTransactedReceivers=4
createMultipleTransactedReceivers=true connected=false
supportedProtocols=[http] serviceOverrides= } . Root Exception
was: Address already in use. Type: class java.net.BindException [10-05
16:33:37] ERROR DefaultSystemExceptionStrategy [main]: Failed to bind
to uri "http://127.0.0.1:8080/hello"
org.mule.api.lifecycle.LifecycleException: Cannot process event as
"connector.http.mule.default" is stopped
I think the problem is in what you're not showing: testHello_with_Spring() is probably executing while Mule is already running. The second Mule you're starting in it then port-conflicts with the other one.
Are testHello() and testHello_with_Spring() in the same test suite? If yes, seeing that testHello() relies on an already running Mule, I'd say that would be the cause of port conflict for testHello_with_Spring().