imported classes not working - android

I'm doing a calculator tutorial online, and there is two separate classes that need to be imported into the main class
I put the two classes in a new package in the scr folder and tried importing them into main class like so
import com.example.brkyclasses.Alertwindow;
import com.example.brkyclasses.Calculator2;
Eclipse is still asking me to create methods when the methods are in the two classes is there something else i need to do, do i need to add these two classes to manifest or something else

Those are package specific imports. You need to look in your manifest xml and see what your package name is under the package tag (should be like 3rd line). And then you will probably create some file called Alertwindow and Calculator2 and so you will import your own classes. using the package.name.Alertwindow format.

You need to add either the source code for those classes, or the .jar file that those classes are implemented in, to your project. If you included the .jar, you need to edit your project settings and specify the location of the .jar

Related

Is there anyway to put multiple activities in a folder in android studio?

I have multiple activities. For organization purposes I want to to put them in folders without affecting the project. How can this be done?
Just create a new folder.
In fact, you can organize your project and separate the class as you want. This way, you keep your project organized and you can hide some methods and let them to be used only for classes in same package, for example.
I use do:
...\app\src\main\java\com\example\myapp\activities
...\app\src\main\java\com\example\myapp\service
...\app\src\main\java\com\example\myapp\dataprovider
...\app\src\main\java\com\example\myapp\adapters
So, your activities classes would start with:
package com.example.myapp.activities;
And your services would start with:
package com.example.myapp.service;
Also, you may need to adjust your imports:
import com.example.myapp.dataprovider.Class1;
import com.example.myapp.dataprovider.Class2;
However, this should be done automatically by Android Studio.
Just remember that doing that, you are creating a different packages. This way, you have to take a special attention with method accessbility (private, protected, public)
However, since we usually use private and public modifiers, we should not have any problem.

Library class as return type for methods in aidl interface

In IPC to interpret data received the process should be knowing the Class structure. So i made a Library of all required classes which are all implementing Parcelable.
In library i have defined aidl files for all calsses and ensured that these file are present in JAR.
In application, i have created same aidl file and place in the same package name as in library.
In aidl file which contains method definitions no error is shown but in code section of Stub() i get that the Library class as return could not be found.
if i create the same library object inside the method it shows valid object, but something with it as return type.
so, i moved one of the class from library to application there is problem with this class.
What have i missed so that library classes are not recognized as return type.
Note: i edited the compiler created class file for aidl in gen folder and added import to my library, error is solved but i cant save it, compiler will overwrite it.
what a shame... Package name of classes in my library had first letter as capital while i messed it by creating package structure in my application with small letter...
Wont delete the Question. someone else might also do same mistake

new to android not sure what import info.androidhive.imageslider.R; means

I have been working through this tutorial and came across this code:
import info.androidhive.imageslider.R;
This is important because when i copy these files from this tutorial into a new project - it gives me an error on this line of code.
can you give me a detailed explanation on what it means?
This is the import of your resource library. Resource means where your app store its drawable, layout etc. In most cases, it is under the packages name like:
if your package name is: info.androidhive.imageslider
then, your resource package name will be info.androidhive.imageslider.R
When you open a new android project, your must notice that there is a gen folder where there is a R.java file. This import actually import that file to the class where you may use some resource.
As you copied the code from other places, I think you have changed your project package name and so for that, now the app can't match it with current package for R file. Please, check it and change it according to it.
Hope it may help you.
You got this explained in the tutorial (btw: it's good to read tutorial, not just copy files from it):
I kept my package name as info.androidhive.imageslider
You must have proper import here. If you are using Eclipse, best solution would be to press CTRL+Shift+o.

Android multiple packages in one project, what is R and how to import it?

I have a launcher for people with bad eyesight and a simple music player, this is my second APP so bear in mind I'm a complete noob in android and eclipse.
I tried to merge both my launcher and music player. I added the activity to the manifiest with a different intent, copied layouts and drawables to the launcher project and I added the player's package inside my /src folder.
Afterwards on the first lines of com.easyplayer.java I got this error:
import com.easyplayer.R; // the import com.easyplayer.R cannot be resolved
This is the only bug I'm getting so I suppose I did everything else fine. I imagine R must reference the player's layout, but I'm not sure how to fix it (cleaning/rebuilding doesn't work). What is the R class? And what can I do to fix this?
The R class you see is auto-generated by Android. It is a utility class that contains references to all the resources in your project. There is a few answers detailing its contents here.
You mentioned you performed a clean of your project, but you need to do a full build as well to regenerate this file.
edit: The import of the new code may have somehow invalidated your xml files. Check to see if there are any errors there, which could be preventing the R file from being re-created during a build.
if you have several packages like, com.example.app.package1 and com.example.app.package2, then import the R.java file like,
import com.example.app.R;
And if you already have import android.R; then please delete that and save the file and clean the project, problem will be solve...:)

generate blank aidl file

This may sound stupid but for some reason I can't find anywhere on Eclipse that lets me generate blank .aidl files... Does anyone know how?
You could make a copy form this:
http://developer.android.com/guide/developing/tools/aidl.html
and than use something liek th ecode2code eclips eplugin to generate code from the template you have created..
There is no option (yet, I guess) to create a aidl file. You should just create a file (right click on the package -> new file ) and give it name with .aidl extension. Then in this file you should just add several lines:
The name of the package, for instance package com.test;
And just declare interface IYourName { }
So as you can do only several things with android interface, there is no need to make a separate template for this.

Categories

Resources