Import issues! - Android Software Development

Just started working on an Android project. I've messed before but never anything too serious. But now its game time.
Code:
import org.appache.http.*;
now HttpClient, DefaultHttpClient, and HttpPost are all telling me I need to import their specific package.
Does android not allow me to .*; and pull in the entire lib?
Eclipse corrects it by importing the specific
Code:
import org.apache.http.impl.client.DefaultHttpClient;

That's Java 101.
"import a.b.*" only imports the classes directly within the "a.b" package, not any of the sub-packages.
Just use Eclipse's "Organize Imports". Ctrl+shift+O. It'll ask you to clarify which class you mean sometimes (when there's more than one class in the classpath with identical names), but in general It Just Works.

mstorer3772 said:
That's Java 101.
"import a.b.*" only imports the classes directly within the "a.b" package, not any of the sub-packages.
Just use Eclipse's "Organize Imports". Ctrl+shift+O. It'll ask you to clarify which class you mean sometimes (when there's more than one class in the classpath with identical names), but in general It Just Works.
Click to expand...
Click to collapse
I knew this in the back of my head but its been a while since i touched java...
Kcarpenter failed his java classes Or just walked by them without actually trying to understand it.
But I get that now. Thanks for the clarification. ctrl+shift+o has been my friend so far, but it was getting annoying.
Thanks for the answer.

Related

How to "run" Linux apps on WM6?

I have two Linux apps, Tuxcards & Kontacts, for which I am urgently looking for data compatible WM6 apps.
Any suggestions?
bump...bump....bump...
you can import and export .vcf-style vCards.
harddisk_wp said:
you can import and export .vcf-style vCards.
Click to expand...
Click to collapse
I realized that about Kontacts myself by now.
But what about the XML file format of Tuxcards?
pharao said:
I have two Linux apps, Tuxcards & Kontacts, for which I am urgently looking for data compatible WM6 apps.
Any suggestions?
Click to expand...
Click to collapse
Not sure what exactly you trying to do ... but I am a long time Linux desktop user. Synchronising my HD2 with Kontact (the contacts and appointments) over SynCE and OpenSync without problems.
Syncing is of no interest for me, as I never use that unreliable process anyway.
Never sure what gets overwritten where.
I have TONS of tech notes stored in my Tuxcards archive which I need for my work. So I'm desperately looking for an XML viewer for my SmartPhone that can handle/display the TuxCards archive.
I've read a TuxCards look-a-like tool called BasketNotes, but it also only exports in HTML format.
And that makes the entire Collapsible Tree functionality of Tuxcards go away.
Its a real pain in the rear trying to browse through hundreds of static web pages on a smart phone.
Anyone know of a way to easily import Tuxcard XML archives e.g. into Phatnotes?
bump...bump...bump
Sorry, but I'm still looking desperately for an XML Reader for WM6.
Anyone got any ideas here?
pharao said:
Sorry, but I'm still looking desperately for an XML Reader for WM6.
Anyone got any ideas here?
Click to expand...
Click to collapse
http://tinyurl.com/ycd2ye3
Edit:
I just tested the 1st one in the results, and it works fine. It's ugly, but it works. Spend some time with the rest of the results if you're not happy with the 1st one.
johncmolyneux said:
http://tinyurl.com/ycd2ye3
Edit:
I just tested the 1st one in the results, and it works fine. It's ugly, but it works. Spend some time with the rest of the results if you're not happy with the 1st one.
Click to expand...
Click to collapse
Hhhmm, I had googled my eyes out for an XML WM6 reader and couldn't find *anything* other than Porn Sites & Crack Torrents....
I'll try the Haali Reader for starters.
Thankz a lot...
I tried all of those your Google list came up with and none works.
The best I get is some notepad like prog which reads XML like a flat text file.
Not one of them even cares to interpret the inner structure of the XML data, so no chance of a snowball in hell to get a hierarchical notebook like layout of it :-(
Specially that Haali app was a big disappointment here.
And even apps like phatnotes only support plain text file imports and TuxCards doesn't export to plain text....(only to HTML)
pharao said:
I tried all of those your Google list came up with and none works.
The best I get is some notepad like prog which reads XML like a flat text file.
Not one of them even cares to interpret the inner structure of the XML data, so no chance of a snowball in hell to get a hierarchical notebook like layout of it :-(
Specially that Haali app was a big disappointment here.
And even apps like phatnotes only support plain text file imports and TuxCards doesn't export to plain text....(only to HTML)
Click to expand...
Click to collapse
Stupid question for you then - Why not export to HTML and use Opera?
Edit: Sorry, just realised I missed one of your earlier posts...
sub69 said:
Stupid question for you then - Why not export to HTML and use Opera?
Edit: Sorry, just realised I missed one of your earlier posts...
Click to expand...
Click to collapse
The question wouldn't be that stupid if not for the ABYSMALLY LOUSY quality of that HTML export
While TuxCards itself offers dynamic tree navigation, the exported HTML file is one big static dump, w/o proper font sizing and minimal (if any) graphic support.
In essence, its a pain in the rear to review, specially on a PocketPC device.
I think they just put it in there to have something listed under "Export" (just like the PhatNotes folks with their lousy Text Only import "feature").

[q] Question about R. Java

Is there anyway in Eclipse to have it update the R.java file without having to have a clean build. I am creating the XML files as I go, and am tired of having to comment out code just to have the file rebuild itself.
Also on my one project, the project can't seem to even get the R. Layout. Main to even be read. I noticed it when created the project, in the Main. Java file it had an error. Why does Eclipse have to be so confusing lol.
Thanks for help in advance
Sent from my HTC Desire CDMA using XDA App
You can try turning the automatic building of the application off, then building it when you're ready.
The only problems I ever have is when I go to run a program after a lot of xml changes and it puts a layout_name.out.xml. Then you delete it, close the project, open the project, and clean build.
There is also the saving the xml file to be able to use the view, whatever it may be in the source files.
Thanks for quick reply, what I would like is as soon as I save the XML files it updates the R. Java
Sent from my HTC Desire CDMA using XDA App
this is a problem with eclipse. search these boards for R.java and you will find many people complaining about how Eclipse messes with their project because of some issue with R.java. if you havent tried IntelliJ before you might try that. there are no issues using it with R.java
and the Community Android Edition is free.
So if I understand you correctly, you want to be able to create something in the xml, and have it create it in your class file, which will create it in your R.java file by itself?
If this is the case, I don't think it would work like this. Everything with an id created for you. I know some of my apps, I don't directly interact with some of the views, so I don't need them created. For example, I have a label like textview that stays the same. I don't want it created and throwing up the unused variable exclamation point, nor do I want to waste memory doing it. I think this was the simplest of options, instead of deleting everything you don't use, you just create what you do.
I don't know your level of programming knowledge, so I guess I'll just leave it at that. No disrespect intended, if I have somehow offended you.
j0hnZ said:
So if I understand you correctly, you want to be able to create something in the xml, and have it create it in your class file, which will create it in your R.java file by itself?
If this is the case, I don't think it would work like this. Everything with an id created for you. I know some of my apps, I don't directly interact with some of the views, so I don't need them created. For example, I have a label like textview that stays the same. I don't want it created and throwing up the unused variable exclamation point, nor do I want to waste memory doing it. I think this was the simplest of options, instead of deleting everything you don't use, you just create what you do.
I don't know your level of programming knowledge, so I guess I'll just leave it at that. No disrespect intended, if I have somehow offended you.
Click to expand...
Click to collapse
i believe he means that he has created something in xml with an @+id/something and then when he goes to use it in one of his activities/etc it throws an error because R.java has not been updated with the id of 'something'..
killersnowman said:
i believe he means that he has created something in xml with an @+id/something and then when he goes to use it in one of his activities/etc it throws an error because R.java has not been updated with the id of 'something'..
Click to expand...
Click to collapse
Weird, I've never had that problem.
killersnowman said:
i believe he means that he has created something in xml with an @+id/something and then when he goes to use it in one of his activities/etc it throws an error because R.java has not been updated with the id of 'something'..
Click to expand...
Click to collapse
Basically, it doesn't even recognize it basically. I guess I should just recreate the project and copy paste my stuff
Sent from my HTC Desire CDMA using XDA App

Explain extends Activity to me because

it seems like I can create an Activity thus:
Code:
public class MainActivity extends Activity
and then create other activities like this:
Code:
public class SplashActivity extends MainActivity
and the SplashActivity should inherit the "extend Activity".
Fine.
But what is the point in this? It seems that even if I extend a master java file I still don't get any of the other imports inherited, like os.Bundle.
If I could inherit all the imports from a master java file I'd understand extending the MainActivity.
Can anyone shed light on this?
extends has absolutely nothing to do with imports. It allows the subclass to inherit public and protected methods and variables of the superclass and also allows you to override the methods if you choose to.
To fully understand the concept behind this, i suggest read a java book.. xD But without going into a whole lot of confusing stuff ill give it a go...
The example you gave you are essentially saying SplashActivity is a grandchild of Activity. the Activity is unique to the android platform. here is a basic java example:
Class Car extends Vehicle or Class truck extends Vehicle.. extends does not just give you methods, you inherit methods that override previous ones. if you are looking for a quick way to import packages like "EditText" after typing that use: Cntl + Shift +O.
extends is a java term for inheritance. you can think about it like if you had a Fruit class with certain functionality, then you have an Apple class that extends Fruit. Apple gains all the functionality from Fruit but you can then add new functionality specific to an Apple class.
and if you think this is done for import reasons then you are thinking on a whole different level than the makers of java. try getting an ide that auto imports Classes as you use them in your code, like IntelliJ
Thanks for the information guys.
I knew extends would allow method inheritance, I just though it would also allow package import inheritance.
One of the hurdles I come up against in learning Android development is that even the Google tutorials don't tell you that you need to import different packages for different things - e.g. the Tabs tutorial doesn't explain that you need to import all sorts of stuff and the only way I got it working was that Eclipse is smart and will suggest solutions to your errors.
Thanks again.
Subjective Effect said:
Thanks for the information guys.
I knew extends would allow method inheritance, I just though it would also allow package import inheritance.
One of the hurdles I come up against in learning Android development is that even the Google tutorials don't tell you that you need to import different packages for different things - e.g. the Tabs tutorial doesn't explain that you need to import all sorts of stuff and the only way I got it working was that Eclipse is smart and will suggest solutions to your errors.
Thanks again.
Click to expand...
Click to collapse
The import statement in java is kind of misleading. It's not really importing anything. It just allow you to refer to a class in that java file by using it's short class name (Activity) instead of it's fully qualified name (android.app.Activity). You never really have to use an import statement in your code but if you don't you just wind up having to type the full package name in front every time you use a class name.
So say for instance you didn't have an
import android.app.Activity;
statement in your java file. In order to get the compiler to know what Activity you are talking about you would need to write android.app.Activity everywhere in your code instead of the much simpler way of importing it once and referring to it as Activity.
Hope that made sense.
Also, say for example you had another class in a different package with the same name...
com.example.Activity
If you wanted to use that class in the same java file that you are using android.app.Activity an import is not even going to help you. You would always need to use the fully qualitied name to refer to each Activity class because if you just say "Activity" the compiler don't know if you mean android.app.Activity or com.example.Activity.

Registering devices with GCM error

Hello everybody,
I'm experimenting with Google Cloud Messaging and I was following the tutorial at https :// github. com/ GoogleCloudPlatform/gradle-appengine-templates/blob/master/GcmEndpoints/README.md (I beg pardon but I can't post links). Unfortunately I spent the last two days struggling with solving all the dependencies but I still miss one.
In this code (taken from the tutorial at point 2.2) I cannot resolve the class "Registration"; I've been trying looking for it but given such a vague name I got back millions results that had little to do with my problem.
I also tried to add to my project all the suggested libraries but none of them contained the class I need.
Code:
public GcmRegistrationAsyncTask() {
Registration.Builder builder = new Registration.Builder(AndroidHttp.newCompatibleTransport(), new AndroidJsonFactory(), null)
// Need setRootUrl and setGoogleClientRequestInitializer only for local testing, otherwise they can be skipped
.setRootUrl("h t t p : / / 10.0.2.2:8080/_ah/api/")
.setGoogleClientRequestInitializer(new GoogleClientRequestInitializer() {
@Override
public void initialize(AbstractGoogleClientRequest<?> abstractGoogleClientRequest) throws IOException {
abstractGoogleClientRequest.setDisableGZipContent(true);
}
});
// end of optional local run code
regService = builder.build();
}
Could somebody point me in the right direction?
Thanks in advance for the help!
Bye
Mario
I was just following the same instructions today and I am experiencing the same problem unfortunately.
thvranken said:
I was just following the same instructions today and I am experiencing the same problem unfortunately.
Click to expand...
Click to collapse
Well, at least it means probably we are not dumb
At any rate if I should find something I'll post it here so it's available to whoever needs it and pls do the same...
Hmm.. I couldn't find a "Registration" class or import anywhere in their source code so it may be included in one of the dependencies, try checking your build.gradle files against the one given in their source code to check for the correct dependencies.
In any case, their method is (IMO) an extremely weird and complicated way of doing something very simple, if you haven't found the solution by Monday (when I should have more free time) I'll put together a package (including the html/php/MySQL server back-end files) with how I managed to do GCM messaging (which includes multicast messages)
Jonny said:
Hmm.. I couldn't find a "Registration" class or import anywhere in their source code so it may be included in one of the dependencies, try checking your build.gradle files against the one given in their source code to check for the correct dependencies.
In any case, their method is (IMO) an extremely weird and complicated way of doing something very simple, if you haven't found the solution by Monday (when I should have more free time) I'll put together a package (including the html/php/MySQL server back-end files) with how I managed to do GCM messaging (which includes multicast messages)
Click to expand...
Click to collapse
Hi Jonny, tnx for taking time and having a look! I checked the gradle file but it seemed everything in order...
At any rate I started studying better the code (I should have done it earlier actually) and noted that in the backend Android Studio created before a class with the methods I invoke in the app and before the declaration there is annotation:
Code:
@Api(name = "registration", version = "v1", namespace = @ApiNamespace(ownerDomain = "backend.rtalert.rt_finance.com", ownerName = "backend.rtalert.rt_finance.com", packagePath=""))
public class RegistrationEndpoint {
private static final Logger log = Logger.getLogger(RegistrationEndpoint.class.getName());
Now, searching on the web seems like I would somehow need to compile the backend module and import it as a lib into my app (despite is all within the same project). I imported both the zip file and the discovery one and then synced gradle, but still nothing.
Tomorrow after a few hours sleep I'll try again...
Good night
Mario
Ok apologies for being a bit late, life's been busier than I was expecting over the last few days...
Anyway, the web server files are all located in the following zip file >>> http://darkforest-roms.co.uk/Misc/AndroidGoogleColudMessaging.zip
There is also a table.txt file that contains the MySQL database base table I'm using - the setup is for an app for my school where the staff can send messages to individual year groups or to all year groups.
Assuming whatever webhosting service you are using has phpMyAdmin or similar you can just change the table columns in the table.txt file and import it. Then you need to go through register.php, update.php, possibly unregister.php and index.php to modify the website code to your specific application.
You will also need to edit the parameters in config.php for your Google API key and database name, user and password.
Thats it for the website side code, give me a couple of days to sort out the app-side java code, I need to modify some stuff in my current code before uploading it
Jonny said:
Ok apologies for being a bit late, life's been busier than I was expecting over the last few days...
Anyway, the web server files are all located in the following zip file >>> [
There is also a table.txt file that contains the MySQL database base table I'm using - the setup is for an app for my school where the staff can send messages to individual year groups or to all year groups.
Assuming whatever webhosting service you are using has phpMyAdmin or similar you can just change the table columns in the table.txt file and import it. Then you need to go through register.php, update.php, possibly unregister.php and index.php to modify the website code to your specific application.
You will also need to edit the parameters in config.php for your Google API key and database name, user and password.
Thats it for the website side code, give me a couple of days to sort out the app-side java code, I need to modify some stuff in my current code before uploading it
Click to expand...
Click to collapse
Hi Jonny, don't worry, I was quite busy these days myself, plus I really appeciate your help... In the weekend I'll set it up so I can test it and let you know...
Thanks again
Mario

[Q] Extract JSON data and display in ListView with Searchbox

Hi Everyone,
I am currently a very new starter in the Android App Development stage. I have tried to develop a ListView with Searchbox facility to search data that comes from a specific URL in the form of JSON data. I managed to understand displaying this data in ListView, but adding a search facility is something I'm struggling to grasp somehow.
The code attached is a reference code I am trying to tune before I move on to actually developing my app. However, it doesn't seem to work on the emulator, giving me the error that the MainActivity file has stopped working.
I am unsure if there is a fundamental error somewhere, and would be really grateful to get some advice on this. I have looked online and can't seem to find a good resource that explains merging ListView with JSON data effectively with a Searchbox.
ajitmenezes said:
Hi Everyone,
I am currently a very new starter in the Android App Development stage. I have tried to develop a ListView with Searchbox facility to search data that comes from a specific URL in the form of JSON data. I managed to understand displaying this data in ListView, but adding a search facility is something I'm struggling to grasp somehow.
The code attached is a reference code I am trying to tune before I move on to actually developing my app. However, it doesn't seem to work on the emulator, giving me the error that the MainActivity file has stopped working.
I am unsure if there is a fundamental error somewhere, and would be really grateful to get some advice on this. I have looked online and can't seem to find a good resource that explains merging ListView with JSON data effectively with a Searchbox.
Click to expand...
Click to collapse
You should implement the search on the listview adapter, not on the activity itself.
Take a look at the following article:
http://www.mokasocial.com/2010/07/arrayadapte-filtering-and-you/

Categories

Resources