03-06 21:50:43.031: E/AndroidRuntime(1013): FATAL EXCEPTION: main
03-06 21:50:43.031: E/AndroidRuntime(1013): android.content.res.Resources$NotFoundException: Unable to find resource ID #0xffffffff
03-06 21:50:43.031: E/AndroidRuntime(1013): at android.content.res.Resources.getResourceName(Resources.java:1659)
03-06 21:50:43.031: E/AndroidRuntime(1013): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:903)
03-06 21:50:43.031: E/AndroidRuntime(1013): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1088)
03-06 21:50:43.031: E/AndroidRuntime(1013): at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:682)
03-06 21:50:43.031: E/AndroidRuntime(1013): at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1444)
03-06 21:50:43.031: E/AndroidRuntime(1013): at android.support.v4.app.FragmentManagerImpl.executePendingTransactions(FragmentManager.java:461)
03-06 21:50:43.031: E/AndroidRuntime(1013): at android.support.v4.app.FragmentPagerAdapter.finishUpdate(FragmentPagerAdapter.java:141)
03-06 21:50:43.031: E/AndroidRuntime(1013): at android.support.v4.view.ViewPager.populate(ViewPager.java:1012)
03-06 21:50:43.031: E/AndroidRuntime(1013): at android.support.v4.view.ViewPager.populate(ViewPager.java:881)
03-06 21:50:43.031: E/AndroidRuntime(1013): at android.support.v4.view.ViewPager.onMeasure(ViewPager.java:1366)
03-06 21:50:43.031: E/AndroidRuntime(1013): at android.view.View.measure(View.java:15513)
03-06 21:50:43.031: E/AndroidRuntime(1013): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4827)
03-06 21:50:43.031: E/AndroidRuntime(1013): at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
03-06 21:50:43.031: E/AndroidRuntime(1013): at android.view.View.measure(View.java:15513)
03-06 21:50:43.031: E/AndroidRuntime(1013): at android.widget.LinearLayout.measureVertical(LinearLayout.java:847)
03-06 21:50:43.031: E/AndroidRuntime(1013): at android.widget.LinearLayout.onMeasure(LinearLayout.java:588)
03-06 21:50:43.031: E/AndroidRuntime(1013): at android.view.View.measure(View.java:15513)
03-06 21:50:43.031: E/AndroidRuntime(1013): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4827)
03-06 21:50:43.031: E/AndroidRuntime(1013): at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
03-06 21:50:43.031: E/AndroidRuntime(1013): at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2176)
03-06 21:50:43.031: E/AndroidRuntime(1013): at android.view.View.measure(View.java:15513)
03-06 21:50:43.031: E/AndroidRuntime(1013): at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:1874)
03-06 21:50:43.031: E/AndroidRuntime(1013): at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1089)
03-06 21:50:43.031: E/AndroidRuntime(1013): at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1265)
03-06 21:50:43.031: E/AndroidRuntime(1013): at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:989)
03-06 21:50:43.031: E/AndroidRuntime(1013): at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4351)
03-06 21:50:43.031: E/AndroidRuntime(1013): at android.view.Choreographer$CallbackRecord.run(Choreographer.java:749)
03-06 21:50:43.031: E/AndroidRuntime(1013): at android.view.Choreographer.doCallbacks(Choreographer.java:562)
03-06 21:50:43.031: E/AndroidRuntime(1013): at android.view.Choreographer.doFrame(Choreographer.java:532)
03-06 21:50:43.031: E/AndroidRuntime(1013): at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:735)
03-06 21:50:43.031: E/AndroidRuntime(1013): at android.os.Handler.handleCallback(Handler.java:725)
03-06 21:50:43.031: E/AndroidRuntime(1013): at android.os.Handler.dispatchMessage(Handler.java:92)
03-06 21:50:43.031: E/AndroidRuntime(1013): at android.os.Looper.loop(Looper.java:137)
03-06 21:50:43.031: E/AndroidRuntime(1013): at android.app.ActivityThread.main(ActivityThread.java:5039)
03-06 21:50:43.031: E/AndroidRuntime(1013): at java.lang.reflect.Method.invokeNative(Native Method)
03-06 21:50:43.031: E/AndroidRuntime(1013): at java.lang.reflect.Method.invoke(Method.java:511)
03-06 21:50:43.031: E/AndroidRuntime(1013): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
03-06 21:50:43.031: E/AndroidRuntime(1013): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
03-06 21:50:43.031: E/AndroidRuntime(1013): at dalvik.system.NativeStart.main(Native Method)
03-06 21:55:44.231: E/Trace(1033): error opening trace file: No such file or directory (2)
编辑*我简化了例子,我仍然得到同样的问题。
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.widget.LinearLayout;
import android.widget.TextView;
public class AskQuestionActivity extends FragmentActivity
{
private static LayoutParams MATCH_PARENT = new LayoutParams( LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT );
@Override
protected void onCreate( Bundle savedInstanceState )
{
super.onCreate( savedInstanceState );
ViewPager pager = new ViewPager( this );
pager.setAdapter( new FragmentPagerAdapter( getSupportFragmentManager() )
{
@Override
public int getCount()
{
return 1;
}
@Override
public Fragment getItem( int arg0 )
{
return new BoardFragment();
}
} );
setContentView( pager );
}
public static class BoardFragment extends Fragment
{
@Override
public View onCreateView( LayoutInflater inflater,
ViewGroup container,
Bundle savedInstanceState )
{
TextView textView = new TextView( getActivity() );
textView.setText( "Board" );
textView.setGravity( Gravity.CENTER );
LinearLayout layout = new LinearLayout( getActivity() );
layout.setLayoutParams( MATCH_PARENT );
layout.addView( textView );
return layout;
}
}
}
欢迎任何帮助。
所以我会贴出我认为是解决我的问题的方法。在上面的代码中添加一行,给viewpager
一个“随机”ID;它设法解决了我的问题。
起初,我确信设置自己的ID是不好的做法,但显然有合法的方法可以做到这一点。也就是说,创建一个ids.xml文件,让Android生态系统为您生成一个ID。我建议查看这些SO帖子以获得更多信息--这里和这里。
否则,我建议只为您的布局创建一个XML文件,并在活动
中获取viewpager
(而不是以编程方式实例化它),但最终这完全取决于您试图完成什么。
回收器自定义适配器 01-09 10:43:45.747 660 2-6602/Ctize.connectplus.com.communitize E/AndroidRuntime:致命异常:主进程:Ctize.connectplus.com.communitize,PID:6602 Android.content.res.resources$NotFoundException:资源ID#0x7F
问题内容: 运行片段尝试显示对象的ListView时会发生此异常。我已经研究了该异常,但针对其他情况的解决方案似乎与“ setText”函数有关,或者其他任何尝试将除字符串以外的任何内容显示为字符串的问题。我真的不确定还有什么要说的。提前致谢! Java类 } XML布局 编辑(日志) 问题答案: 发现您的错误。它在您的IngAdapter中的以下行中 在此,第二个参数应该是资源名称,并且绝不能使
问题内容: 我正在开发一个Android应用程序,该程序从MySQL数据库读取数据,但遇到了此错误。我有这个XML布局: 这是我的Java文件: 调用此Activity时,我收到以下错误消息: 我不知道如何解决此错误。 问题答案: 更改 至 有不同的版本-一种采用字符串,一种采用int资源ID。如果将其传递给整数,它将尝试查找相应的字符串资源ID-找不到它,这是你的错误。 我想返回一个整数。你需要
我正在开发一个从MySQL数据库读取数据的Android应用程序,我遇到了这个错误。我有这样的XML布局: 这是我的Java文件: 当调用此activity时,我收到以下错误消息: 我不知道如何修复这个错误。
我仍然不明白错误在哪里,如何恢复它!