Eclipse中,添加图书馆项目。我被困 [英] Eclipse, Add libraries in Project. I'm stuck

查看:274
本文介绍了Eclipse中,添加图书馆项目。我被困的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我卡的时候,我在Eclipse项目中添加库。我下面这个链接官方Android开发网站 http://developer.android.com/tool​​s/support -library / setup.html#库,具有清晰度以及我做的正是它说,但我得到一些reason.Here错误如何happends:

1.I下载支持SDK管理器库。结果
2.I进口它们与现有的Andr​​oid code到工作区,我在这两个.jar文件构建路径>添加到构建路径preSS。结果
3.然后在该项目(在步骤2中制造)我配置构建路径和我同时检查.jar文件,并取消了Android的依赖,我点击完成。一切都还好现在。结果
但在这里谈到的主要问题=>结果
4。我preSS对我的主项目(myfirstapp)属性,然后单击添加并选择我preSS后库应用和大量的错误的兴起一样的研究解决不了做变量的和我R.id从/根文件夹中突然dissapear

我现在添加一些屏幕拍摄,使之更好地为您。
对不起,我有张贴照片没有声誉。请复制以下

链接

我所有codeS:MainActivity.xml

 包com.example.myfirstapp;进口android.content.Intent;
进口android.os.Bundle;
进口android.support.v4.app.Fragment;
进口android.support.v7.app.ActionBarActivity;
进口android.view.LayoutInflater;
进口android.view.Menu;
进口android.view.MenuItem;
进口android.view.View;
进口android.view.ViewGroup;
进口android.widget.EditText;公共类MainActivity扩展ActionBarActivity {
     公共最后静态字符串EXTRA_MESSAGE =com.example.myfirstapp.MESSAGE;
    @覆盖
    保护无效的onCreate(捆绑savedInstanceState){
        super.onCreate(savedInstanceState);
        的setContentView(R.layout.activity_main);        如果(savedInstanceState == NULL){
            getSupportFragmentManager()调用BeginTransaction()
                    。新增(R.id.container,新PlaceholderFragment())
                    。承诺();
        }
    }
    公共无效的sendMessage(查看视图){
        意向意图=新意图(这一点,Displaymessageactivity.class);
        EDITTEXT的EditText =(EditText上)findViewById(R.id.edit_message);
        字符串消息= editText.getText()的toString()。
        intent.putExtra(EXTRA_MESSAGE,消息);
        startActivity(意向);
    }    @覆盖
    公共布尔onCreateOptionsMenu(菜单菜单){        //充气菜单;如果是present这增加了项目操作栏。
        。getMenuInflater()膨胀(R.menu.main,菜单);
        返回true;
    }    @覆盖
    公共布尔onOptionsItemSelected(菜单项项){
        //处理动作栏项目点击这里。操作栏会
        //自动处理上点击主页/向上按钮,只要
        //你在AndroidManifest.xml中指定一个父活动。
        INT ID = item.getItemId();
        如果(ID == R.id.action_settings){
            返回true;
        }
        返回super.onOptionsItemSelected(项目);
    }    / **
     *包含一个简单视图中的占位符片段。
     * /
    公共静态类PlaceholderFragment扩展片段{        公共PlaceholderFragment(){
        }        @覆盖
        公共查看onCreateView(LayoutInflater充气器,容器的ViewGroup,
                捆绑savedInstanceState){
            查看rootView = inflater.inflate(R.layout.fragment_main,集装箱,FALSE);
            返回rootView;
        }
    }}

fragment_main.xml

 < LinearLayout中的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    的xmlns:工具=htt​​p://schemas.android.com/tool​​s
    机器人:layout_width =match_parent
    机器人:layout_height =match_parent
    机器人:方向=横向>
    < EditText上机器人:ID =@ + ID / edit_message
        机器人:layout_weight =1
        机器人:layout_width =0dp
        机器人:layout_height =WRAP_CONTENT
        机器人:提示=@字符串/ edit_message/>
    <按钮
        机器人:layout_width =WRAP_CONTENT
        机器人:layout_height =WRAP_CONTENT
        机器人:文字=@字符串/ button_send
        安卓的onClick =的sendMessage/>
< / LinearLayout中>

的strings.xml

 <?XML版本=1.0编码=UTF-8&GT?;
