when i am running my project it will show the following message on log cat please help me. i have cleaned project many times. and i am using rest Templates.
06-06 14:08:42.251: ERROR/AndroidRuntime(432): FATAL EXCEPTION: main
06-06 14:08:42.251: ERROR/AndroidRuntime(432): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{org.shopzilla.android.common/org.shopzilla.android.common.MainActivity}: java.lang.ClassNotFoundException: org.shopzilla.android.common.MainActivity in loader dalvik.system.PathClassLoader[/data/app/org.shopzilla.android.common-2.apk]
06-06 14:08:42.251: ERROR/AndroidRuntime(432): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1569)
06-06 14:08:42.251: ERROR/AndroidRuntime(432): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
06-06 14:08:42.251: ERROR/AndroidRuntime(432): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
06-06 14:08:42.251: ERROR/AndroidRuntime(432): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
06-06 14:08:42.251: ERROR/AndroidRuntime(432): at android.os.Handler.dispatchMessage(Handler.java:99)
06-06 14:08:42.251: ERROR/AndroidRuntime(432): at android.os.Looper.loop(Looper.java:123)
06-06 14:08:42.251: ERROR/AndroidRuntime(432): at android.app.ActivityThread.main(ActivityThread.java:3683)
06-06 14:08:42.251: ERROR/AndroidRuntime(432): at java.lang.reflect.Method.invokeNative(Native Method)
06-06 14:08:42.251: ERROR/AndroidRuntime(432): at java.lang.reflect.Method.invoke(Method.java:507)
06-06 14:08:42.251: ERROR/AndroidRuntime(432): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
06-06 14:08:42.251: ERROR/AndroidRuntime(432): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
06-06 14:08:42.251: ERROR/AndroidRuntime(432): at dalvik.system.NativeStart.main(Native Method)
06-06 14:08:42.251: ERROR/AndroidRuntime(432): Caused by: java.lang.ClassNotFoundException: org.shopzilla.android.common.MainActivity in loader dalvik.system.PathClassLoader[/data/app/org.shopzilla.android.common-2.apk]
06-06 14:08:42.251: ERROR/AndroidRuntime(432): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240)
06-06 14:08:42.251: ERROR/AndroidRuntime(432): at java.lang.ClassLoader.loadClass(ClassLoader.java:551)
06-06 14:08:42.251: ERROR/AndroidRuntime(432): at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
06-06 14:08:42.251: ERROR/AndroidRuntime(432): at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
06-06 14:08:42.251: ERROR/AndroidRuntime(432): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1561)
*Manifest File is *
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.shopzilla.android.common"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".MainActivity" android:theme="@android:style/Theme.NoTitleBar" android:screenOrientation="portrait"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="org.shopzilla.android.search.SearchTabActivity" android:theme="@android:style/Theme.NoTitleBar" android:screenOrientation="portrait"></activity>
<activity android:name="org.shopzilla.android.Barcode.BarcodeTabActivity" android:theme="@android:style/Theme.NoTitleBar" android:screenOrientation="portrait"></activity>
<activity android:name="org.shopzilla.android.favorites.MyFavoritesTabActivity" android:theme="@android:style/Theme.NoTitleBar" android:screenOrientation="portrait"></activity>
<activity android:name="org.shopzilla.android.search.SearchResultActivity" android:theme="@android:style/Theme.NoTitleBar" android:screenOrientation="portrait"></activity>
<activity android:name="org.shopzilla.android.search.SearchSuggestionActivity" android:theme="@android:style/Theme.NoTitleBar" android:screenOrientation="portrait"></activity>
<activity android:name="org.shopzilla.android.search.SearchGridActivity" android:theme="@android:style/Theme.NoTitleBar" android:screenOrientation="portrait"></activity>
<activity android:name="org.shopzilla.android.search.SearchRefine" android:theme="@android:style/Theme.Translucent.NoTitleBar" android:screenOrientation="portrait"></activity>
<activity android:name="org.shopzilla.android.product.ProductComparisonActivity" android:theme="@android:style/Theme.NoTitleBar" android:screenOrientation="portrait"></activity>
<activity android:name="org.shopzilla.android.product.ProductDetailActivity" android:theme="@android:style/Theme.NoTitleBar" android:screenOrientation="portrait"></activity>
<activity android:name="org.shopzilla.android.product.ProductShareActivity" android:theme="@android:style/Theme.Translucent.NoTitleBar" android:screenOrientation="portrait"></activity>
<activity android:name="org.shopzilla.android.product.ProductZoomActivity" android:theme="@android:style/Theme.Translucent.NoTitleBar" android:screenOrientation="portrait"></activity>
<activity android:name="org.shopzilla.android.moretab.SettingActivity" android:theme="@android:style/Theme.NoTitleBar" android:screenOrientation="portrait"></activity>
<activity android:name="org.shopzilla.android.moretab.AboutActivity" android:theme="@android:style/Theme.NoTitleBar" android:screenOrientation="portrait"></activity>
<activity android:name="org.shopzilla.android.moretab.PrivacyPolicyActivity" android:theme="@android:style/Theme.NoTitleBar" android:screenOrientation="portrait"></activity>
<activity android:name="org.shopzilla.android.favorites.MyfavoritesTabActivity" android:theme="@android:style/Theme.NoTitleBar" android:screenOrientation="portrait"></activity>
<activity android:name="org.shopzilla.android.facebook.FacebookActivity" android:theme="@android:style/Theme.NoTitleBar" android:screenOrientation="portrait"></activity>
<activity android:name="org.shopzilla.android.moretab.More" android:theme="@android:style/Theme.Translucent.NoTitleBar" android:screenOrientation="portrait"></activity>
<activity android:name="com.google.zxing.client.android.CaptureActivity"
android:screenOrientation="landscape"
android:configChanges="orientation|keyboardHidden"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
android:windowSoftInputMode="stateAlwaysHidden">
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
</intent-filter>
<intent-filter>
<action android:name="com.google.zxing.client.android.SCAN"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
<!-- Allow web apps to launch Barcode Scanner by linking to http://zxing.appspot.com/scan. -->
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
<data android:scheme="http" android:host="zxing.appspot.com" android:path="/scan"/>
</intent-filter>
<!-- We also support a Google Product Search URL. -->
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
<data android:scheme="http" android:host="www.google.com" android:path="/m/products/scan"/>
</intent-filter>
<!-- And the UK version. -->
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
<data android:scheme="http" android:host="www.google.co.uk" android:path="/m/products/scan"/>
</intent-filter>
</activity>
<activity android:name="com.google.zxing.client.android.PreferencesActivity"
android:label="@string/preferences_name">
</activity>
<activity android:name="com.google.zxing.client.android.encode.EncodeActivity">
<intent-filter>
<action android:name="com.google.zxing.client.android.ENCODE"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
<!-- This allows us to handle the Share button in Contacts. -->
<intent-filter>
<action android:name="android.intent.action.SEND"/>
<category android:name="android.intent.category.DEFAULT"/>
<data android:mimeType="text/x-vcard"/>
</intent-filter>
</activity>
<activity android:name="com.google.zxing.client.android.book.SearchBookContentsActivity"
android:label="@string/sbc_name"
android:screenOrientation="landscape"
android:configChanges="orientation|keyboardHidden">
<intent-filter>
<action android:name="com.google.zxing.client.android.SEARCH_BOOK_CONTENTS"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
<activity android:name="com.google.zxing.client.android.wifi.WifiActivity"
android:label="@string/wa_name"
android:screenOrientation="landscape"
android:configChanges="orientation|keyboardHidden">
</activity>
<activity android:name="com.google.zxing.client.android.share.ShareActivity"
android:label="@string/share_name"
android:screenOrientation="user">
<intent-filter>
<action android:name="com.google.zxing.client.android.SHARE"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
<activity android:name="com.google.zxing.client.android.share.BookmarkPickerActivity"
android:label="@string/bookmark_picker_name">
<intent-filter>
<action android:name="android.intent.action.PICK"/>
开发者_开发知识库 <category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
<activity android:name="com.google.zxing.client.android.share.AppPickerActivity"
android:label="@string/app_picker_name">
<intent-filter>
<action android:name="android.intent.action.PICK"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
<activity android:name="com.google.zxing.client.android.HelpActivity"
android:screenOrientation="user">
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
</application>
<uses-permission android:name="android.permission.CAMERA"/>
<uses-permission android:name="android.permission.READ_CONTACTS"/>
<uses-permission android:name="android.permission.WRITE_CONTACTS"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="com.android.browser.permission.READ_HISTORY_BOOKMARKS"/>
<uses-permission android:name="android.permission.VIBRATE"/>
<uses-permission android:name="android.permission.FLASHLIGHT"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<!-- Wifi related -->
<uses-permission android:name="android.permission.WRITE_SETTINGS" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"></uses-permission>
</manifest>
On Create code is
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button btn = (Button)findViewById(R.id.btn_Search);
Button btn_scanbar = (Button)findViewById(R.id.btn_ScanBar);
txt_search = (TextView)findViewById(R.id.txt_Search);
recent.add(txt_search.getText().toString());
keyword= txt_search.getText().toString();
//Open Search Result Activity
showDialog(0);
btn.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
// TODO Auto-generated method stub
Intent intent = new Intent(MainActivity.this,SearchResultActivity.class);
intent.putExtra("keyword",txt_search.getText().toString());
startActivity(intent);
}
});
//Open Scan BarCode Activity
btn_scanbar.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
// TODO Auto-generated method stub
Intent intent = new Intent(MainActivity.this,CaptureActivity.class);
startActivity(intent);
}
});
//Geo Coding
this.locationManager =
(LocationManager) getSystemService(Context.LOCATION_SERVICE);
// Subscribe to the location manager's updates on the current location
this.locationManager.requestLocationUpdates("gps", (long)30000, (float) 10.0, new LocationListener()
{
public void onLocationChanged(Location arg0)
{
handleLocationChanged(arg0);
}
public void onProviderDisabled(String arg0) {
// TODO Auto-generated method stub
}
public void onProviderEnabled(String arg0) {
// TODO Auto-generated method stub
}
public void onStatusChanged(String arg0, int arg1, Bundle arg2) {
// TODO Auto-generated method stub
}
});
make sure that the package of your activity MainActivity
is really org.shopzilla.android.common
.
<activity android:name="yourPackage.MainActivity" />
Try adding this to your manifest element in AndroidManifest.xml
package="org.shopzilla.android.common"
You probably refactor the package of your Class MainActivity.
Looking at your manifest you are saying that your MainActivity class is at "org.shopzilla.android.common" are you sure of that??
In the Manifest.xml try to put the entire package for the MainActivity.
<activity
android:name="YOURPACKAGE.MainActivity"
android:theme="@android:style/Theme.NoTitleBar"
android:screenOrientation="portrait"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
If you have a Context variable e.g. Context context = getApplicationContext();
before your onCreate()
then it will cause the same error it just happened to me and I just fixed it by moving that into the onCreate()
method. Hope this Helps
精彩评论