The Big Programming Thread - Page 594
Forum Index > General Forum |
Thread Rules 1. This is not a "do my homework for me" thread. If you have specific questions, ask, but don't post an assignment or homework problem and expect an exact solution. 2. No recruiting for your cockamamie projects (you won't replace facebook with 3 dudes you found on the internet and $20) 3. If you can't articulate why a language is bad, don't start slinging shit about it. Just remember that nothing is worse than making CSS IE6 compatible. 4. Use [code] tags to format code blocks. | ||
Blisse
Canada3710 Posts
| ||
sabas123
Netherlands3122 Posts
from ez pz to this stuff scares me within 10 minutes lol. | ||
Manit0u
Poland17202 Posts
On February 25 2015 21:06 sabas123 wrote: why are coding projects so much harder than tutorialsT_T from ez pz to this stuff scares me within 10 minutes lol. Mostly because tutorials: a) show you only the most basic stuff b) don't concern themselves with common real world applications (like guarding against wrong/malicious user input for example) c) are heavily outdated most of the time d) focus on specific - small - parts of the project, disregarding the wider view and project-wide scope e) are created with single use-case in mind (for example, almost every single web tutorial only shows you how to create a simple blog, with a very simple blog-friendly cms, if that) f) don't show you alternative ways of doing things, so you can pick and choose (and this way already know several possibilities and their implementation) instead of trying to figure out everything yourself g) don't consider the possibility of you using different project structure (folders, files, namespaces) than one used in the tutorial. Just to name a few ![]() | ||
FFGenerations
7088 Posts
so im trying to retrieve a get response from IMDB.com's API in java EE there's so many different examples or tutorials but none actually do the straight forward thing that i want to do step by step. the only one that came close was netbeans connecting to twitter but even that is using application modules instead of web and using an API that is a twitter feed pre-loaded into the IDE and even then that no longer exists!! anyway i started hacking this guy's really nice example of connecting to a weather website API (had to install vaadin view framework) it looks like i've made some progress (especially in understanding what's going on) but im at a problem for a long time now i am getting + Show Spoiler + javax.servlet.ServletException: com.vaadin.server.ServiceException: org.glassfish.jersey.message.internal.MessageBodyProviderNotFoundException: MessageBodyReader not found for media type=text/html; charset=utf-8, type=class org.example.domain.ForecastResponse, genericType=class org.example.domain.ForecastResponse. i pasted + Show Spoiler + <dependency> <groupId>org.glassfish.jersey.media</groupId> <artifactId>jersey-media-moxy</artifactId> <version>2.15</version> </dependency> then i tried changing .request(MediaType.TEXT_HTML) back and forth to APPLICATION_JSON (imdb defaults to json) and TEXT_HTML_TYPE or whatever i tried. lastly i tried changing my query input from a correct movie ID tt1285016 to an incorrect one to see if that would give a different result when it only returns 2 parameters instead of 20. this brings me to the question: how does my application know how to map the response from the API to the class? a normal response is a JSON string that has 20 fields so how does my application know where to put them? maybe this is the missing link. i just changed the movie classes attributes to Response and Error to match the 2 returns from sending an incorrect movie ID to the API but still same problem here is the code...... im very tired so will post now then have another look and keep going view (java class)
service
display controller (oh god i better look at this next i think i forgot to)
response class
child movie class
the guy's project before i cut it up (you need vaadin plugin) https://github.com/mstahv/consuming-rest-apis his blog about the project (i shud reread it) https://vaadin.com/blog/-/blogs/consuming-rest-services-from-java-applications just to reiterate i am getting + Show Spoiler + javax.servlet.ServletException: com.vaadin.server.ServiceException: org.glassfish.jersey.message.internal.MessageBodyProviderNotFoundException: MessageBodyReader not found for media type=text/html; charset=utf-8, type=class org.example.domain.ForecastResponse, genericType=class org.example.domain.ForecastResponse. i must eat some biscuits edit: updated the line to have the correct methods in it....
tried to run using the anime news network's API instead and getting similar error which differs in saying "messagbodyreader not found" for text/xml instead of text/html... edit: why it take an hour to figure out how to upload a fucking project to github? all the videos assume you have dropdown options that dont exist, github tutorial only tells you how to edit the default text file on their system, eventually you figure out you need some 3rd party software to upload because your IDE is unable to do it until "you do it once somehow already" and then you get "failed to sync this branch you might need to open a shell and debug the state of this repo" as if i know what more than 2 of those words even mean. 2 seconds to upload a zip file to mirrorcreator.... ok over an hour later and still cant get any of this fucking git shit to upload my shit so here is the literally 9 kb file if you want it to open https://www.mirrorcreator.com/files/KQF7SBBH/restapiexampletest1zip._links . i deleted the git directory in it but hopefully everything is right | ||
Manit0u
Poland17202 Posts
https://help.github.com/articles/set-up-git/ Some required reading: https://www.atlassian.com/git/tutorials/ https://help.github.com/articles/set-up-git/ GitBash will be your BFF from now on. As far as the code goes, even just skimming through it I've noticed that you have 'omdb' instead of 'imdb'. Could this be your problem? | ||
FFGenerations
7088 Posts
the problem is possibly that im trying to insert X data into X class which it doesnt fit...... i would have thought the problem occurs befoer that happens and also the error message is weird....and isnt this evidenced by the fact the error msg changes when i change it to different website ??? just got an ambulance coz i had lung pain the last few weeks and it was pretty bad today then i started fainting suddenly .... ok now i guess.... this fucking git bullshit | ||
Ropid
Germany3557 Posts
| ||
Deleted User 3420
24492 Posts
class{ variable2 = 5 method(){ variable1 = variable2 *5; }} so I create an instance of it call method and now variable 1 is 25 here for that object later in my program I do object.variable2 = 10 and so variable 2 becomes 10. variable1 doesn't change values though (I thought it would). It seems to keep whatever value variable1 had when the object was created, which I guess makes sense. Is there a way to make my object "update" all it's variables that are based on a formula? | ||
Manit0u
Poland17202 Posts
On February 26 2015 06:19 travis wrote: hey guys, I have a method that declares a variable like this class{ variable2 = 5 method(){ variable1 = variable2 *5; }} so I create an instance of it call method and now variable 1 is 25 here for that object later in my program I do object.variable2 = 10 and so variable 2 becomes 10. variable1 doesn't change values though (I thought it would). It seems to keep whatever value variable1 had when the object was created, which I guess makes sense. Is there a way to make my object "update" all it's variables that are based on a formula? http://java.about.com/od/workingwithobjects/a/accessormutator.htm | ||
Deleted User 3420
24492 Posts
that, uh, makes sense | ||
AKnopf
Germany259 Posts
This way in the rest of your code you just have to call your methodWithAGoodNameForTheThingThatIsVariable1 instead of using variable1 and you can always be sure it has the correct value. That of course only works, when variable1 should always be variable2 * 5, as mentioned above. Think of it this way: variable1 does not really add any new information to instance of your class, because all the information is already in variable2. It is only a shortcut so you don't have to do the calculation *5 as often. (That is btw. a cache) Usually, that is not worth the hassle of having two variables which have to be kept consistent. ----------------- On February 26 2015 04:35 Ropid wrote: Here's a simplified guide for git: http://rogerdudler.github.io/git-guide/ Yeah, I didn't know there was Source Tree for windows now. That's great news. ![]() | ||
RoyGBiv_13
United States1275 Posts
On February 26 2015 07:27 AKnopf wrote: Why is variable1 a variable in the first place, when it is based only of the value of variable2 and should change every time variable1 changes? Usually, you would use a method for that.
This way in the rest of your code you just have to call your methodWithAGoodNameForTheThingThatIsVariable1 instead of using variable1 and you can always be sure it has the correct value. That of course only works, when variable1 should always be variable2 * 5, as mentioned above. Think of it this way: variable1 does not really add any new information to instance of your class, because all the information is already in variable2. It is only a shortcut so you don't have to do the calculation *5 as often. (That is btw. a cache) Usually, that is not worth the hassle of having two variables which have to be kept consistent. ----------------- Yeah, I didn't know there was Source Tree for windows now. That's great news. ![]() It's java, so it doesn't really matter, but using a variable to cache a commonly accessed value is an easy speed optimization that a compiler can't easily optimize for [1]. Python programmers have this pretty well ingrained into them, as if you look at any class properties, they are often cached values even if they are derived. Not to mention the readability improvement for representing two separate data both as parameters with different names rather than having one be a function and another be a parameter. + Show Spoiler [1] + In our C compiler, if we can statically count each time a derived value is accessed, we may be able to fit it in registers instead of recomputing. I don''t know if the optimization takes into account the complexity of the computation, but it probably does. x86 is screwed on this count, as it doesn't have registers to scratch. + Show Spoiler + It's better just to be smarter than the compiler and tell it to cache to value... | ||
Blisse
Canada3710 Posts
omdb returns json, ann returns xml, you can't do the same thing for both of the formats. | ||
Deleted User 3420
24492 Posts
If that's the case... what's the alternative? I just want to give my users a few seconds to read the text on the screen before the text changes. | ||
Blisse
Canada3710 Posts
In either case, use a timer construct in the language instead. | ||
FFGenerations
7088 Posts
On February 26 2015 08:52 Blisse wrote: @ff omdb returns json, ann returns xml, you can't do the same thing for both of the formats. yo, (as mentioned) i have them with application_xml, aplpication_json, text_html, application_xml_type or whatever they all are and no change. i tried adding the line .header("Content-type", "text/html") alongside the .request(MediaType.TEXT_HTML) . i tried adding more random dependencies (why my project stop deploying and i have to reload old version to get it to deploy again? fuck it). i'll move onto something different today so dont worry about it.... i think its to do with the way i try to handle the api response, or maybe some configuration is missing, but either way i cant waste any more time on this and will look at different implementations and work towards a clean build | ||
berated-
United States1134 Posts
On February 26 2015 12:11 FFGenerations wrote: yo, (as mentioned) i have them with application_xml, aplpication_json, text_html, application_xml_type or whatever they all are and no change. i tried adding the line .header("Content-type", "text/html") alongside the .request(MediaType.TEXT_HTML) . i tried adding more random dependencies (why my project stop deploying and i have to reload old version to get it to deploy again? fuck it). i'll move onto something different today so dont worry about it.... i think its to do with the way i try to handle the api response, or maybe some configuration is missing, but either way i cant waste any more time on this and will look at different implementations and work towards a clean build Omdb does return json, but they don't do so in an appropriate way. The header you are looking for is Accept: application/json .. but they seem to ignore that and any request and just send you back json with a Content-Type of text/html which is just wrong. When you use jersey client, it definitely tries to honor the return type if you use the autotmatic mapping. I would suggest you not do that. Instead of doing .get(Class.class) you can instead just do get which should return a Response object. You can then get the response object to give you the body as a String and then you parse the content as json yourself using either json or still going with moxy. If you are going to do this route I'd suggest looking at gson. Edit: Looks like if you use the r query param it sends back the right content-type for xml http://www.omdbapi.com/?i=tt1285016&r=xml Still doesn't for json even if you do r=json If you have it send you back XML you're still going to have to start playing with Entities which it doesn't look like you are doing. I personally still think it would be easier to just get it as json and get the body as a string and parse it yourself. | ||
FFGenerations
7088 Posts
thanks dude. like i said ill start from scratch from a dif perspective/setup i try
but still com.vaadin.server.ServiceException: org.glassfish.jersey.message.internal.MessageBodyProviderNotFoundException: MessageBodyReader not found for media type=text/xml; charset=utf-8, type=class org.example.domain.ForecastResponse, genericType=class org.example.domain.ForecastResponse.etc and besides its similarlly (but not identically) problem on animenewsnetwork as with imdb | ||
Blisse
Canada3710 Posts
just call .get(String.class) and it'll give a string object you can work with instead (unless it fails) | ||
nunez
Norway4003 Posts
| ||
| ||