我已经有这个运行时错误差不多一个星期了,找不到解决方案(我是一个新的android程序员)。请帮帮我!
日志位于此消息的末尾。我知道有一些类似的问题,但我无法找到解决问题的方法。
我正在尝试使用Intent
从活动中调用一个类,但运行时错误表明无法找到此类。
这是日志文件:
07-01 13:22:57.098: E/dalvikvm(1488): Could not find class 'com.XXX.ui.ViewPager',
referenced from method com.XXX.ui.MainIWrapper.onCreate
07-01 13:22:57.338: E/AndroidRuntime(1488): FATAL EXCEPTION: main
07-01 13:22:57.338: E/AndroidRuntime(1488): java.lang.RuntimeException: Unable to start
activity ComponentInfo{com.XXX/com.XXX.ui.MainIWrapper}:
android.view.InflateException: Binary XML file line #43: Error inflating class
com.XXX.ui.NavigationBar
07-01 13:22:57.338: E/AndroidRuntime(1488): at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
07-01 13:22:57.338: E/AndroidRuntime(1488): at
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
07-01 13:22:57.338: E/AndroidRuntime(1488): at
android.app.ActivityThread.access$1500(ActivityThread.java:117)
07-01 13:22:57.338: E/AndroidRuntime(1488): at
android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
07-01 13:22:57.338: E/AndroidRuntime(1488): at
android.os.Handler.dispatchMessage(Handler.java:99)
07-01 13:22:57.338: E/AndroidRuntime(1488): at
android.os.Looper.loop(Looper.java:130)
07-01 13:22:57.338: E/AndroidRuntime(1488): at
android.app.ActivityThread.main(ActivityThread.java:3683)
07-01 13:22:57.338: E/AndroidRuntime(1488): at
java.lang.reflect.Method.invokeNative(Native Method)
07-01 13:22:57.338: E/AndroidRuntime(1488): at
java.lang.reflect.Method.invoke(Method.java:507)
07-01 13:22:57.338: E/AndroidRuntime(1488): at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
07-01 13:22:57.338: E/AndroidRuntime(1488): at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
07-01 13:22:57.338: E/AndroidRuntime(1488): at
dalvik.system.NativeStart.main(Native
Method)
07-01 13:22:57.338: E/AndroidRuntime(1488): Caused by: android.view.InflateException:
Binary
XML file line #43: Error inflating class com.XXX.ui.NavigationBar
07-01 13:22:57.338: E/AndroidRuntime(1488): at
android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:581)
07-01 13:22:57.338: E/AndroidRuntime(1488): at
android.view.LayoutInflater.rInflate(LayoutInflater.java:623)
07-01 13:22:57.338: E/AndroidRuntime(1488): at
android.view.LayoutInflater.rInflate(LayoutInflater.java:626)
07-01 13:22:57.338: E/AndroidRuntime(1488): at
android.view.LayoutInflater.rInflate(LayoutInflater.java:626)
07-01 13:22:57.338: E/AndroidRuntime(1488): at
android.view.LayoutInflater.rInflate(LayoutInflater.java:626)
07-01 13:22:57.338: E/AndroidRuntime(1488): at
android.view.LayoutInflater.inflate(LayoutInflater.java:408)
07-01 13:22:57.338: E/AndroidRuntime(1488): at
android.view.LayoutInflater.inflate(LayoutInflater.java:320)
07-01 13:22:57.338: E/AndroidRuntime(1488): at
android.view.LayoutInflater.inflate(LayoutInflater.java:276)
07-01 13:22:57.338: E/AndroidRuntime(1488): at
com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:207)
07-01 13:22:57.338: E/AndroidRuntime(1488): at
android.app.Activity.setContentView(Activity.java:1657)
07-01 13:22:57.338: E/AndroidRuntime(1488): at
com.XXX.ui.MainIWrapper.onCreate(MainIWrapper.java:69)
07-01 13:22:57.338: E/AndroidRuntime(1488): at
android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
07-01 13:22:57.338: E/AndroidRuntime(1488): at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
07-01 13:22:57.338: E/AndroidRuntime(1488): ... 11 more
07-01 13:22:57.338: E/AndroidRuntime(1488): Caused by: java.lang.ClassNotFoundException:
com.XXX.ui.NavigationBar in loader dalvik.system.PathClassLoader[/data/app/com.XXX-
2.apk]
07-01 13:22:57.338: E/AndroidRuntime(1488): at
dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240)
07-01 13:22:57.338: E/AndroidRuntime(1488): at
java.lang.ClassLoader.loadClass(ClassLoader.java:551)
07-01 13:22:57.338: E/AndroidRuntime(1488): at
java.lang.ClassLoader.loadClass(ClassLoader.java:511)
07-01 13:22:57.338: E/AndroidRuntime(1488): at
android.view.LayoutInflater.createView(LayoutInflater.java:471)
07-01 13:22:57.338: E/AndroidRuntime(1488): at
android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:570)
07-01 13:22:57.338: E/AndroidRuntime(1488): ... 23 more
这是处理意图的功能:
private Activity from;
private Class to;
public void open() {
Intent intent;
intent = new Intent(from, to);
if (extras != null) {
intent.putExtras(extras);
}
if (to.equals(MainWrapper.class)) {
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
}
if (activityForResultRequestCode == -1) {
from.startActivity(intent);
} else {
from.startActivityForResult(intent, activityForResultRequestCode);
}
if (pendingAnimation != null && pendingAnimation.length == 2) {
from.overridePendingTransition(pendingAnimation[0], pendingAnimation[1]);
} else {
from.overridePendingTransition(R.anim.slide_in_right, R.anim.hold);
}
if (toClosePreviousActivity) {
from.finish();
}
}
这是来自的活动(需要更改)的调用,我要加载的类(它使用正在执行意图的open()
函数):< / p>
UiUtils.getOpenActivityBuilder(SplashScreen.this,MainIWrapper.class).toClosePrev(true).open;
这是我的清单的一部分 - 这是需要更改为班级MainIWrapper
的主要活动:
<activity
android:name=".ui.SplashScreen"
android:configChanges="orientation"
android:screenOrientation="portrait"
android:theme="@android:style/Theme.NoTitleBar" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
这是清单文件中的mainWrapper声明:
<activity
android:name=".ui.MainIWrapper"
android:configChanges="orientation"
android:launchMode="singleTask"
android:screenOrientation="portrait"
android:theme="@android:style/Theme.NoTitleBar" />
这是mainWrapper
声明:
public class MainIWrapper extends BaseWebSiteScreen implements HasBox {...}
这是主要的活动宣言:
public class SplashScreen extends Activity {...}
谢谢你的帮助但是我仍然找不到问题(我真的是android的初学者)
这些是来自我的XML的行(来自第43行):
<com.XXX.ui.NavigationBar
xmlns:vwpgind="http://schemas.android.com/apk/res/com.XXX"
android:id="@+id/navigation_bar"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="top"
vwpgind:arrowImageSrc="@drawable/common_slider_arrow"
vwpgind:hideFirstItem="true" />
来自MainIWrapper.OnCreate()的代码是:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_iwrapper);
isUserLoggedIn = UserDetails.getInstance(getApplicationContext()).isUserLoggedIn();
//we want to refresh user thumb each time user opens Main iWrapper
if (UserDetails.getInstance(getApplicationContext()).isUserLoggedIn())
UserDetails.deleteCachedUserThumb(getApplicationContext());
textBox = (TextBox) findViewById(R.id.text_box);
viewPager = (ViewPager) findViewById(R.id.view_pager);
pageViewAdapter = new PageViewAdapter();
viewPager.setAdapter(pageViewAdapter);
viewPager.setOffscreenPageLimit(NUMBER_OF_PAGES_TO_PRELOAD);
navigationBar = (NavigationBar) findViewById(R.id.navigation_bar);
topBar = (TopBar) findViewById(R.id.top_bar);
progressAnimation = (ImageView) findViewById(R.id.progress_animation);
bottomBar = (BottomBar) findViewById(R.id.bottom_bar);
}
我仍然无法在这里找到错误。我查看了构建路径和包含com.XXX.ui包的src文件夹(此包包含NavigationBar和ViewPager类)
这些是来自我的XML的行(来自第43行):
<com.XXX.ui.NavigationBar
xmlns:vwpgind="http://schemas.android.com/apk/res/com.XXX"
android:id="@+id/navigation_bar"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="top"
vwpgind:arrowImageSrc="@drawable/common_slider_arrow"
vwpgind:hideFirstItem="true" />
来自MainIWrapper.OnCreate()的代码是:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_iwrapper);
isUserLoggedIn = UserDetails.getInstance(getApplicationContext()).isUserLoggedIn();
//we want to refresh user thumb each time user opens Main iWrapper
if (UserDetails.getInstance(getApplicationContext()).isUserLoggedIn())
UserDetails.deleteCachedUserThumb(getApplicationContext());
textBox = (TextBox) findViewById(R.id.text_box);
viewPager = (ViewPager) findViewById(R.id.view_pager);
pageViewAdapter = new PageViewAdapter();
viewPager.setAdapter(pageViewAdapter);
viewPager.setOffscreenPageLimit(NUMBER_OF_PAGES_TO_PRELOAD);
navigationBar = (NavigationBar) findViewById(R.id.navigation_bar);
topBar = (TopBar) findViewById(R.id.top_bar);
progressAnimation = (ImageView) findViewById(R.id.progress_animation);
bottomBar = (BottomBar) findViewById(R.id.bottom_bar);
}
我仍然看不出这里有什么问题
public class ViewPager extends android.support.v4.view.ViewPager {
public ViewPager(Context context) {
super(context);
}
public ViewPager(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
public Parcelable onSaveInstanceState() {
try {
return super.onSaveInstanceState();
} catch (Exception e) {
return null;
}
}
答案 0 :(得分:2)
编译器不检查布局XML文件中引用的类是否存在,因此仅在运行时获取错误是正常的。
很可能com。XXX.ui.NavigationBar
类在您的类路径中不存在。检查您的软件包名称,可能只是一个错字,或者您忘记在NavigationBar
类上的软件包名称重构后更改XML文件中的软件包名称。
答案 1 :(得分:0)
错误都在这里:
07-01 13:22:57.098: E/dalvikvm(1488): Could not find class 'com.XXX.ui.ViewPager',
referenced from method com.XXX.ui.MainIWrapper.onCreate
android.view.InflateException: Binary XML file line #43: Error inflating class
com.XXX.ui.NavigationBar
发布MainIWrapper.onCreate()中的代码,并查看XML for NavigationBar中的第43行。