java - The method DataOutputStream(OutputStream) is undefined for the type -


i followed lot of tutorials make progress project. following tutorial create google cloud messaging server using json , jackson library.

i somehow got right jackson library of libraries on internet. error appeared title of question.

this code:

import java.io.bufferedreader; import java.io.dataoutputstream; import java.io.ioexception; import java.io.inputstreamreader; import java.net.httpurlconnection; import java.net.malformedurlexception; import java.net.url;  import org.codehaus.jackson.map.objectmapper;   public class post2gcm {      public static void post(string apikey, content content){         try{             //1. url             url url = new url("https://android.googleapis.com/gcm/send");             //2. open connection             httpurlconnection conn = (httpurlconnection) url.openconnection();             //3. specify post method             conn.setrequestmethod("post");             //4.set headers             conn.setrequestproperty("content-type", "application/json");             conn.setrequestproperty("authorization", "key="+apikey);              conn.setdooutput(true);             //5. add json data post request body             //5.1 use jackson object mapper convert contnet object json             objectmapper mapper = new objectmapper();             //5.2 connection stream              dataoutputstream wr = dataoutputstream(conn.getoutputstream());             //5.3 copy content "json"             mapper.writevalue(wr, content);             //5.4 send request             wr.flush();             //5.5             wr.close();             //6. response             int responsecode = conn.getresponsecode();             system.out.println("\nsending 'post' request url: "+url);             system.out.println("response code: "+responsecode);              bufferedreader in = new bufferedreader(new inputstreamreader(conn.getinputstream()));             string inputline;             stringbuffer response = new stringbuffer();              while((inputline = in.readline()) != null){                 response.append(inputline);             }             in.close();             //7. print result             system.out.println(response.tostring());         }catch(malformedurlexception e){             e.printstacktrace();         }catch(ioexception e){             e.printstacktrace();         }     } } 

i don't know how fix one, i've looked answers there isn't answer.

your missing new keyword

     //5.2 connection stream      dataoutputstream wr = dataoutputstream(conn.getoutputstream()); 

replace

   dataoutputstream wr = new dataoutputstream(conn.getoutputstream()); 

Comments

Popular posts from this blog

php - Admin SDK -- get information about the group -

dns - How To Use Custom Nameserver On Free Cloudflare? -

Python Error - TypeError: input expected at most 1 arguments, got 3 -