rawatdeepesh
rawatdeepesh

Reputation: 584

error in class extending AsyncTask

I have been trying to get some data from my dotnet webservice and pass the results in json format to my android application. The json data is retrieved in doInBackground fucntion (which is being overridden ) by calling the invokeJSONWS . This gives me an error when i try to call the publishProgress method . I need to pass the json data to this publishProgress method .Do i need to override publishProgress since the return type for it would be string[].

   private class ChartTask extends AsyncTask< String,Void, Void>{

    // Generates dummy data in a non-ui thread
    @Override
    protected Void doInBackground(String... params) {
        int i = 0;
        invokeJSONWS(params[0],"PopulateCities");
        return null;
        try{
            do{
                String [] values = new String[2];
                Random r = new Random();
                int visits = r.nextInt(27);

                values[0] = Integer.toString(i);
                values[1] = Integer.toString(visits);

                publishProgress(values);
                                 //Error here:The method publishProgress(Void...) in the type AsyncTask<String,Void,Void> is not applicable for the arguments (String[])                    
                Thread.sleep(1000);
                i++;
            }while(i<=30);
        }catch(Exception e){ }
        return null;
    }

    // Plotting generated data in the graph
    @Override
    protected void onProgressUpdate(String[] values) {
        visitsSeries.add(Integer.parseInt(values[0]), Integer.parseInt(values[1]));
        mChart.repaint();
    }
           //error here:The method onProgressUpdate(String[]) of type MainActivity.ChartTask must override or implement a supertype method

}


//Method which invoke web methods
public void invokeJSONWS(String country, String methName) {
    // Create request
    SoapObject request = new SoapObject(NAMESPACE, methName);
    // Property which holds input parameters
    PropertyInfo paramPI = new PropertyInfo();
    // Set Name
    paramPI.setName("country");
    // Set Value
    paramPI.setValue(country);
    // Set dataType
    paramPI.setType(String.class);
    // Add the property to request object
    request.addProperty(paramPI);
    // Create envelope
    SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
            SoapEnvelope.VER11);
    envelope.dotNet = true;
    // Set output SOAP object
    envelope.setOutputSoapObject(request);
    // Create HTTP call object
    HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);

    try {
        // Invole web service
        androidHttpTransport.call(SOAP_ACTION+methName, envelope);
        // Get the response
        SoapPrimitive response = (SoapPrimitive) envelope.getResponse();
        // Assign it to static variable
        responseJSON = response.toString();

    } catch (Exception e) {
        e.printStackTrace();
    }
}


@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.activity_main, menu);
    return true;
}

}

Is there a way out to this problem ? Thanks in Advance!!

The Logcat looks like this

