Why does couldn't find import for class appear in the aidl file compiled by Eclipse?

Source: Internet
Author: User

Aidl is being studied recently and the following error occurs: couldn't find import for class cannot import class!

 

IMyService. aidl

Project directory:

Student. java

Private int age; <br/> private String name; <br/> public int getAge () {<br/> return age; <br/>}< br/> public void setAge (int age) {<br/> this. age = age; <br/>}< br/> public String getName () {<br/> return name; <br/>}< br/> public void setName (String name) {<br/> this. name = name; <br/>}< br/> // public static final Parcelable. creator <Student> CREATOR = new Creator <Student> () {<br/> // @ Override <br/> // public Student [] newArray (int size) {<br/> /// TODO Auto-generated method stub <br/> // return new Student [size]; <br/> //} <br/> // @ Override <br/> // public Student createFromParcel (Parcel source) {<br/> /// TODO Auto-generated method stub <br/> // return new Student (source ); <br/> //}; <br/> public Student () {<br/>}< br/> public Student (Parcel pl) {<br/> age = pl. readInt (); <br/> name = pl. readString (); <br/>}</p> <p> public int describeContents () {<br/> // TODO Auto-generated method stub <br/> return 0; <br/>}</p> <p> public void writeToParcel (Parcel dest, int flags) {<br/> // TODO Auto-generated method stub <br/> dest. writeInt (age); <br/> dest. writeString (name); <br/>} 

Later, I checked it online. The problem has finally been solved. Thanks to this eldest brother! Http://blog.csdn.net/jackyu613/archive/2010/11/16/6011564.aspx

The specific solution is as follows:

 

Refer to the Section in Chapter 8th of the complete handout on Android/OPhone development:
"The AIDL service only supports a limited number of data types. Therefore, if you use the AIDL service to transmit some complex data, you need to perform further processing. The AIDL Service supports the following data types:

Java simple type (int, char, boolean, etc ). Import is not required ).

String and CharSequence. Import is not required ).

List and Map. Note that the element types of List and Map objects must be data types supported by AIDL. Import is not required ).

The API automatically generated by AIDL. Import is required ).

Class that implements the android. OS. Parcelable interface. Import is required ).

The next two data types need to be imported using import, which will be detailed later in this chapter.

The method for passing data types that do not require import is the same. The procedure for passing a value of the data type to be imported (for example, a class implementing the android. OS. Parcelable Interface) is slightly complicated. In addition to creating a class that implements the android. OS. Parcelable interface, you also need to create an aidl file for this class and define it using the parcelable keyword ."

In fact, we only need to create the Student. aidl file to define the Student class. The Code is as follows:

/* // Device/java/android/content/Intent. aidl <br/> ** Copyright 2007, The Android Open Source Project <br/> ** Licensed under the Apache License, version 2.0 (the "License"); <br/> ** you may not use this file except T in compliance with the License. <br/> ** You may obtain a copy of the License at <br/> ** http://www.apache.org/licenses/LICENSE-2.0 <br/> ** unless required by applicable law or agreed to in writing, software <br/> ** distributed under the License is distributed on an "as is" BASIS, <br/> ** without warranties or conditions of any kind, either express or implied. <br/> ** See the License for the specific language governing permissions and <br/> ** limitations under the License. <br/> */<br/> package com. android. aidl; <br/> parcelable Student; 

Note that parcelable must be in lower case. The directory structure is as follows:

 

In addition, there is a "method" on the Internet, that is, adding LOCAL_AIDL_INCLUDES :=$ (FRAMEWORKS_BASE_JAVA_SRC_DIRS) in frameworks/base/Android. mk with LOCAL_AIDL_INCLUDES := the location of the class to be imported. In fact, this "method" is also restricted by the import rules mentioned above. A class that does not implement the Parcelable interface is powerless.


 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.