R.java不会产生

时间:2014-03-25 09:55:04

标签: java android eclipse

我目前正在开发一个项目,我将ListView的适配器从ArrayAdapter更新为Custom CursorAdapter。

我有意删除了R.java,在将新的R.java插入<string></string>文件后重新生成res/string.xml文件,因为它没有自动重新生成。该文件未生成。

我继续调试,并运行Project->Clean...以尝试重新生成R.java文件。这也不起作用。

在检查StackOverflow之后,我还尝试更改AndroidManifest.xml中的版本,希望重新生成该文件。这也行不通。我已经尝试了一些其他的黑客,希望Eclipse可以重新生成文件。没有运气。

有没有人有任何想法?我的时间紧迫,这真的让我退缩了。

以下是问题出现时我正在处理的文件:

package com.renaissanceartsmedia.gradingapp.controllers.fragments;

import java.util.ArrayList;

import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.os.Bundle;
import android.support.v4.app.ListFragment;
import android.support.v4.util.ArrayMap;
import android.support.v4.widget.CursorAdapter;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;
import android.widget.TextView;

import com.renaissanceartsmedia.gradingapp.R;
import com.renaissanceartsmedia.gradingapp.controllers.activities.CourseActivity;
import com.renaissanceartsmedia.gradingapp.model.Course;
import com.renaissanceartsmedia.gradingapp.model.CourseStore;
import com.renaissanceartsmedia.gradingapp.model.GradingAppDatabaseHelper.CourseCursor;

public class CourseListFragment extends ListFragment {

    // DEBUG
    private static final String TAG = "CourseListFragment";

    // Create an ArrayList<String> to store flashcards
    ArrayList<Course> mCourses;
    ArrayMap<Long, Course> mCoursesById;

    // Cursor Object
    private CourseCursor mCursor;

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

        // Set the Title of the Fragment's Activity
        getActivity().setTitle(R.string.course_list);

        // Load Cursor to DB
        mCursor = CourseStore.get(getActivity()).queryCourses();

        // Set the list of FlashcardListFragments
        mCourses = CourseStore.get(getActivity()).getCourses();
        mCoursesById  = CourseStore.get(getActivity()).getCoursesById();

        // Create an ArrayAdapter to use for displaying FlashcardListFragments in FlashcardListActivity
        /*
        ArrayAdapter<Flashcard> adapter = new ArrayAdapter<Flashcard>(
                                                                    getActivity(),
                                                                    android.R.layout.simple_list_item_1,
                                                                    mFlashcards);
        */

        // OLD METHOD
        //ListItemLayoutAdapter adapter = new ListItemLayoutAdapter(mCourses);
        CourseCursorAdapter adapter = new CourseCursorAdapter(getActivity(), mCursor);

        // Set the adapter for the list
        setListAdapter(adapter);
    }


    /* Handles a user selection of a FlashcardListFragment
     * 
     */
    @Override
    public void onListItemClick(ListView l, View v, int position, long id) {
        //Flashcard f = (Flashcard)(getListAdapter()).getItem(position);
        // OLD WAY
        //Course c = ((ListItemLayoutAdapter)getListAdapter()).getItem(position);

        /*
        Course c = ((CourseCursorAdapter))getListAdapter());
        Log.d(TAG, c.getCourseTitle() + " was clicked");


        // Start a new activity using an Intent
        Intent openFlashcardDetail = new Intent(getActivity(), CourseActivity.class);

        // Add EXTRAS to the intent
        //openFlashcardDetail.putExtra(FlashcardFragment.EXTRA_FLASHCARD_ID, f.getId());
        openFlashcardDetail.putExtra(Course.EXTRA_COURSE_ID, c.getId());

        startActivity(openFlashcardDetail);
        */

    }

    // OLD METHOD
    //class ListItemLayoutAdapter extends ArrayAdapter<Course> {
    class CourseCursorAdapter extends CursorAdapter {

        // Member Properties
        // OLD METHOD
        Course mCurrentListObject;
        CourseCursor mCourseCursor;

        // Constructor
        // OLD METHOD
        /*
        public ListItemLayoutAdapter(ArrayList<Course> itemContent) {
            super(getActivity(), 0, itemContent);

        }
        */

        public CourseCursorAdapter(Context context, CourseCursor cursor) {
            super(context, cursor, 0);
            mCourseCursor = cursor;
        }
        // OLD WAY
        /*
        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            //If we weren't given a view, inflate a new view
            if (convertView == null) {
                convertView = getActivity().getLayoutInflater()
                        .inflate(R.layout.list_item_layout, null);
            }

            // Configure the view for this object
            mCurrentListObject = getItem(position);

            // Make Connections from Layout to Java code
            TextView mainTextView = (TextView) convertView.findViewById(R.id.item_main_text);
            TextView subTextView = (TextView) convertView.findViewById(R.id.item_sub_text);

            // Set the Contents of the Views
            mainTextView.setText(setMainText());
            subTextView.setText(setSubText());

            return convertView;
        }
        */

        @Override 
        public View newView(Context context, Cursor cursor, ViewGroup parent) {
            // Use a layout Inflater to get a row view
            LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            return inflater.inflate(android.R.layout.simple_list_item_1, parent, false);
        }

        @Override
        public void bindView(View view, Context context, Cursor cursor) {

            // Get the course for the current row
            Course course = mCourseCursor.getCourse();

            // Setup a new TextView
            TextView courseTitleTextView = (TextView)view;
            String mainText = context.getString(R.string.course_title_hint, course.getCourseTitle());
            courseTitleTextView.setText(mainText);


        }



        public String setMainText() {
            return mCurrentListObject.getCourseTitle();
        }
        public String setSubText() {
            return mCurrentListObject.getSubject();
        }

    }
}

4 个答案:

答案 0 :(得分:1)

我有解决方案,希望这会对你有所帮助。 !!

步骤1)更改构建目标

例如,如果您选择2.2作为构建目标,则选择您拥有的最大值。 (如4.4)

如果您选择4.4,则选择4.3作为目标。

Build Target

步骤2)清理项目

Clean Project

它将再次创建R.java

谢谢。

答案 1 :(得分:0)

这通常是因为您的XML或资源文件名中存在某个问题。 尝试重新启动Eclipse,如果它仍然没有指出问题所在,请尝试在发生此问题之前将您对XML文件所做的最后更改重新执行。您会在某处发现某种语法错误或拼写错误或无效的文件名。修复它,然后再次清洁。

答案 2 :(得分:0)

如果你在Eclipse上打开问题视图(窗口 - &gt;显示视图 - &gt;问题)并在资源或清单中查找错误

答案 3 :(得分:0)

尝试重新启动eclipse,有时它可以解决问题。检查您是否使用jdk 7,它只需要jdk 6.