04-18 05:55:24.680: W/dalvikvm(1324): VFY: unable to resolve new-instance 430 (Lcom/google/gson/Gson;) in Lin/wptrafficanalyzer/achartenginedynamicchart/MainActivity;
04-18 05:55:24.680: D/dalvikvm(1324): VFY: replacing opcode 0x22 at 0x000f
04-18 05:55:24.820: E/dalvikvm(1324): Could not find class 'org.ksoap2.serialization.SoapObject', referenced from method in.wptrafficanalyzer.achartenginedynamicchart.MainActivity.invokeJSONWS
04-18 05:55:24.820: W/dalvikvm(1324): VFY: unable to resolve new-instance 584 (Lorg/ksoap2/serialization/SoapObject;) in Lin/wptrafficanalyzer/achartenginedynamicchart/MainActivity;
04-18 05:55:24.850: D/dalvikvm(1324): VFY: replacing opcode 0x22 at 0x0000
04-18 05:55:24.850: D/dalvikvm(1324): DexOpt: unable to opt direct call 0x0c0f at 0x11 in Lin/wptrafficanalyzer/achartenginedynamicchart/MainActivity;.<init>
04-18 05:55:24.860: D/dalvikvm(1324): DexOpt: unable to opt direct call 0x0fd1 at 0x04 in Lin/wptrafficanalyzer/achartenginedynamicchart/MainActivity;.invokeJSONWS
04-18 05:55:24.860: D/dalvikvm(1324): DexOpt: unable to opt direct call 0x0fcd at 0x09 in Lin/wptrafficanalyzer/achartenginedynamicchart/MainActivity;.invokeJSONWS
04-18 05:55:24.860: D/dalvikvm(1324): DexOpt: unable to opt direct call 0x0fd4 at 0x20 in Lin/wptrafficanalyzer/achartenginedynamicchart/MainActivity;.invokeJSONWS
04-18 05:55:24.860: D/dalvikvm(1324): DexOpt: unable to opt direct call 0x0fd7 at 0x2d in Lin/wptrafficanalyzer/achartenginedynamicchart/MainActivity;.invokeJSONWS
04-18 05:55:24.890: D/AndroidRuntime(1324): Shutting down VM
04-18 05:55:24.900: W/dalvikvm(1324): threadid=1: thread exiting with uncaught exception (group=0xb2ac5ba8)
04-18 05:55:24.920: E/AndroidRuntime(1324): FATAL EXCEPTION: main
04-18 05:55:24.920: E/AndroidRuntime(1324): Process: in.wptrafficanalyzer.achartenginedynamicchart, PID: 1324
04-18 05:55:24.920: E/AndroidRuntime(1324): java.lang.NoClassDefFoundError: com.google.gson.Gson
04-18 05:55:24.920: E/AndroidRuntime(1324):     at in.wptrafficanalyzer.achartenginedynamicchart.MainActivity.<init>(MainActivity.java:43)
04-18 05:55:24.920: E/AndroidRuntime(1324):     at java.lang.Class.newInstanceImpl(Native Method)
04-18 05:55:24.920: E/AndroidRuntime(1324):     at java.lang.Class.newInstance(Class.java:1208)
04-18 05:55:24.920: E/AndroidRuntime(1324):     at android.app.Instrumentation.newActivity(Instrumentation.java:1061)
04-18 05:55:24.920: E/AndroidRuntime(1324):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2112)
04-18 05:55:24.920: E/AndroidRuntime(1324):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
04-18 05:55:24.920: E/AndroidRuntime(1324):     at android.app.ActivityThread.access$800(ActivityThread.java:135)
04-18 05:55:24.920: E/AndroidRuntime(1324):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
04-18 05:55:24.920: E/AndroidRuntime(1324):     at android.os.Handler.dispatchMessage(Handler.java:102)
04-18 05:55:24.920: E/AndroidRuntime(1324):     at android.os.Looper.loop(Looper.java:136)
04-18 05:55:24.920: E/AndroidRuntime(1324):     at android.app.ActivityThread.main(ActivityThread.java:5017)
04-18 05:55:24.920: E/AndroidRuntime(1324):     at java.lang.reflect.Method.invokeNative(Native Method)
04-18 05:55:24.920: E/AndroidRuntime(1324):     at java.lang.reflect.Method.invoke(Method.java:515)
04-18 05:55:24.920: E/AndroidRuntime(1324):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
04-18 05:55:24.920: E/AndroidRuntime(1324):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
04-18 05:55:24.920: E/AndroidRuntime(1324):     at dalvik.system.NativeStart.main(Native Method)
04-18 05:55:38.600: I/Process(1324): Sending signal. PID: 1324 SIG: 9

Upvotes: 0

Views: 1023

Answers (2)

Manish Dubey
Manish Dubey

Reputation: 4306

Change this:

private class ChartTask extends AsyncTask< String,Void, Void>{

to this :

private class ChartTask extends AsyncTask<String, String, Void>{

Upvotes: 1

Paresh Mayani
Paresh Mayani

Reputation: 128428

Because you have taken Void progress, instead it's required to be String as you are expecting String progress.

Upvotes: 1

Related Questions