<资源>    <字符串名称=APP_NAME> myfirstapp< /串>
    <字符串名称=action_settings>设置< /串>
    <字符串名称=edit_message>输入消息< /串>
    <字符串名称=button_send>发送和LT; /串>
    <字符串名称=title_activity_displaymessageactivity> Displaymessageactivity< /串>
    <字符串名称=参考hello world>世界,你好<!/串>< /资源>

Displaymessageactivity.xml

 包com.example.myfirstapp;进口android.content.Intent;
进口android.os.Bundle;
进口android.support.v4.app.Fragment;
进口android.support.v7.app.ActionBarActivity;
进口android.view.LayoutInflater;
进口android.view.Menu;
进口android.view.MenuItem;
进口android.view.View;
进口android.view.ViewGroup;
进口android.widget.TextView;公共类Displaymessageactivity扩展ActionBarActivity {    @覆盖        公共无效的onCreate(捆绑savedInstanceState){
            super.onCreate(savedInstanceState);            //从意图消息
            意向意图= getIntent();
            字符串消息= intent.getStringExtra(MainActivity.EXTRA_MESSAGE);            //创建文本视图
            TextView中的TextView =新的TextView(本);
            textView.setTextSize(40);
            textView.setText(消息);            //设置文本视图作为活动布局
            的setContentView(TextView的);
        }    @覆盖
    公共布尔onCreateOptionsMenu(菜单菜单){        //充气菜单;如果是present这增加了项目操作栏。
        。getMenuInflater()膨胀(R.menu.displaymessageactivity,菜单);
        返回true;
    }    @覆盖
    公共布尔onOptionsItemSelected(菜单项项){
        //处理动作栏项目点击这里。操作栏会
        //自动处理上点击主页/向上按钮,只要
        //你在AndroidManifest.xml中指定一个父活动。
        INT ID = item.getItemId();
        如果(ID == R.id.action_settings){
            返回true;
        }
        返回super.onOptionsItemSelected(项目);
    }    / **
     *包含一个简单视图中的占位符片段。
     * /
    公共静态类PlaceholderFragment扩展片段{        公共PlaceholderFragment(){
        }        @覆盖
        公共查看onCreateView(LayoutInflater充气器,容器的ViewGroup,
                捆绑savedInstanceState){
            查看rootView = inflater.inflate(
                    R.layout.fragment_displaymessageactivity,集装箱,FALSE);
            返回rootView;
        }
    }}

fragment_displaymessageactivity.xml

 <的RelativeLayout的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    的xmlns:工具=htt​​p://schemas.android.com/tool​​s
    机器人:layout_width =match_parent
    机器人:layout_height =match_parent
    机器人:paddingBottom会=@扪/ activity_vertical_margin
    机器人:paddingLeft =@扪/ activity_horizo​​ntal_margin
    机器人:paddingRight =@扪/ activity_horizo​​ntal_margin
    机器人:paddingTop =@扪/ activity_vertical_margin
    工具:上下文=$ com.example.myfirstapp.Displaymessageactivity PlaceholderFragment>    <的TextView
        机器人:layout_width =WRAP_CONTENT
        机器人:layout_height =WRAP_CONTENT
        机器人:文字=@字符串/参考hello world/>< / RelativeLayout的>

事情到目前为止,我曾尝试:
1.重新安装Eclipse和Java结果
2.从SDK管理器中搜索重新下载库
3.清洁工程。结果
4.我所有的XML文件开头小写(但MainActivity.xml和Displaymessageactivity.xml必须以大写字母开头)

我尽力,我在这里永远困。我很frustated从谷歌:/结果
每一个帮助非常AP preciated,欢迎!


解决方案

  

库添加到您的应用程序项目:


  
  

      
  1. 在Project Explorer中,右键单击您的项目并选择属性。

  2.   
  3. 在该对话框左侧的类别面板中,选择Android系统。

  4.   
  5. 在库窗格中,单击添加按钮。

  6.   

在步骤3中,注意到在库窗格中,您应该看到appcompat_v7已被​​添加(当您创建项目后续MyFirstApp指示它的自动添加,因为您已经选择的minSdkVersion = 8,而不是11)(您第二图像)。

于是删除所有在库窗格中添加的库添加的库之前,(所以在你的第三图像,它只有Android的支持-V7-应用程序兼容性图书馆窗格中),那么R.java不会消失。

I'm stuck when Add libraries in my project in Eclipse. I am following this link official android development website http://developer.android.com/tools/support-library/setup.html#libs-with-res and I do exactly what it says but I get errors for some reason.Here how it happends:

