我的目标是复制NotePad示例项目,这样如果我修改源文件以便通过实验学习,原始示例文件将不受到影响。 @Neutrino在this post的子弹1-2-3中很好地解释了这个目标背后的理性。
根据@ Neutrino的帖子,我执行了以下步骤:
步骤1:将示例代码复制到临时位置(工作区目录之外):
1. Close Eclipse.
2. Copy the entire sample folder
**NotePad** from C:\android-sdk-windows\samples\android-7
to C:\Users\androideve\Documents\NotePad
步骤2.从副本导入到工作区:
1. Start Eclipse
2. File > New > Project > Android Project [Next]
> Create project from existing **source**: C:\Users\androideve\Documents\NotePad
3. Delete project from Package Explorer (without deleting its files from disk!)
4. File > Import...
> General > Existing Projects into Workspace [Next]
> Browse: C:\Users\androideve\Documents\NotePad
> Check "Copy projects into workspace" [Finish]
5. Delete entire folder C:\Users\androideve\Documents\NotePad from disk.
这会导致项目创建,但它会带来21个错误,而不知道导致它们的原因(请记住,我是Android新手而且我没有编写NotePad程序):
Description Resource Path Location Type
Error generating final archive: java.io.FileNotFoundException: C:\sb\workspace\NotesList\bin\resources.ap_ does not exist NotesList Unknown Android Packaging Problem
error: Error: String types not allowed (at 'layout_height' with value 'match_parent'). note_editor.xml /NotesList/res/layout line 17 Android AAPT Problem
error: Error: String types not allowed (at 'layout_width' with value 'match_parent'). note_editor.xml /NotesList/res/layout line 17 Android AAPT Problem
error: Error: String types not allowed (at 'layout_width' with value 'match_parent'). noteslist_item.xml /NotesList/res/layout line 17 Android AAPT Problem
R cannot be resolved to a variable NoteEditor.java /NotesList/src/com/example/android/notepad line 148 Java Problem
R cannot be resolved to a variable NoteEditor.java /NotesList/src/com/example/android/notepad line 151 Java Problem
R cannot be resolved to a variable NoteEditor.java /NotesList/src/com/example/android/notepad line 175 Java Problem
R cannot be resolved to a variable NoteEditor.java /NotesList/src/com/example/android/notepad line 177 Java Problem
R cannot be resolved to a variable NoteEditor.java /NotesList/src/com/example/android/notepad line 194 Java Problem
R cannot be resolved to a variable NoteEditor.java /NotesList/src/com/example/android/notepad line 195 Java Problem
R cannot be resolved to a variable NoteEditor.java /NotesList/src/com/example/android/notepad line 265 Java Problem
R cannot be resolved to a variable NoteEditor.java /NotesList/src/com/example/android/notepad line 269 Java Problem
R cannot be resolved to a variable NoteEditor.java /NotesList/src/com/example/android/notepad line 276 Java Problem
R cannot be resolved to a variable NotesList.java /NotesList/src/com/example/android/notepad line 83 Java Problem
R cannot be resolved to a variable NotesList.java /NotesList/src/com/example/android/notepad line 94 Java Problem
R cannot be resolved to a variable NotesList.java /NotesList/src/com/example/android/notepad line 177 Java Problem
R cannot be resolved to a variable NotesLiveFolder.java /NotesList/src/com/example/android/notepad line 48 Java Problem
R cannot be resolved to a variable NotesLiveFolder.java /NotesList/src/com/example/android/notepad line 51 Java Problem
R cannot be resolved to a variable TitleEditor.java /NotesList/src/com/example/android/notepad line 71 Java Problem
R cannot be resolved to a variable TitleEditor.java /NotesList/src/com/example/android/notepad line 80 Java Problem
R cannot be resolved to a variable TitleEditor.java /NotesList/src/com/example/android/notepad line 83 Java Problem
我做错了什么,我需要做什么才能使这个NotePad示例构建并运行复制?
答案 0 :(得分:11)
好的,我想我到了那里(请注意原始步骤与以下步骤之间的细微差别):
步骤1:将示例代码复制到临时位置(工作区目录之外):
1. Close Eclipse.
2. Copy the entire sample folder
**NotePad** from C:\android-sdk-windows\samples\android-8
to C:\Users\androideve\Documents\NotePad
步骤2.从副本导入到工作区:
1. Start Eclipse
2. File > New > Project > Android Project [Next]
> Create project from existing **source**: C:\Users\androideve\Documents\NotePad
> Build Target: **Uncheck** Android 1.5. **Check** Android 2.2. [Finish]
3. Delete project from Package Explorer (without deleting its files from disk!)
4. File > Import...
> General > Existing Projects into Workspace [Next]
> Browse: C:\Users\androideve\Documents\NotePad
> Check "Copy projects into workspace" [Finish]
5. Delete entire folder C:\Users\androideve\Documents\NotePad from disk.
现在,项目是像以前一样创建的,而不是21个错误,我只有1个警告:
Description Resource Path Location Type
Attribute minSdkVersion (3) is lower than the project target API level (8) AndroidManifest.xml /NotesList line 1 Android ADT Problem
我在控制台上也有两条红色消息:
[2011-02-10 12:45:50 - com.android.ide.eclipse.adt.internal.project.AndroidManifestHelper] Unable to read C:\android-sdk-windows\AndroidManifest.xml: java.io.FileNotFoundException: C:\android-sdk-windows\AndroidManifest.xml (The system cannot find the file specified)
[2011-02-10 12:45:50 - com.android.ide.eclipse.adt.internal.project.AndroidManifestHelper] Unable to read C:\android-sdk-windows\AndroidManifest.xml: java.io.FileNotFoundException: C:\android-sdk-windows\AndroidManifest.xml (The system cannot find the file specified)
确实如此:C:\ android-sdk-windows中没有AndroidManifest.xml,但NoteList目录中有一个。为什么抱怨这个?为什么它在C:\ android-sdk-windows中查找?
无论如何,在创建启动配置之后,复制的逐字样本项目继续在模拟器上运行而没有任何问题(现在我终于可以继续学习它的编程方面了。)
总之,问题的根源是我使用的是Android 7样本(而不是Android 8),并且我继续使用构建目标1.5(而不是2.2)。
一切都很顺利。 :)
答案 1 :(得分:2)
尝试确保您的导入语句正确无误:
R cannot be resolved - Android error
另外,为什么你认为它正在考虑C:\sb\workspace\NotesList\bin\resources.ap_
?这不是你的项目存储的地方,是吗?
我可能会建议尝试这样做:
File > Import
并选择Existing Projects into Workspace
选项Select root directory
并浏览到Samples文件夹,直至找到NodePad根目录Open
或任何相关的“确定”选项Copy projects into workspace
Finish
这应该导入一个很好的API演示版本的碳复制品,以便修改目录树中的原始资源
答案 2 :(得分:2)
右键单击Eclipse项目,选择属性,转到Android并确保选择了正确的SDK。
答案 3 :(得分:1)
更简单的解决方案:
就是这样,项目和代码现在重复并在您的工作区中工作。