I'm trying the tutorial located here
I have compiled sample code for openCV without issues - so I'm sure I have all the necessary things installed for opencv. I've added the opencv library to my project and I'm compiling with java 1.6 (java 7 doesn't work with opencv4android right now AFAIK). I added the opencv library as a resource as well.
However, the sample code doesn't make sense to me once it gets to step 5 under Hello OpenCV example.
public void onCreate (Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mView = new HelloOpenCVView(this);
setContentView (mView);
}
Is the code I'm talking about, I immediately get the error "mView cannot be resolved to a variable". mview is consistently used without declaration throughout the code -- is it from another file I'm supposed to be importing? Any ideas? Thanks
B
The "m" in mView indicates that it is a member variable. It's a language naming convention used in most Android apps (you can read more about it here if you feel so inclined). So just add the following inside MyActivity:
public class MyActivity extends Activity implements HelperCallbackInterface
{
private HelloOpenCVView mView;
... // rest of class
}
That should resolve your mView cannot be resolved to a variable error, which is just a scoping issue.
On that page it says to refer to the 15-puzzle sample for more details. I suggest taking a look at it here.
I agree it is a little confusing. Since OpenCV is open source, feel free to send them a GitHub pull request with an amendment to this part of the documentation.
Related
I am facing a strange problem.
I have a solution that contains an Android project and a class library project.
If in that library project I execute this line:
String s = "Código inválido";
This is actually shown when watching the variable: Código inválido.
However, when I do that assignment inside the Activity code, the text is shown correctly as Código inválido.
What may be wrong with this?
The origin of the problem was when I tried to show, in the Activity layout, a text that was assigned in a class library method. After a lot of digging, I found what I expose in this question.
Just in case, I tell you that all files encodings are UTF-8, and in the project settings all encodings are also UTF-8.
This is Android Studio 4.0.1
Thanks
Jaime
So I was following this tutorial and got everything mostly working. But for some reason, the line that says initialize() is not being recognized by Android Studio.
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.part_camera_view);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
myContext = this;
initialize(); //This line is not recognized
}
I'm way too new to understanding what's going on, so I'm hoping to be nudged in the right direction. I can't find anything in Android documents that talk about initialize()
I've basically copy and pasted the script from the tutorial and changed the specific elements to fit my project. I am able to see a screen with the buttons provided, but I can not see the live view from the camera, and I believe that line is the problem
Any thoughts?
Initialize is a function. It isn't a prebuilt SDK function- if you want one, you have to write it yourself. If you don't need one, the call to it shouldn't be there.
As an aside, I have serious concerns about this code without even looking at the link to the tutorial- there's no reason to store this in a separate variable, and it makes me doubt the author understands his own code.
If you scroll down to the bottom of the tutorials page you will find a link where you can download the source code of the example project. You will find the initialize method in theAndroidCameraExample class.
I'm making a paid/free version of my app so have a 'Library Project' that the two apps use.
I'm trying to use Android Annotations to clean up my code:
http://code.google.com/p/androidannotations/
Unfortunately when I use this in my shared library project, one of my projects gets the error in Eclipse:
The type xActivity_ is already defined xActivity_.java /ProjectName/.apt_generated/lib/activities/
Because Android Annotations automatically creates a new activity with an extra '_' in the folder .apt_generated one of the apps is allowed to create this file, but the other gets the error "already defined".
Is there a way in Eclipse to resolve this? Or is it a problem with the Android Annotations?
This seems to be an AndroidAnnotations bug, and should be reported on the dedicated bug tracker.
AndroidAnnotations wasn't designed with this use case in mind, but this is still a very valid use case. The problem seems to be that the activity is generated in the shared library project, when it should be generated in each depending project, am I right ?
(please answer in the bug tracker)
This question is quite old, but I thought that I should mention android annotations now supports being used in libaries:
https://github.com/excilys/androidannotations/wiki/Library-projects
One caveat is that due to the way android library projects generate the R class, you cannot reference resouces directly inside the annotations. Eg, you cant do this:
#EActivity(R.layout.myLayout)
public class MyActivity extends Activity {
#Click(R.id.myButton1, R.id.myButton2})
public void someButtonClicked() {
}
}
Instead you must do this:
#EActivity(resName="myLayout")
public class MyActivity extends Activity {
#Click(resName={"myButton1", "myButton2"})
public void someButtonClicked() {
}
}
I just knew AndroidAnnotations (which seems a great tool!) but I think that if you do this using different projects (sharing the same library) your problem should be solved.
I've got a few projects Im trying to combine into one and Ive already included all the other projects as library ones through the settings. What Im sort of stuck on is how to use them in my main activity.
Ive messed around and feel like Ive almost got it but Im just stuck. I know I have to declare all the new activities in the main manifest but Im not sure about what to include in the main .java activity inorder to call from the newly included stuff.
Is this something that I could figure out by looking at the android api demos that come with the sdk?
Can some one point me to an open source project somewhere and explain the process used to include the library projects.
Any help would be much appreciated.
Are you using eclipse to manage your settings? It doesnt really matter, but its easier to make sure your library paths are set correctly and are accessible by the calling project.
Assuming that they are accessible, you just access the classes in the library like any other class: Import the package and instantiate the class as you would normally. For an android activity, this means that you would likely create an activity from the library based on some response from your main activity. It doesn't matter if that Activity is local to this project or imported from a library. eg:
// import the activity/package/class from your library
import com.mylibrary.activities.ImportedActivity;
public class LocalActivity extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
// Button Code
button = (ImageView) findViewById(R.id.button);
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// create a new intent based on your library activity
Intent myIntent = new Intent(v.getContext(), ImportedActivity.class);
startActivityForResult(myIntent, 0);
}
});
}
note, I have not tried to compile the code above, its just for purposes of demonstration.
If your libraries are correctly referenced in eclipse, this should work. If not you will get errors on either the import of the external libraries (package not found) or build errors when the actual library is needed.
I want to add an entire medical dictionary to my android phone (Moto Droid). I would like to be able to send text messages and have the medical words be in the predictable text.
I've been trying to write a small app that would accomplish this, but everything I try the app crashes on startup. I've never written an app for a mobile platform so that is a first for me. Here is what is not working properly.
public class WordAdd extends Activity {
/** Called when the activity is first created. */
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
UserDictionary.Words.addWord( this , "newMedicalWord", 1, UserDictionary.Words.LOCALE_TYPE_CURRENT);
}
}
It seems so simple to do, yet I am so stuck. Thanks for any help you can provide.
EDIT: I should mention that I am getting this error for Android 2.1 in the AVD (virtual device).
EDIT 2: User Dictionary is found in the Android API. addWord is a static method. I don't declare UserDictionary because I just use the one static method. It's been ages since I developed anything in Java and this is my first attempt at any mobile development, so I don't know if I am doing something wrong.
Add this to your app's AndroidManifest.xml file outside of the <application> element:
<uses-permission android:name="android.permission.WRITE_USER_DICTIONARY"></uses-permission>
Try setting a breakpoint at the start of your activity and stepping through the code with the debugger. This should help you isolate whether that call is really what is causing the crash, and what the underlying exception is.
mm mm where UserDictionary is defined? maybe you should just
UserDictionary = new UserDictionaryType();
UserDictionary.Words = new WordsType();
OR define in the class just under the class declaration the fallowing :
static UserDictionaryType UserDictionary;
if that's the case it's obvious why your app crashed ... (do it on kernel mode and "Houston we got a problem" you cant access pointer that you didnt allocated memory for even in java which is managed code... )
but again I am not familiar with your code show us where it defined and I would try to help you more ...
EDIT1: even if UserDictionary exists in the API you didn't declare on one...
you should declare somewhwere static UserDictionary ud = new UserDictionary();