1.I download support libraries from SDK Manager.
2.I import them with existing Android Code into workspace and I press on the both .jar files Build Path>Add to Build Path.
3. Then on that project (made in step 2) I configure Build Path and I check both .jar files and uncheck the Android Dependencies and I click finish. Everything is okay for now.
But here comes the main problem=>
4. I press on my main project (myfirstapp) properties and click Add and select the libraries after that I press Apply and lots of errors raise up like R cannot be resolved to do variable and my R.id from /gen folder suddenly dissapear

I add now some screen shoots to make it better for you. Sorry I have no reputations for posting images. Please copy links below

All my Codes: MainActivity.xml

package com.example.myfirstapp;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.app.ActionBarActivity;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;

public class MainActivity extends ActionBarActivity {
     public final static String EXTRA_MESSAGE = "com.example.myfirstapp.MESSAGE";
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        if (savedInstanceState == null) {
            getSupportFragmentManager().beginTransaction()
                    .add(R.id.container, new PlaceholderFragment())
                    .commit();
        }
    }
    public void sendMessage(View view) {
        Intent intent = new Intent(this, Displaymessageactivity.class);
        EditText editText = (EditText) findViewById(R.id.edit_message);
        String message = editText.getText().toString();
        intent.putExtra(EXTRA_MESSAGE, message);
        startActivity(intent);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {

        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();
        if (id == R.id.action_settings) {
            return true;
        }
        return super.onOptionsItemSelected(item);
    }

    /**
     * A placeholder fragment containing a simple view.
     */
    public static class PlaceholderFragment extends Fragment {

        public PlaceholderFragment() {
        }

        @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container,
                Bundle savedInstanceState) {
            View rootView = inflater.inflate(R.layout.fragment_main, container, false);
            return rootView;
        }
    }

}

fragment_main.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal">
    <EditText android:id="@+id/edit_message"
        android:layout_weight="1"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:hint="@string/edit_message" />
    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/button_send"
        android:onClick="sendMessage" />
</LinearLayout>  

strings.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>

    <string name="app_name">myfirstapp</string>
    <string name="action_settings">Settings</string>
    <string name="edit_message">Enter a message</string>
    <string name="button_send">Send</string>
    <string name="title_activity_displaymessageactivity">Displaymessageactivity</string>
    <string name="hello_world">Hello world!</string>

</resources>  

Displaymessageactivity.xml

package com.example.myfirstapp;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.app.ActionBarActivity;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

public class Displaymessageactivity extends ActionBarActivity {

    @Override

        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);

            // Get the message from the intent
            Intent intent = getIntent();
            String message = intent.getStringExtra(MainActivity.EXTRA_MESSAGE);

            // Create the text view
            TextView textView = new TextView(this);
            textView.setTextSize(40);
            textView.setText(message);

            // Set the text view as the activity layout
            setContentView(textView);
        }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {

        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.displaymessageactivity, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();
        if (id == R.id.action_settings) {
            return true;
        }
        return super.onOptionsItemSelected(item);
    }

    /**
     * A placeholder fragment containing a simple view.
     */
    public static class PlaceholderFragment extends Fragment {

        public PlaceholderFragment() {
        }

        @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container,
                Bundle savedInstanceState) {
            View rootView = inflater.inflate(
                    R.layout.fragment_displaymessageactivity, container, false);
            return rootView;
        }
    }

}  

fragment_displaymessageactivity.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.example.myfirstapp.Displaymessageactivity$PlaceholderFragment" >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/hello_world" />

</RelativeLayout>

Things I have tried so far: 1. Reinstall Eclipse and Java
2. Redownload libraries from SDK Manager
3. Clean the Project.
4. Make all my xml files starting with lowercase (but the MainActivity.xml and Displaymessageactivity.xml must start with uppercase)

I tried my best and I am stuck here forever. I am very frustated from Google :/
Every help is very appreciated and welcome!

解决方案

Add the library to your application project:

  1. In the Project Explorer, right-click your project and select Properties.
  2. In the category panel on the left side of the dialog, select Android.
  3. In the Library pane, click the Add button.

In step 3, notice that in the Library pane, you should see that the appcompat_v7 already be added (it's added automatically when you create your project follow MyFirstApp instruction, because you have already chosen minSdkVersion=8, not 11) (your second image).

So remove all the added libraries in the Library pane before adding your library (so in your third image it only has android-support-v7-appcompat in Library Pane), then the R.java will not disappear.

这篇关于Eclipse中,添加图书馆项目。我被困的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