Reputation: 3150
I've been having this runtime error for almost a week and can't find the solution (I'm a new android programmer). Please help me!
The log is at the end of this message. I know there are some similar questions to mine but I couldn't find a solution to my problem.
I'm trying to call a class from activity using Intent
but the runtime error says that this class couldn't be found.
This is the log file:
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
This is the function that deals with the intent:
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();
}
}
This is the call from the activity (that needs to be changed), with the class I want to load (it uses the open()
function that is doing the intent):
UiUtils.getOpenActivityBuilder(SplashScreen.this,MainIWrapper.class).toClosePrev(true).open;
This is a part of my manifest -- it's the main activity that needs to be changed to the class 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>
This is the mainWrapper declaration in the manifest file:
<activity
android:name=".ui.MainIWrapper"
android:configChanges="orientation"
android:launchMode="singleTask"
android:screenOrientation="portrait"
android:theme="@android:style/Theme.NoTitleBar" />
This is the mainWrapper
declaration:
public class MainIWrapper extends BaseWebSiteScreen implements HasBox {...}
And this is the main activity declaration:
public class SplashScreen extends Activity {...}
Thank you for the help But i still can't find the problem(I'm really a beginner in android)
Those are the lines from my XML(from line 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" />
the code from MainIWrapper.OnCreate() is:
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);
}
I still can't find the error here. I looked at the build path and the src folder with the com.XXX.ui package in it(this package contains the NavigationBar and the ViewPager classes)
Those are the lines from my XML(from line 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" />
the code from MainIWrapper.OnCreate() is:
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);
}
I still can't see what is the problem here
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;
}
}
Upvotes: 1
Views: 1935
Reputation: 4307
The compiler doesn't check whether the classes referenced in the layout XML files exists, so it is normal to only get the error at runtime.
Most likely the com.XXX.ui.NavigationBar
class doesn't exist on your classpath. Check your package names, maybe it's just a typo, or maybe you forgot to change the package names in the XML file after a package name refactor on the NavigationBar
class.
Upvotes: 2
Reputation: 95588
Errors are all here:
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
Post the code from your MainIWrapper.onCreate() and have a look at line 43 in your XML for NavigationBar.
Upvotes: 0