Ruby`requiret':无法加载这样的文件(LoadError)(Ruby `require': cannot load such file (LoadError))
我有一个目录结构如下所示:
- lib - yp-crawler (directory) - file-a.rb - file-b.rb - file-c.rb - yp-crawler.rb
我的
lib/yp-crawler.rb
文件如下所示:require "yp-crawler/file-c" require "yp-crawler/file-b" require "yp-crawler/file-a" module YPCrawler end
当我尝试通过执行以下操作在命令行运行我的文件时:
ruby lib/yp-crawler.rb
我得到这个错误:
`require': cannot load such file -- yp-crawler/file-c (LoadError) from .rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require' from lib/yp-crawler.rb:1:in `<main>'
什么可能导致这个?
I have a directory structure that looks like this:
- lib - yp-crawler (directory) - file-a.rb - file-b.rb - file-c.rb - yp-crawler.rb
My
lib/yp-crawler.rb
file looks like this:require "yp-crawler/file-c" require "yp-crawler/file-b" require "yp-crawler/file-a" module YPCrawler end
When I try to run my file at the command line by doing this:
ruby lib/yp-crawler.rb
I get this error:
`require': cannot load such file -- yp-crawler/file-c (LoadError) from .rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require' from lib/yp-crawler.rb:1:in `<main>'
What could be causing this?
原文:https://stackoverflow.com/questions/39747140
更新时间:2023-03-19 15:03
最满意答案
试试这个代码,这只是一个由Recycler Adapter支持的List Activity,包含List Activity的XML,Card Layout XML文件
public class ListActivity extends AppCompatActivity { DBHelper helper; static List<DBModel>dbList; RecyclerView mRecyclerView; private static RecyclerView.Adapter mAdapter; private RecyclerView.LayoutManager mLayoutManager; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_list); addListenerOnButtonAdd(); TextView tvNoData = (TextView)findViewById(R.id.tvNoData); setTitle("");// This sets the title of the toolbar Toolbar topToolBar = (Toolbar)findViewById(R.id.toolbar); setSupportActionBar(topToolBar); //topToolBar.setLogo(R.drawable.keyss);// See Notes in MainActivity setRequestedOrientation( ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); helper = new DBHelper(this); dbList = new ArrayList<>(); dbList = helper.getDataFromDB(); mRecyclerView = (RecyclerView)findViewById(R.id.recycleview); mRecyclerView.setHasFixedSize(true); // use a linear layout manager mLayoutManager = new LinearLayoutManager(this); mRecyclerView.setLayoutManager(mLayoutManager); // Code below defines the adapter mAdapter = new RecyclerAdapter(this,dbList); mRecyclerView.setAdapter(mAdapter); int sz = dbList.size(); if(sz == 0){ tvNoData.setVisibility(View.VISIBLE); tvNoData.setText("No Data"); } } // This method is called from DetailsActivity and notifies Recycler View that the DB was changed of DB and Recycler View public static void removeListRow(int position) { dbList.remove(position); mAdapter.notifyItemRemoved(position); mAdapter.notifyItemRangeChanged(position, dbList.size()); } /* this BUTTON is on the ToolBar click to ADD new record */ private void addListenerOnButtonAdd() { // Navigate to DetailsActivity to ADD new DATA Toolbar tb = (Toolbar) findViewById( R.id.toolbar ); setSupportActionBar( tb ); tb.findViewById( R.id.btnAdd ).setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { Intent intentSP = new Intent(ListActivity.this, DetailsActivity.class ); Bundle extras = new Bundle(); extras.putString("FROM_LIST_ACTIVITY","true" ); intentSP.putExtras(extras); startActivity( intentSP ); } } ); } public void onBackPressed(){ Intent intent = new Intent( ListActivity.this, MainActivity.class ); startActivity( intent ); } } <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/activity_list" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@color/color_lightGray" android:orientation="vertical" tools:context="com.searchdb.ListActivity"> <android.support.v7.widget.Toolbar android:id="@+id/toolbar" android:minHeight="?attr/actionBarSize" android:background="@color/color_darkGray" android:layout_width="match_parent" android:layout_height="64dp"> <ImageView android:id="@+id/imageTB" android:layout_width="70dp" android:layout_height="wrap_content" android:paddingBottom="2dp" android:paddingLeft="2dp" android:paddingRight="2dp" android:paddingTop="4dp" android:src="@drawable/keyss" /> <TextView android:text="@string/list_view" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignBottom="@+id/toolbar" android:layout_alignParentStart="true" android:layout_marginStart="30dp" android:layout_marginBottom="20dp" android:id="@+id/tvLA" android:textStyle="bold" android:textColor="@color/color_White" android:textSize="22sp" /> <Button android:text="@string/add" android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/btnAdd" android:layout_marginLeft="100dp" android:textSize="18sp" android:textStyle="bold" android:focusable="false" android:textColor="@color/color_White" android:background="@color/color_Transparent"/> </android.support.v7.widget.Toolbar> <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal"> <android.support.v7.widget.RecyclerView android:id="@+id/recycleview" android:layout_width="match_parent" android:layout_height="match_parent"/> </LinearLayout> <LinearLayout android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <TextView android:text="TextView" android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/tvNoData" android:gravity="center" android:layout_marginTop="240dp" android:visibility="invisible" android:textAllCaps="true" android:textStyle="bold" android:textSize="30sp" android:textColor="@color/color_Red" /> </LinearLayout> </LinearLayout> public class RecyclerAdapter extends RecyclerView.Adapter<RecyclerAdapter.ViewHolder> { static List<DBModel> dbList; static private Context context; int sz; RecyclerAdapter(Context context, List<DBModel> dbList) { RecyclerAdapter.dbList = new ArrayList<>(); RecyclerAdapter.context = context; RecyclerAdapter.dbList = dbList; } @Override public RecyclerAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { View itemLayoutView = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_row, null); // create ViewHolder ViewHolder viewHolder = new ViewHolder(itemLayoutView); return viewHolder; } @Override public void onBindViewHolder(RecyclerAdapter.ViewHolder holder, int position) { holder.rowid.setText(String.valueOf(dbList.get(position).getRowid())); holder.station.setText(dbList.get(position).getStation_Name()); System.out.println("RecyclerAdapter BindViewHolder FIRST position "+position); } @Override public int getItemCount() { return dbList.size(); } public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener { public TextView station, rowid; public ViewHolder(View itemLayoutView) { super(itemLayoutView); rowid = (TextView) itemLayoutView.findViewById(R.id.rvROWID); station = (TextView) itemLayoutView.findViewById(R.id.rvSTATION); // Attach a click listener to the entire row view itemLayoutView.setOnClickListener(this); } @Override public void onClick(View v) { Intent intentN = new Intent(context, DetailsActivity.class); Bundle extras = new Bundle(); extras.putInt("POSITION", getAdapterPosition()); extras.putString("FROM_LIST_ACTIVITY", "false"); intentN.putExtras(extras); context.startActivity(intentN); } } } <?xml version="1.0" encoding="utf-8"?> <android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android" xmlns:card_view="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_margin="5dp" android:orientation="horizontal" card_view:cardCornerRadius="5dp" card_view:cardUseCompatPadding="true"> <RelativeLayout android:layout_width="match_parent" android:layout_height="match_parent" android:background="@color/color_White"> <TextView android:id="@+id/rvROWID" android:layout_width="wrap_content" android:layout_height="50dp" android:gravity="left|center_vertical" android:padding="10dp" android:textAlignment="center" android:text="Position ID" android:textColor="@color/color_Black" android:layout_marginLeft="10dp" android:textStyle="bold" android:textSize="16sp"/> <TextView android:id="@+id/rvSTATION" android:layout_width="fill_parent" android:layout_height="50dp" android:padding="10dp" android:gravity="right|center_vertical" android:text="Station" android:layout_marginLeft="10dp" android:textStyle="bold" android:textSize="16sp" android:textColor="@color/color_Black" /> </RelativeLayout> </android.support.v7.widget.CardView>
Try this code this is just a List Activity that is backed by a Recycler Adapter the XML for the List Activity is included and the Card Layout XML file
public class ListActivity extends AppCompatActivity { DBHelper helper; static List<DBModel>dbList; RecyclerView mRecyclerView; private static RecyclerView.Adapter mAdapter; private RecyclerView.LayoutManager mLayoutManager; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_list); addListenerOnButtonAdd(); TextView tvNoData = (TextView)findViewById(R.id.tvNoData); setTitle("");// This sets the title of the toolbar Toolbar topToolBar = (Toolbar)findViewById(R.id.toolbar); setSupportActionBar(topToolBar); //topToolBar.setLogo(R.drawable.keyss);// See Notes in MainActivity setRequestedOrientation( ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); helper = new DBHelper(this); dbList = new ArrayList<>(); dbList = helper.getDataFromDB(); mRecyclerView = (RecyclerView)findViewById(R.id.recycleview); mRecyclerView.setHasFixedSize(true); // use a linear layout manager mLayoutManager = new LinearLayoutManager(this); mRecyclerView.setLayoutManager(mLayoutManager); // Code below defines the adapter mAdapter = new RecyclerAdapter(this,dbList); mRecyclerView.setAdapter(mAdapter); int sz = dbList.size(); if(sz == 0){ tvNoData.setVisibility(View.VISIBLE); tvNoData.setText("No Data"); } } // This method is called from DetailsActivity and notifies Recycler View that the DB was changed of DB and Recycler View public static void removeListRow(int position) { dbList.remove(position); mAdapter.notifyItemRemoved(position); mAdapter.notifyItemRangeChanged(position, dbList.size()); } /* this BUTTON is on the ToolBar click to ADD new record */ private void addListenerOnButtonAdd() { // Navigate to DetailsActivity to ADD new DATA Toolbar tb = (Toolbar) findViewById( R.id.toolbar ); setSupportActionBar( tb ); tb.findViewById( R.id.btnAdd ).setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { Intent intentSP = new Intent(ListActivity.this, DetailsActivity.class ); Bundle extras = new Bundle(); extras.putString("FROM_LIST_ACTIVITY","true" ); intentSP.putExtras(extras); startActivity( intentSP ); } } ); } public void onBackPressed(){ Intent intent = new Intent( ListActivity.this, MainActivity.class ); startActivity( intent ); } } <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/activity_list" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@color/color_lightGray" android:orientation="vertical" tools:context="com.searchdb.ListActivity"> <android.support.v7.widget.Toolbar android:id="@+id/toolbar" android:minHeight="?attr/actionBarSize" android:background="@color/color_darkGray" android:layout_width="match_parent" android:layout_height="64dp"> <ImageView android:id="@+id/imageTB" android:layout_width="70dp" android:layout_height="wrap_content" android:paddingBottom="2dp" android:paddingLeft="2dp" android:paddingRight="2dp" android:paddingTop="4dp" android:src="@drawable/keyss" /> <TextView android:text="@string/list_view" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignBottom="@+id/toolbar" android:layout_alignParentStart="true" android:layout_marginStart="30dp" android:layout_marginBottom="20dp" android:id="@+id/tvLA" android:textStyle="bold" android:textColor="@color/color_White" android:textSize="22sp" /> <Button android:text="@string/add" android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/btnAdd" android:layout_marginLeft="100dp" android:textSize="18sp" android:textStyle="bold" android:focusable="false" android:textColor="@color/color_White" android:background="@color/color_Transparent"/> </android.support.v7.widget.Toolbar> <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal"> <android.support.v7.widget.RecyclerView android:id="@+id/recycleview" android:layout_width="match_parent" android:layout_height="match_parent"/> </LinearLayout> <LinearLayout android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <TextView android:text="TextView" android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/tvNoData" android:gravity="center" android:layout_marginTop="240dp" android:visibility="invisible" android:textAllCaps="true" android:textStyle="bold" android:textSize="30sp" android:textColor="@color/color_Red" /> </LinearLayout> </LinearLayout> public class RecyclerAdapter extends RecyclerView.Adapter<RecyclerAdapter.ViewHolder> { static List<DBModel> dbList; static private Context context; int sz; RecyclerAdapter(Context context, List<DBModel> dbList) { RecyclerAdapter.dbList = new ArrayList<>(); RecyclerAdapter.context = context; RecyclerAdapter.dbList = dbList; } @Override public RecyclerAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { View itemLayoutView = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_row, null); // create ViewHolder ViewHolder viewHolder = new ViewHolder(itemLayoutView); return viewHolder; } @Override public void onBindViewHolder(RecyclerAdapter.ViewHolder holder, int position) { holder.rowid.setText(String.valueOf(dbList.get(position).getRowid())); holder.station.setText(dbList.get(position).getStation_Name()); System.out.println("RecyclerAdapter BindViewHolder FIRST position "+position); } @Override public int getItemCount() { return dbList.size(); } public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener { public TextView station, rowid; public ViewHolder(View itemLayoutView) { super(itemLayoutView); rowid = (TextView) itemLayoutView.findViewById(R.id.rvROWID); station = (TextView) itemLayoutView.findViewById(R.id.rvSTATION); // Attach a click listener to the entire row view itemLayoutView.setOnClickListener(this); } @Override public void onClick(View v) { Intent intentN = new Intent(context, DetailsActivity.class); Bundle extras = new Bundle(); extras.putInt("POSITION", getAdapterPosition()); extras.putString("FROM_LIST_ACTIVITY", "false"); intentN.putExtras(extras); context.startActivity(intentN); } } } <?xml version="1.0" encoding="utf-8"?> <android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android" xmlns:card_view="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_margin="5dp" android:orientation="horizontal" card_view:cardCornerRadius="5dp" card_view:cardUseCompatPadding="true"> <RelativeLayout android:layout_width="match_parent" android:layout_height="match_parent" android:background="@color/color_White"> <TextView android:id="@+id/rvROWID" android:layout_width="wrap_content" android:layout_height="50dp" android:gravity="left|center_vertical" android:padding="10dp" android:textAlignment="center" android:text="Position ID" android:textColor="@color/color_Black" android:layout_marginLeft="10dp" android:textStyle="bold" android:textSize="16sp"/> <TextView android:id="@+id/rvSTATION" android:layout_width="fill_parent" android:layout_height="50dp" android:padding="10dp" android:gravity="right|center_vertical" android:text="Station" android:layout_marginLeft="10dp" android:textStyle="bold" android:textSize="16sp" android:textColor="@color/color_Black" /> </RelativeLayout> </android.support.v7.widget.CardView>
相关问答
更多-
NumberPicker没有主题(NumberPicker has no theme)[2022-06-04]
使用Hyper-V的Visual Studio Android模拟器似乎存在问题。 在我的手机或使用HAXM的Android SDK仿真器上安装应用程序时,未出现问题。 It seems to be a problem with the Visual Studio Android Emulator using Hyper-V. Problem did not appear when installing the App on my mobile phone or in Android SDK emulato ... -
NumberPicker picker = new NumberPicker(this); picker.setMinValue(0); picker.setMaxValue(2); picker.setDisplayedValues( new String[] { "Belgium", "France", "United Kingdom" } ); NumberPicker picker = new NumberPicker(this); picker.setMinValue(0); picker.se ...
-
无法在android中导入android.widget.NumberPicker(Not able to import android.widget.NumberPicker in android)[2022-07-30]
NumberPicker已添加到API Level 11中。因此,您无法将其导入到API 10(Android 2.3.3)项目中。 备择方案: android-numberpicker :Android 4.0 NumberPicker回退到 2.1。 android-wheel :具有自定义项目支持的灵活轮子。 如果我是你,我会和第一个一起去。 NumberPicker was added in API Level 11. So, you can't import it to your API 10 ( ... -
问题似乎是NumberPicker小部件中的一个错误。 我用这里描述的方法2解决了它。 The issue seems to a bug in NumberPicker widget. And I have solved it using method 2 described here.
-
在onClick的setMaxValue之前检查Call setDisplayedValues(null) 。 参考: https : //stackoverflow.com/a/24322319/2624806 Well, I look into the source code of NumberPicker.java, find that it will recompute the data and refresh UI in setMinValue(int minValue) and setMaxVa ...
-
在android中使用NumberPicker,但使用SQlite的字符串(Using NumberPicker in android but with strings from SQlite)[2023-10-03]
试试这个代码,这只是一个由Recycler Adapter支持的List Activity,包含List Activity的XML,Card Layout XML文件 public class ListActivity extends AppCompatActivity { DBHelper helper; static ListdbList; RecyclerView mRecyclerView; private static RecyclerView.Ad ... -
minutePicker = new NumberPicker(MainActivity.this); minutePicker = (NumberPicker) findViewById(R.id.minuten_picker); 您正在以编程方式创建NumberPicker ,然后使用findViewById()返回的任何内容覆盖引用。 如果您的activity_main布局不包含minuten_picker ,则返回null。 只选择另一个:以原型方式创建它或从您膨胀的视图层次结构中找到它。 如果选 ...
-
如何使用calabash为android NumberPicker输入值(How to enter value to android NumberPicker with calabash)[2022-01-11]
实际上这只是我缺少红宝石和葫芦。 我克隆calabash android并开始调查并找到下一个解决方案: query("android.widget.NumberPicker id:'minutes_picker'", setValue:minutes) minutes应该是整数值 Actually it was just my lack of ruby and calabash. I clone calabash android and start investigating and found n ... -
错过了: setDisplayedValues 。 这就是我所需要的。 Missed that: setDisplayedValues. That's what I needed.
-
我刚用你的代码测试过。 getValue()实际上返回所选项目的索引(仅当您设置显示的值时)。 所有你需要做的就是解析字符串,你会得到你想要的。 String[] nums = {"1","1.5","2","2.5","3","3.5","4","4.5","5","5.5","6","6.5","7","7.5","8","8.5","9"}; int index = listeningScorenp.getValue(); String val = nums[index]; float selecte ...