我对 2.2 版本中 fragment 的兼容性有疑问。我使用“Sherlock Action Bar”来创建操作栏,但我无法创建两个 fragment 。我总是收到这个错误:
01-07 12:51:56.124: E/AndroidRuntime(475): FATAL EXCEPTION: main 01-07
12:51:56.124: E/AndroidRuntime(475): java.lang.RuntimeException:
Unable to start activity
ComponentInfo{com.example.pruebasherlock_v4/com.example.pruebasherlock_v4.MainActivity}:
android.view.InflateException: Binary XML file line #7: Error
inflating class fragment 01-07 12:51:56.124: E/AndroidRuntime(475):
at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
01-07 12:51:56.124: E/AndroidRuntime(475): at
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
01-07 12:51:56.124: E/AndroidRuntime(475): at
android.app.ActivityThread.access$2300(ActivityThread.java:125) 01-07
12:51:56.124: E/AndroidRuntime(475): at
android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
01-07 12:51:56.124: E/AndroidRuntime(475): at
android.os.Handler.dispatchMessage(Handler.java:99) 01-07
12:51:56.124: E/AndroidRuntime(475): at
android.os.Looper.loop(Looper.java:123) 01-07 12:51:56.124:
E/AndroidRuntime(475): at
android.app.ActivityThread.main(ActivityThread.java:4627) 01-07
12:51:56.124: E/AndroidRuntime(475): at
java.lang.reflect.Method.invokeNative(Native Method) 01-07
12:51:56.124: E/AndroidRuntime(475): at
java.lang.reflect.Method.invoke(Method.java:521) 01-07 12:51:56.124:
E/AndroidRuntime(475): at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
01-07 12:51:56.124: E/AndroidRuntime(475): at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626) 01-07
12:51:56.124: E/AndroidRuntime(475): at
dalvik.system.NativeStart.main(Native Method) 01-07 12:51:56.124:
E/AndroidRuntime(475): Caused by: android.view.InflateException:
Binary XML file line #7: Error inflating class fragment 01-07
12:51:56.124: E/AndroidRuntime(475): at
android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:576)
01-07 12:51:56.124: E/AndroidRuntime(475): at
android.view.LayoutInflater.rInflate(LayoutInflater.java:618) 01-07
12:51:56.124: E/AndroidRuntime(475): at
android.view.LayoutInflater.inflate(LayoutInflater.java:407) 01-07
12:51:56.124: E/AndroidRuntime(475): at
android.view.LayoutInflater.inflate(LayoutInflater.java:320) 01-07
12:51:56.124: E/AndroidRuntime(475): at
android.view.LayoutInflater.inflate(LayoutInflater.java:276) 01-07
12:51:56.124: E/AndroidRuntime(475): at
com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:198)
01-07 12:51:56.124: E/AndroidRuntime(475): at
android.app.Activity.setContentView(Activity.java:1647) 01-07
12:51:56.124: E/AndroidRuntime(475): at
com.example.pruebasherlock_v4.MainActivity.onCreate(MainActivity.java:12)
01-07 12:51:56.124: E/AndroidRuntime(475): at
android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
01-07 12:51:56.124: E/AndroidRuntime(475): at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
01-07 12:51:56.124: E/AndroidRuntime(475): ... 11 more 01-07
12:51:56.124: E/AndroidRuntime(475): Caused by:
java.lang.ClassNotFoundException: android.view.fragment in loader
dalvik.system.PathClassLoader[/data/app/com.example.pruebasherlock_v4-1.apk]
01-07 12:51:56.124: E/AndroidRuntime(475): at
dalvik.system.PathClassLoader.findClass(PathClassLoader.java:243)
01-07 12:51:56.124: E/AndroidRuntime(475): at
java.lang.ClassLoader.loadClass(ClassLoader.java:573) 01-07
12:51:56.124: E/AndroidRuntime(475): at
java.lang.ClassLoader.loadClass(ClassLoader.java:532) 01-07
12:51:56.124: E/AndroidRuntime(475): at
android.view.LayoutInflater.createView(LayoutInflater.java:466) 01-07
12:51:56.124: E/AndroidRuntime(475): at
android.view.LayoutInflater.onCreateView(LayoutInflater.java:544)
01-07 12:51:56.124: E/AndroidRuntime(475): at
com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:66)
01-07 12:51:56.124: E/AndroidRuntime(475): at
android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:563)
01-07 12:51:56.124: E/AndroidRuntime(475): ... 20 more
我的 main_activity 包含这个:
package com.example.pruebasherlock_v4;
import android.app.Activity;
import android.os.Bundle;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
}
我的 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"
tools:context=".MainActivity" >
<fragment
android:id="@+id/listaIzq"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="fill_parent"
class="com.example.pruebasherlock_v4.Lista"/>
<fragment
android:id="@+id/detallesDer"
android:layout_weight="3"
android:layout_width="0dp"
android:layout_height="fill_parent"
class="com.example.pruebasherlock_v4.Detalle" />
</LinearLayout>
“lista”和“Detalle”类包含以下内容:
list :
package com.example.pruebasherlock_v4;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import com.actionbarsherlock.app.SherlockListFragment;
public class Lista extends SherlockListFragment{
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Override
//se sobreescribe este método como el que siempre "carga" la información a mostrar en el fragment
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
String[] values = new String[] { "Android", "iPhone", "WindowsMobile",
"Blackberry", "WebOS", "Ubuntu", "Windows7", "Max OS X",
"Linux", "OS/2" };
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this.getActivity(), android.R.layout.simple_list_item_1, values);
setListAdapter(adapter);
}
@Override
//al hacer tap en algun elemento de la vista, setea el texto del elemento en el nuevo fragment
public void onListItemClick(ListView l, View v, int position, long id) {
String item = (String) getListAdapter().getItem(position);
Detalle fragment = (Detalle) getFragmentManager().findFragmentById(R.id.detallesDer);
if (fragment != null && fragment.isInLayout()) {
fragment.setText(item);
} else {
/*Intent intent = new Intent(getActivity().getApplicationContext(), DetailActivity.class);
intent.putExtra("value", item);
startActivity(intent);*/
}
}
}
详细信息:
package com.example.pruebasherlock_v4;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import com.actionbarsherlock.app.SherlockFragment;
public class Detalle extends SherlockFragment {
@Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
Log.e("Test", "hello");
}
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.detalle, container, false);
return view;
}
public void setText(String item) {
TextView view = (TextView) getView().findViewById(R.id.textoDetalle);
view.setText(item);
}
}
我觉得放了很多代码,但不是因为它是错误的。
非常感谢您的帮助。
最佳答案
My main_activity contains this:
如果您打算使用 ActionBarSherlock,请继承 Sherlock 类,例如 SherlockActivity。如果您也打算使用 fragment ,请继承SherlockFragmentActivity。
引用the ActionBarSherlock documentation :
When creating an activity to use the action bar on all versions of Android, you must declare your activity to extend any of the activity classes that start with 'Sherlock' (e.g., SherlockActivity, SherlockFragmentActivity).
关于android - 操作栏 Sherlock + ListFragments + Fragments,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14200785/
我的瘦服务器配置了nginx,我的ROR应用程序正在它们上运行。在我发布代码更新时运行thinrestart会给我的应用程序带来一些停机时间。我试图弄清楚如何优雅地重启正在运行的Thin实例,但找不到好的解决方案。有没有人能做到这一点? 最佳答案 #Restartjustthethinserverdescribedbythatconfigsudothin-C/etc/thin/mysite.ymlrestartNginx将继续运行并代理请求。如果您将Nginx设置为使用多个上游服务器,例如server{listen80;server
如何将send与+=一起使用?a=20;a.send"+=",10undefinedmethod`+='for20:Fixnuma=20;a+=10=>30 最佳答案 恐怕你不能。+=不是方法,而是语法糖。参见http://www.ruby-doc.org/docs/ProgrammingRuby/html/tut_expressions.html它说Incommonwithmanyotherlanguages,Rubyhasasyntacticshortcut:a=a+2maybewrittenasa+=2.你能做的最好的事情是:
最近因为项目需要,需要将Android手机系统自带的某个系统软件反编译并更改里面某个资源,并重新打包,签名生成新的自定义的apk,下面我来介绍一下我的实现过程。APK修改,分为以下几步:反编译解包,修改,重打包,修改签名等步骤。安卓apk修改准备工作1.系统配置好JavaJDK环境变量2.需要root权限的手机(针对系统自带apk,其他软件免root)3.Auto-Sign签名工具4.apktool工具安卓apk修改开始反编译本文拿Android系统里面的Settings.apk做demo,具体如何将apk获取出来在此就不过多介绍了,直接进入主题:按键win+R输入cmd,打开命令窗口,并将路
我对如何计算通过{%assignvar=0%}赋值的变量加一完全感到困惑。这应该是最简单的任务。到目前为止,这是我尝试过的:{%assignamount=0%}{%forvariantinproduct.variants%}{%assignamount=amount+1%}{%endfor%}Amount:{{amount}}结果总是0。也许我忽略了一些明显的东西。也许有更好的方法。我想要存档的只是获取运行的迭代次数。 最佳答案 因为{{incrementamount}}将输出您的变量值并且不会影响{%assign%}定义的变量,我
我有一个使用SeleniumWebdriver和Nokogiri的Ruby应用程序。我想选择一个类,然后对于那个类对应的每个div,我想根据div的内容执行一个Action。例如,我正在解析以下页面:https://www.google.com/webhp?sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8#q=puppies这是一个搜索结果页面,我正在寻找描述中包含“Adoption”一词的第一个结果。因此机器人应该寻找带有className:"result"的div,对于每个检查它的.descriptiondiv是否包含单词“adoption
我正在我的Rails项目中安装Grape以构建RESTfulAPI。现在一些端点的操作需要身份验证,而另一些则不需要身份验证。例如,我有users端点,看起来像这样:moduleBackendmoduleV1classUsers现在如您所见,除了password/forget之外的所有操作都需要用户登录/验证。创建一个新的端点也没有意义,比如passwords并且只是删除password/forget从逻辑上讲,这个端点应该与用户资源。问题是Grapebefore过滤器没有像except,only这样的选项,我可以在其中说对某些操作应用过滤器。您通常如何干净利落地处理这种情况?
在我做的一些网络开发中,我有多个操作开始,比如对外部API的GET请求,我希望它们同时开始,因为一个不依赖另一个的结果。我希望事情能够在后台运行。我找到了concurrent-rubylibrary这似乎运作良好。通过将其混合到您创建的类中,该类的方法具有在后台线程上运行的异步版本。这导致我编写如下代码,其中FirstAsyncWorker和SecondAsyncWorker是我编写的类,我在其中混合了Concurrent::Async模块,并编写了一个名为“work”的方法来发送HTTP请求:defindexop1_result=FirstAsyncWorker.new.async.
a=[3,4,7,8,3]b=[5,3,6,8,3]假设数组长度相同,是否有办法使用each或其他一些惯用方法从两个数组的每个元素中获取结果?不使用计数器?例如获取每个元素的乘积:[15,12,42,64,9](0..a.count-1).eachdo|i|太丑了...ruby1.9.3 最佳答案 使用Array.zip怎么样?:>>a=[3,4,7,8,3]=>[3,4,7,8,3]>>b=[5,3,6,8,3]=>[5,3,6,8,3]>>c=[]=>[]>>a.zip(b)do|i,j|c[[3,5],[4,3],[7,6],
我有一个非常简单的Controller来管理我的Rails应用程序中的静态页面:classPagesController我怎样才能让View模板返回它自己的名字,这样我就可以做这样的事情:#pricing.html.erb#-->"Pricing"感谢您的帮助。 最佳答案 4.3RoutingParametersTheparamshashwillalwayscontainthe:controllerand:actionkeys,butyoushouldusethemethodscontroller_nameandaction_nam
我有一个数组数组,想将元素附加到子数组。+=做我想做的,但我想了解为什么push不做。我期望的行为(并与+=一起工作):b=Array.new(3,[])b[0]+=["apple"]b[1]+=["orange"]b[2]+=["frog"]b=>[["苹果"],["橙子"],["Frog"]]通过推送,我将推送的元素附加到每个子数组(为什么?):a=Array.new(3,[])a[0].push("apple")a[1].push("orange")a[2].push("frog")a=>[[“苹果”、“橙子”、“Frog”]、[“苹果”、“橙子”、“Frog”]、[“苹果”、“