I'm new to mobile development and Xamarin. I am trying to make an instance of a class which is found in another project under the same solution (HotDog and HotDogDataService). I get the red underline the using saying The type or namespace name 'RaysHotDogs' could not be found.
Why can't I instantiate these classes in this project? The classes are public.
One of your projects is not being build, judging by the error message provided - in one of your layout files, if you look at the xml you probably have invalid property, It's one one of the relative layouts as far as I can see.
Related
I'm working on a text-based game as a practice project.
I already managed to write an engine that displays information and handles user input. It draws the games content from custom Scene classes. More precisely, I have a Scene superclass and create child-classes, like EvilDungeon extends Scene, for the actual playable levels.
All scenes are located in a "Scenes"-folder, but I want to be able to make game expansions later on by dropping additional .class files of new scenes into said folder.
My plan was to use loadClass when the game is started to add them to a Scene-array, but it requires the class names which I can't know, since there can a any random combination of scenes in the Scenes-folder.
How can I load all scenes in the folder without knowing which scenes exactly are present? Can I retrieve the class name somehow?
My plan was to use loadClass when the game is started to add them to a Scene-array, but it requires the class names which I can't know, since there can a any random combination of scenes in the Scenes-folder.
That's what Service Provider Interfaces are for. Just define an interface for your plugins and use ServiceLoader to get an instance of each plug-in.
The plug-in needs to provide a text-file in /META-INF/services named after the interface and containing the class which implements that interface (both names must be fully qualified). You'll find the details in the documentation of ServiceLoader.
This gives you the ability to add plugins to the class-path. E.g. you can run your application using something like java -cp myapp.jar;plugins/* my.app.Main, then all the plugin-Jars in folder plugin will be added to the class-path and are available to your application (for more information on the asterisk, see this answer).
If you want to load plug-ins at runtime, you can use a URLClassLoader, e. g. read this question or this tutorial on how to use the URLClassLoader.
In an Android application, I notice that the package name of a class does not have to match the name that was generated when I created the new project. In other areas, Java is insistent that everything matches. I would like to understand why this is not the case for package names, and what the implications are.
Example: I create a new project named TextToSpeech, using my own reverse domain name. This gives a package name of com.lexogram.texttospeech; the path to the MainActivity.java class file is TextToSpeech/app/src/man/java/com.lexogram.texttospeech/.
I now go to a TextToSpeech tutorial and copy-and-paste the code into my project. This code uses com.example.texttospeech as the package name, both in the MainActivity class and in the AndroidManifest.xml. I run the project, and everything works fine.
Does this mean that each activity can use a different package name, so long as the name is used consistently across all files in the activity?
What it means is that your project can have multiple packages inside of it.
Java documentation explains them nicely:
To make types easier to find and use, to avoid naming conflicts, and
to control access, programmers bundle groups of related types into
packages.
Is it possible to make net beans scan for classes in namespaces which i haven't imported YET.
What I mean is, when I begin typing the name of a class, netbeans doesn't show it in its 'code prediction'. it only shows after I have imported the class's namespace.
I want it to show the class in the code prediction regardless of if I've imported the namespace or not
This isn't an issue with eclipse, can I make it work like eclipse?
Please go through this link.. I have followed this and I achieved what you are trying to get. https://netbeans.org/kb/docs/java/editor-codereference.html
Moreover, you can always customize your code completion settings to whatever behavior you need. It behaves almost similar to eclipse.
This is also a design question. I don't know the best way to design having many activities and how to break them up into packages while still accessing the apps resources.
I have an application which allows a user to login and access a tabbed activity which gives access to many modules. If they click a module they will load the module which will in turn contains a tabbed activity.
Currently i have 3 packages within this app:
com.appname.app (many activities i'd like to split up, login, module list etc)
com.appname.app.XML (xml handlers)
com.appname.app.Utils (static util classes etc)
I'd like to add a new package to contain all my modules so something like
com.appname.app.Modules ( or even a seperate package for EACH module)
But i can then no longer access the main apps resources without referring to them with a full package name such as setContentView(com.appname.app.R.layout.channel_list);
Obviously within any com.appname.app activities i just reference the resources such as layouts via setContentView(R.layout.channel_list);.
I'd have thought that a sub package (sub directory) should have access to a parent's resources without having to use com.appname.app.R.layout.channel_list instead of R.layout.channel_list. Which is why i'm assuming something is wrong with my design
The same issue goes for accessing string, drawable etc resources...
Im sure this is something very basic I'm missing. I've tried manually importing the "parent" package and that didn't work either.
is this how i should be doing things? or should i somehow be creating the resource files within each module package? or there another way i should be handling the design/split up of my app?
Since the Android pre-compiler would compile all references to a R.class file and place in in the main package there's no better way than to explicitly import the resources wherever you want to use them
import com.appname.app.R;
so that no full qualifier is needed.
I've developed several Android apps now and have created a code base of classes that I frequently use in more than one app. This code is all in a subversion (svn) repository with each app in its own repository. Each app then has svn:externals references for the needed packages (e.g., com.company.android.views). This works great except in the case when the R class has to be imported for custom attributes.
A custom view has an import like this:
import com.company.apps.myapp.R
so that it can have code like this:
attributes.getBoolean(R.styleable.WebImageView_autoload, autoload)
That custom attribute is defined in res/values/attrs.xml:
<declare-styleable name="WebImageView">
<attr name="autoload" format="boolean" />
...others
</declare-styleable>
This works perfectly, but the problem comes when I have a second app that uses this same view. Now I update the import to import com.company.apps.anotherapp.R so that it will work with "anotherapp" and that breaks it with "myapp." When working on several apps at once, this becomes an issue.
My temporary solution has been to check in an update to the applicable classes and then lock the svn:externals to that specific revision. Each app ends up being locked to a different revision, which gets messy fast, but that still seems better than copying the various classes into the app's repo directly.
The only other solution I've thought of it using reflection, something like:
Class class = Class.forName(context.getPackageName() + ".R");
Field[] fields = class.getDeclaredFields();
And then loop through the fields, assigning the ones I care about to variables that are used throughout the class. This seems rather heavy-handed though, especially when we could be talking about several classes needing to do this.
How can I solve this issue? Is there a way to dynamically import the com.company.apps.*.R or to somehow generate a different R class that doesn't depend on the specific app? Or is there some other obvious (or not so obvious) solution I've totally missed?
Took me a while, but I found a good answer: Library Projects.
Structurally, a library project is similar to a standard Android application project. For example, it includes a manifest file at the project root, as well as src/, res/ and similar directories. The project can contain the same types of source code and resources as a standard Android project, stored in the same way. For example, source code in the library project can access its own resources through its R class.