I'm getting a force close every time I try to start a FragmentActivity from an Activity using an Intent. Here's the code from the Activity:
Intent intent = new Intent(getApplicationContext(), OrgHome.class);
intent.putExtra("Username", organization_name.getText().toString());
startActivity(intent);
And here's the logcat:
08-01 16:52:45.823: E/AndroidRuntime(600): FATAL EXCEPTION: main
08-01 16:52:45.823: E/AndroidRuntime(600): java.lang.NoClassDefFoundError: com.project3.organizations.OrgHome
08-01 16:52:45.823: E/AndroidRuntime(600): at com.project3.organizations.MainActivity$1$1.mobDBResponse(MainActivity.java:76)
08-01 16:52:45.823: E/AndroidRuntime(600): at com.mobdb.android.MobDBRequest.onPostExecute(MobDBRequest.java:78)
08-01 16:52:45.823: E/AndroidRuntime(600): at com.mobdb.android.MobDBRequest.onPostExecute(MobDBRequest.java:1)
08-01 16:52:45.823: E/AndroidRuntime(600): at android.os.AsyncTask.finish(AsyncTask.java:417)
08-01 16:52:45.823: E/AndroidRuntime(600): at android.os.AsyncTask.access$300(AsyncTask.java:127)
08-01 16:52:45.823: E/AndroidRuntime(600): at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:429)
08-01 16:52:45.823: E/AndroidRuntime(600): at android.os.Handler.dispatchMessage(Handler.java:99)
08-01 16:52:45.823: E/AndroidRuntime(600): at android.os.Looper.loop(Looper.java:123)
08-01 16:52:45.823: E/AndroidRuntime(600): at android.app.ActivityThread.main(ActivityThread.java:3683)
08-01 16:52:45.823: E/AndroidRuntime(600): at java.lang.reflect.Method.invokeNative(Native Method)
08-01 16:52:45.823: E/AndroidRuntime(600): at java.lang.reflect.Method.invoke(Method.java:507)
08-01 16:52:45.823: E/AndroidRuntime(600): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
08-01 16:52:45.823: E/AndroidRuntime(600): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
08-01 16:52:45.823: E/AndroidRuntime(600): at dalvik.system.NativeStart.main(Native Method)
08-01 16:52:48.053: I/Process(600): Sending signal. PID: 600 SIG: 9
OrgHome.class is defined in the manifest correctly. What's going on here?
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.project3.organizations"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="15" />
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="#string/title_activity_main" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="OrgHome"></activity>
</application>
</manifest>
Change the manifest:
Use this if OrgHome is in the same place as MainActivity
<activity android:name=".OrgHome" />
Use this if it's in a sub-folder
<activity android:name=".sub.path.to.OrgHome" />
Or specify the whole path
<activity android:name="entire.path.to.OrgHome" />
for addressing the Fragment activities you should write (getactivity(),nameofOtherActivity.class); and you should be all right.
Related
Good evening and good week. We run this script from tutorial but my crash concept does not make an error in the code. nor to the errors refer to a particular line code. Please for your help.
Tutorial: http://gabesechansoftware.com/location-tracking/
01-26 15:36:06.751: I/Process(10528): Sending signal. PID: 10528 SIG: 9
01-26 15:36:18.251: D/AndroidRuntime(10613): Shutting down VM
01-26 15:36:18.251: W/dalvikvm(10613): threadid=1: thread exiting with uncaught exception (group=0x2b542210)
01-26 15:36:18.251: E/AndroidRuntime(10613): FATAL EXCEPTION: main
01-26 15:36:18.251: E/AndroidRuntime(10613): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{pack/pack.MainActivity}: java.lang.ClassNotFoundException: pack.MainActivity
01-26 15:36:18.251: E/AndroidRuntime(10613): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1891)
01-26 15:36:18.251: E/AndroidRuntime(10613): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1992)
01-26 15:36:18.251: E/AndroidRuntime(10613): at android.app.ActivityThread.access$600(ActivityThread.java:127)
01-26 15:36:18.251: E/AndroidRuntime(10613): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1158)
01-26 15:36:18.251: E/AndroidRuntime(10613): at android.os.Handler.dispatchMessage(Handler.java:99)
01-26 15:36:18.251: E/AndroidRuntime(10613): at android.os.Looper.loop(Looper.java:137)
01-26 15:36:18.251: E/AndroidRuntime(10613): at android.app.ActivityThread.main(ActivityThread.java:4441)
01-26 15:36:18.251: E/AndroidRuntime(10613): at java.lang.reflect.Method.invokeNative(Native Method)
01-26 15:36:18.251: E/AndroidRuntime(10613): at java.lang.reflect.Method.invoke(Method.java:511)
01-26 15:36:18.251: E/AndroidRuntime(10613): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
01-26 15:36:18.251: E/AndroidRuntime(10613): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
01-26 15:36:18.251: E/AndroidRuntime(10613): at dalvik.system.NativeStart.main(Native Method)
01-26 15:36:18.251: E/AndroidRuntime(10613): Caused by: java.lang.ClassNotFoundException: pack.MainActivity
01-26 15:36:18.251: E/AndroidRuntime(10613): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
01-26 15:36:18.251: E/AndroidRuntime(10613): at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
01-26 15:36:18.251: E/AndroidRuntime(10613): at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
01-26 15:36:18.251: E/AndroidRuntime(10613): at android.app.Instrumentation.newActivity(Instrumentation.java:1023)
01-26 15:36:18.251: E/AndroidRuntime(10613): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1882)
01-26 15:36:18.251: E/AndroidRuntime(10613): ... 11 more
01-26 15:41:18.281: I/Process(10613): Sending signal. PID: 10613 SIG: 9
Manifest
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="my.pack"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="24" />
<permission
android:name="my.pack.permission.MAPS_RECEIVE"
android:protectionLevel="signature"/>
<uses-permission android:name="my.pack.permission.MAPS_RECEIVE"/>
<uses-permission android:name="permission_name"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-feature
android:glEsVersion="0x00020000"
android:required="true"/>
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="My api key"/>
<activity
android:name=".MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
You full activity name (package + class) is not the same in manifest and code. There's pack.MainActivity declared in manifest but it is not found in code.
This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 10 years ago.
I know there are many people who have the problem. I've tried many ways I can find, however still get the error.
there's only one activity and it's registered.
tried to complete .MainActivity by com.hermione.woodenfish.MainActivity, no use
clean and rebuild don't work either
really need help, thanks!!
LogCat:
08-01 12:09:33.944: E/Trace(1032): error opening trace file: No such file or directory (2)
08-01 12:09:34.384: D/AndroidRuntime(1032): Shutting down VM
08-01 12:09:34.424: W/dalvikvm(1032): threadid=1: thread exiting with uncaught exception (group=0x40a13300)
08-01 12:09:34.465: E/AndroidRuntime(1032): FATAL EXCEPTION: main
08-01 12:09:34.465: E/AndroidRuntime(1032): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.hermione.woodenfish/com.hermione.woodenfish.MainActivity}: java.lang.NullPointerException
08-01 12:09:34.465: E/AndroidRuntime(1032): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1983)
08-01 12:09:34.465: E/AndroidRuntime(1032): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
08-01 12:09:34.465: E/AndroidRuntime(1032): at android.app.ActivityThread.access$600(ActivityThread.java:130)
08-01 12:09:34.465: E/AndroidRuntime(1032): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
08-01 12:09:34.465: E/AndroidRuntime(1032): at android.os.Handler.dispatchMessage(Handler.java:99)
08-01 12:09:34.465: E/AndroidRuntime(1032): at android.os.Looper.loop(Looper.java:137)
08-01 12:09:34.465: E/AndroidRuntime(1032): at android.app.ActivityThread.main(ActivityThread.java:4745)
08-01 12:09:34.465: E/AndroidRuntime(1032): at java.lang.reflect.Method.invokeNative(Native Method)
08-01 12:09:34.465: E/AndroidRuntime(1032): at java.lang.reflect.Method.invoke(Method.java:511)
08-01 12:09:34.465: E/AndroidRuntime(1032): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
08-01 12:09:34.465: E/AndroidRuntime(1032): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
08-01 12:09:34.465: E/AndroidRuntime(1032): at dalvik.system.NativeStart.main(Native Method)
08-01 12:09:34.465: E/AndroidRuntime(1032): Caused by: java.lang.NullPointerException
08-01 12:09:34.465: E/AndroidRuntime(1032): at android.content.ContextWrapper.getResources(ContextWrapper.java:81)
08-01 12:09:34.465: E/AndroidRuntime(1032): at android.media.MediaPlayer.create(MediaPlayer.java:824)
08-01 12:09:34.465: E/AndroidRuntime(1032): at com.hermione.woodenfish.MainActivity.<init>(MainActivity.java:24)
08-01 12:09:34.465: E/AndroidRuntime(1032): at java.lang.Class.newInstanceImpl(Native Method)
08-01 12:09:34.465: E/AndroidRuntime(1032): at java.lang.Class.newInstance(Class.java:1319)
08-01 12:09:34.465: E/AndroidRuntime(1032): at android.app.Instrumentation.newActivity(Instrumentation.java:1053)
08-01 12:09:34.465: E/AndroidRuntime(1032): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1974)
08-01 12:09:34.465: E/AndroidRuntime(1032): ... 11 more
08-01 12:33:02.784: E/Trace(1171): error opening trace file: No such file or directory (2)
08-01 12:33:03.125: D/AndroidRuntime(1171): Shutting down VM
08-01 12:33:03.125: W/dalvikvm(1171): threadid=1: thread exiting with uncaught exception (group=0x40a13300)
08-01 12:33:03.154: E/AndroidRuntime(1171): FATAL EXCEPTION: main
08-01 12:33:03.154: E/AndroidRuntime(1171): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.hermione.woodenfish/com.hermione.woodenfish.MainActivity}: java.lang.NullPointerException
08-01 12:33:03.154: E/AndroidRuntime(1171): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1983)
08-01 12:33:03.154: E/AndroidRuntime(1171): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
08-01 12:33:03.154: E/AndroidRuntime(1171): at android.app.ActivityThread.access$600(ActivityThread.java:130)
08-01 12:33:03.154: E/AndroidRuntime(1171): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
08-01 12:33:03.154: E/AndroidRuntime(1171): at android.os.Handler.dispatchMessage(Handler.java:99)
08-01 12:33:03.154: E/AndroidRuntime(1171): at android.os.Looper.loop(Looper.java:137)
08-01 12:33:03.154: E/AndroidRuntime(1171): at android.app.ActivityThread.main(ActivityThread.java:4745)
08-01 12:33:03.154: E/AndroidRuntime(1171): at java.lang.reflect.Method.invokeNative(Native Method)
08-01 12:33:03.154: E/AndroidRuntime(1171): at java.lang.reflect.Method.invoke(Method.java:511)
08-01 12:33:03.154: E/AndroidRuntime(1171): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
08-01 12:33:03.154: E/AndroidRuntime(1171): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
08-01 12:33:03.154: E/AndroidRuntime(1171): at dalvik.system.NativeStart.main(Native Method)
08-01 12:33:03.154: E/AndroidRuntime(1171): Caused by: java.lang.NullPointerException
08-01 12:33:03.154: E/AndroidRuntime(1171): at android.content.ContextWrapper.getResources(ContextWrapper.java:81)
08-01 12:33:03.154: E/AndroidRuntime(1171): at android.media.MediaPlayer.create(MediaPlayer.java:824)
08-01 12:33:03.154: E/AndroidRuntime(1171): at com.hermione.woodenfish.MainActivity.<init>(MainActivity.java:23)
08-01 12:33:03.154: E/AndroidRuntime(1171): at java.lang.Class.newInstanceImpl(Native Method)
08-01 12:33:03.154: E/AndroidRuntime(1171): at java.lang.Class.newInstance(Class.java:1319)
08-01 12:33:03.154: E/AndroidRuntime(1171): at android.app.Instrumentation.newActivity(Instrumentation.java:1053)
08-01 12:33:03.154: E/AndroidRuntime(1171): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1974)
08-01 12:33:03.154: E/AndroidRuntime(1171): ... 11 more
MainActivity.java
package com.hermione.woodenfish;
import android.app.Activity;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
public class MainActivity extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
private MediaPlayer mp = MediaPlayer.create(this, R.raw.knok);
public void sendKnok(View view) {
if (mp.isPlaying()){
mp.stop();
}
mp.start();
}
}
Manifest:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.hermione.woodenfish"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="15" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="#string/title_activity_main" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
I think the problem is here in this line,
private MediaPlayer mp = MediaPlayer.create(this, R.raw.knok);
You have tried to initialize the Context object before the onCreate(). This might be creating the problem. How about you Initialize your MediaPlayer inside your onCreate(),
private MediaPlayer mp =null; //Global Declaration
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mp = MediaPlayer.create(this, R.raw.knok);
}
Your problem is here:
08-01 12:33:03.154: E/AndroidRuntime(1171): Caused by: java.lang.NullPointerException
08-01 12:33:03.154: E/AndroidRuntime(1171): at android.content.ContextWrapper.getResources(ContextWrapper.java:81)
08-01 12:33:03.154: E/AndroidRuntime(1171): at android.media.MediaPlayer.create(MediaPlayer.java:824)
08-01 12:33:03.154: E/AndroidRuntime(1171): at com.hermione.woodenfish.MainActivity.<init>(MainActivity.java:23)
08-01 12:33:03.154: E/AndroidRuntime(1171): at java.lang.Class.newInstanceImpl(Native Method)
08-01 12:33:03.154: E/AndroidRuntime(1171): at java.lang.Class.newInstance(Class.java:1319)
08-01 12:33:03.154: E/AndroidRuntime(1171): at android.app.Instrumentation.newActivity(Instrumentation.java:1053)
08-01 12:33:03.154: E/AndroidRuntime(1171): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1974)
08-01 12:33:03.154: E/AndroidRuntime(1171): ... 11 more
You're getting a NullPointerException. Look at line 23 in MainActivity in debug and see what's happening.
Can someone please tell me how to fix my problem? I'm building my first android app and below is the error codes I get when application is launched in Emulator.
Thank you
04-12 21:07:03.480: D/AndroidRuntime(327): Shutting down VM
04-12 21:07:03.480: W/dalvikvm(327): threadid=1: thread exiting with uncaught exception(group=0x40015560)
04-12 21:07:03.580: E/AndroidRuntime(327): FATAL EXCEPTION: main
04-12 21:07:03.580: E/AndroidRuntime(327): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{obd.gss.namespace/obd.gss.namespace.activity.Gssobdreadermainactivity}: java.lang.ClassNotFoundException: obd.gss.namespace.activity.Gssobdreadermainactivity in loader dalvik.system.PathClassLoader[/data/app/obd.gss.namespace-1.apk]
04-12 21:07:03.580: E/AndroidRuntime(327): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1569)
04-12 21:07:03.580: E/AndroidRuntime(327): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
04-12 21:07:03.580: E/AndroidRuntime(327): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
04-12 21:07:03.580: E/AndroidRuntime(327): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
04-12 21:07:03.580: E/AndroidRuntime(327): at android.os.Handler.dispatchMessage(Handler.java:99)
04-12 21:07:03.580: E/AndroidRuntime(327): at android.os.Looper.loop(Looper.java:123)
04-12 21:07:03.580: E/AndroidRuntime(327): at android.app.ActivityThread.main(ActivityThread.java:3683)
04-12 21:07:03.580: E/AndroidRuntime(327): at java.lang.reflect.Method.invokeNative(Native Method)
04-12 21:07:03.580: E/AndroidRuntime(327): at java.lang.reflect.Method.invoke(Method.java:507)
04-12 21:07:03.580: E/AndroidRuntime(327): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
04-12 21:07:03.580: E/AndroidRuntime(327): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
04-12 21:07:03.580: E/AndroidRuntime(327): at dalvik.system.NativeStart.main(Native Method)
04-12 21:07:03.580: E/AndroidRuntime(327): Caused by: java.lang.ClassNotFoundException: obd.gss.namespace.activity.Gssobdreadermainactivity in loader dalvik.system.PathClassLoader[/data/app/obd.gss.namespace-1.apk]
04-12 21:07:03.580: E/AndroidRuntime(327): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240)
04-12 21:07:03.580: E/AndroidRuntime(327): at java.lang.ClassLoader.loadClass(ClassLoader.java:551)
04-12 21:07:03.580: E/AndroidRuntime(327): at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
04-12 21:07:03.580: E/AndroidRuntime(327): at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
04-12 21:07:03.580: E/AndroidRuntime(327): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1561)
04-12 21:07:03.580: E/AndroidRuntime(327): ... 11 more
Here are the contents of my manifest:
<uses-sdk android:minSdkVersion="10" />
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<uses-permission android:name="android.permission.BLUETOOTH"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION"></uses-permission>
<uses-permission android:name="android.permission.CONTROL_LOCATION_UPDATES"></uses-permission>
<uses-permission android:name="android.permission.WAKE_LOCK"></uses-permission>
<application
android:icon="#drawable/icon"
android:label="#string/app_name">
<activity android:name=".Activity.Gssobdreadermainactivity"
android:label="#string/app_name"
android:screenOrientation="portrait"
android:launchMode="singleInstance">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".Activity.Gssobdreaderconfigactivity"
android:label="#string/app_name">
</activity>
<activity android:name=".activity.Gssobdreadercommandactivity"
android:label="#string/app_name"
android:screenOrientation="portrait">
</activity>
<service android:name="io.GssobdReaderService"/>
</application>
The cause of your problem is:
java.lang.ClassNotFoundException: obd.gss.namespace.activity.Gssobdreadermainactivity
Did you forget to add your Activity to your manifest?
Your Manifest should look something like:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="obd.gss.namespace"
android:versionCode="1"
android:versionName="1.0" >
<!-- permissions and other stuff here -->
<application
android:icon="#drawable/icon"
android:label="#string/app_name">
<activity android:name=".activity.Gssobdreadermainactivity"
android:label="#string/app_name"
android:screenOrientation="portrait"
android:launchMode="singleInstance">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<!--more activities and services here -->
</application>
</manifest>
Note that the combination of the manifest tag's package attribute and the activity tag's name attribute should be exactly the same as the fully qualified name of your class. Using my above example, you would wind up with:
obd.gss.namespace.activity.Gssobdreadermainactivity
I've had a similar issue, particularly with newly imported projects. The closest thing to a solution I've found is to make sure the .classpath file is writable, restart Eclipse(or whichever IDE you use), refresh the project, clean and build the project and try again. This doesn't always fix it, but doing it a couple times usually makes the error go away for me. The essence of the error is that the Android OS can't find the Activity, although it does know that the Activity should exist and is trying to launch it.
What does your source tree look like? You probably need to remove the .activity. and .Activity. prefixes from your applications fully quallified class name. Unless, of course, you have an "activity" and an "Activity" folder in your source tree (=
I want to use the GreenDroid library in my application.
I added it as a library in the project settings.
My XML:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.korn.tvbrain"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="7" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/Theme.GreenDroid"
android:name=".TVBrainApplication">>
<activity
android:label="#string/app_name"
android:name=".TVBrainActivity" >
<intent-filter >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
TVBrainActivity:
public class TVBrainActivity extends GDActivity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setActionBarContentView(R.layout.gd_action_bar_empty);
}
}
Application Class:
public class AppBrainApplication extends GDApplication{
#Override
public Class<?> getHomeActivityClass() {
return AppBrainApplication.class;
}
}
Error Log:
10-24 10:25:55.265: E/AndroidRuntime(524): Uncaught handler: thread main exiting due to uncaught exception
10-24 10:25:55.295: E/AndroidRuntime(524): java.lang.RuntimeException: Unable to instantiate application com.korn.tvbrain.TVBrainApplication: java.lang.ClassNotFoundException: com.korn.tvbrain.TVBrainApplication in loader dalvik.system.PathClassLoader#44bfd908
10-24 10:25:55.295: E/AndroidRuntime(524): at android.app.ActivityThread$PackageInfo.makeApplication(ActivityThread.java:523)
10-24 10:25:55.295: E/AndroidRuntime(524): at android.app.ActivityThread.handleBindApplication(ActivityThread.java:3996)
10-24 10:25:55.295: E/AndroidRuntime(524): at android.app.ActivityThread.access$2900(ActivityThread.java:119)
10-24 10:25:55.295: E/AndroidRuntime(524): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1901)
10-24 10:25:55.295: E/AndroidRuntime(524): at android.os.Handler.dispatchMessage(Handler.java:99)
10-24 10:25:55.295: E/AndroidRuntime(524): at android.os.Looper.loop(Looper.java:123)
10-24 10:25:55.295: E/AndroidRuntime(524): at android.app.ActivityThread.main(ActivityThread.java:4363)
10-24 10:25:55.295: E/AndroidRuntime(524): at java.lang.reflect.Method.invokeNative(Native Method)
10-24 10:25:55.295: E/AndroidRuntime(524): at java.lang.reflect.Method.invoke(Method.java:521)
10-24 10:25:55.295: E/AndroidRuntime(524): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
10-24 10:25:55.295: E/AndroidRuntime(524): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
10-24 10:25:55.295: E/AndroidRuntime(524): at dalvik.system.NativeStart.main(Native Method)
10-24 10:25:55.295: E/AndroidRuntime(524): Caused by: java.lang.ClassNotFoundException: com.korn.tvbrain.TVBrainApplication in loader dalvik.system.PathClassLoader#44bfd908
10-24 10:25:55.295: E/AndroidRuntime(524): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:243)
10-24 10:25:55.295: E/AndroidRuntime(524): at java.lang.ClassLoader.loadClass(ClassLoader.java:573)
10-24 10:25:55.295: E/AndroidRuntime(524): at java.lang.ClassLoader.loadClass(ClassLoader.java:532)
10-24 10:25:55.295: E/AndroidRuntime(524): at android.app.Instrumentation.newApplication(Instrumentation.java:942)
10-24 10:25:55.295: E/AndroidRuntime(524): at android.app.ActivityThread$PackageInfo.makeApplication(ActivityThread.java:518)
10-24 10:25:55.295: E/AndroidRuntime(524): ... 11 more
I always get a ClassNotFound Exception.
In application tag in AndroidManifest file I guess android:name=".TVBrainApplication" here the name should be android:name=".AppBrainApplication"
It looks like you should add android:name=".AppBrainApplication" instead of android:name=".TVBrainApplication" in your AndroidManifest
I have recently taken up Android Development and I was looking to using the WebView display webpages. I picked up from the sample that was given on Google site and for some reason the emulator kept saying page was not available. I searched in StackOverflow and found links relating to WebViewClient. I tried that also but no luck there, I have checked multiple times about the manifest entry for internet permission and its there. As a test I ran the browser available within the emulator and sure enough my firewall popped up a question on whether to allow it access or not. The pop up never came to me when I was running it from program. The code that I have is what is there Google pages
mWebView = (WebView) findViewById(R.id.webview);
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.loadUrl("http://www.google.com");
mWebView.setWebViewClient(new HelloWebViewClient());
private class HelloWebViewClient extends WebViewClient {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
I tried loading simple html directly using loadData and it worked fine. I am at loss as to what is happening and how this can be resolved. I would appreciate any help on this.
Adding the Android Manifest here
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.hellowebview"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="8" />
<application android:icon="#drawable/icon" android:label="#string/app_name">
<activity android:name=".HelloWebView"
android:label="#string/app_name"
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>
<uses-permission android:name="android.permission.INTERNET" />
</application>
</manifest>
To check if its just a WebView thingy, I tried accessing the internet using httpGet and httpResonse classes and got the same problem, the code was not able to connect to the given site. It failed stating the below
05-10 00:37:53.191: WARN/System.err(294): java.net.UnknownHostException: feeds.feedburner.com
05-10 00:37:53.230: WARN/System.err(294): at java.net.InetAddress.lookupHostByName(InetAddress.java:513)
05-10 00:37:53.230: WARN/System.err(294): at java.net.InetAddress.getAllByNameImpl(InetAddress.java:278)
05-10 00:37:53.230: WARN/System.err(294): at java.net.InetAddress.getAllByName(InetAddress.java:242)
05-10 00:37:53.250: WARN/System.err(294): at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:136)
05-10 00:37:53.250: WARN/System.err(294): at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164)
05-10 00:37:53.250: WARN/System.err(294): at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119)
05-10 00:37:53.271: WARN/System.err(294): at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:348)
05-10 00:37:53.271: WARN/System.err(294): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
05-10 00:37:53.280: WARN/System.err(294): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
05-10 00:37:53.291: WARN/System.err(294): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465)
05-10 00:37:53.301: WARN/System.err(294): at com.example.hellowebview.HelloWebView.onCreate(HelloWebView.java:43)
05-10 00:37:53.301: WARN/System.err(294): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
05-10 00:37:53.309: WARN/System.err(294): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
05-10 00:37:53.322: WARN/System.err(294): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
05-10 00:37:53.330: WARN/System.err(294): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
05-10 00:37:53.340: WARN/System.err(294): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
05-10 00:37:53.350: WARN/System.err(294): at android.os.Handler.dispatchMessage(Handler.java:99)
05-10 00:37:53.350: WARN/System.err(294): at android.os.Looper.loop(Looper.java:123)
05-10 00:37:53.361: WARN/System.err(294): at android.app.ActivityThread.main(ActivityThread.java:4627)
05-10 00:37:53.361: WARN/System.err(294): at java.lang.reflect.Method.invokeNative(Native Method)
05-10 00:37:53.372: WARN/System.err(294): at java.lang.reflect.Method.invoke(Method.java:521)
05-10 00:37:53.380: WARN/System.err(294): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
05-10 00:37:53.380: WARN/System.err(294): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
05-10 00:37:53.401: WARN/System.err(294): at dalvik.system.NativeStart.main(Native Method)
05-10 00:37:56.773: WARN/ActivityManager(58): Launch timeout has expired, giving up wake lock!
05-10 00:37:58.083: WARN/ActivityManager(58): Activity idle timeout for HistoryRecord{44fc9108 com.example.hellowebview/.HelloWebView}
05-10 00:38:06.300: DEBUG/KeyguardViewMediator(58): pokeWakelock(5000)
05-10 00:38:06.651: INFO/ARMAssembler(58): generated scanline__00000077:03545404_00000004_00000000 [ 47 ipp] (67 ins) at [0x3724c8:0x3725d4] in 7266287 ns
05-10 00:38:06.720: INFO/ARMAssembler(58): generated scanline__00000177:03515104_00001001_00000000 [ 91 ipp] (114 ins) at [0x371380:0x371548] in 1486222 ns
05-10 00:38:30.430: DEBUG/AndroidRuntime(294): Shutting down VM
05-10 00:38:30.430: WARN/dalvikvm(294): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
05-10 00:38:30.752: ERROR/AndroidRuntime(294): FATAL EXCEPTION: main
05-10 00:38:30.752: ERROR/AndroidRuntime(294): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.hellowebview/com.example.hellowebview.HelloWebView}: java.lang.NullPointerException
05-10 00:38:30.752: ERROR/AndroidRuntime(294): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
05-10 00:38:30.752: ERROR/AndroidRuntime(294): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
05-10 00:38:30.752: ERROR/AndroidRuntime(294): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
05-10 00:38:30.752: ERROR/AndroidRuntime(294): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
05-10 00:38:30.752: ERROR/AndroidRuntime(294): at android.os.Handler.dispatchMessage(Handler.java:99)
05-10 00:38:30.752: ERROR/AndroidRuntime(294): at android.os.Looper.loop(Looper.java:123)
05-10 00:38:30.752: ERROR/AndroidRuntime(294): at android.app.ActivityThread.main(ActivityThread.java:4627)
05-10 00:38:30.752: ERROR/AndroidRuntime(294): at java.lang.reflect.Method.invokeNative(Native Method)
05-10 00:38:30.752: ERROR/AndroidRuntime(294): at java.lang.reflect.Method.invoke(Method.java:521)
05-10 00:38:30.752: ERROR/AndroidRuntime(294): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
05-10 00:38:30.752: ERROR/AndroidRuntime(294): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
05-10 00:38:30.752: ERROR/AndroidRuntime(294): at dalvik.system.NativeStart.main(Native Method)
05-10 00:38:30.752: ERROR/AndroidRuntime(294): Caused by: java.lang.NullPointerException
05-10 00:38:30.752: ERROR/AndroidRuntime(294): at com.example.hellowebview.HelloWebView.onCreate(HelloWebView.java:51)
05-10 00:38:30.752: ERROR/AndroidRuntime(294): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
05-10 00:38:30.752: ERROR/AndroidRuntime(294): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
05-10 00:38:30.752: ERROR/AndroidRuntime(294): ... 11 more
Got it. For some reason the order in which the permission is set matters a lot. I changed the order of my permission setting in manifest file and it worked. Here's the modified manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.hellowebview"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="8" />
<uses-permission android:name="android.permission.INTERNET" />
<application android:icon="#drawable/icon" android:label="#string/app_name">
<activity android:name=".HelloWebView"
android:label="#string/app_name"
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>
</application>
</manifest>
I am not sure what is the significance of this but would appreciate if anyone could elaborate.
Got it. For some reason the order in which the permission is set matters a lot. I changed the order of my permission setting in manifest file and it worked. Here's the modified manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.hellowebview"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="8" />
<uses-permission android:name="android.permission.INTERNET" />
<application android:icon="#drawable/icon" android:label="#string/app_name">
<activity android:name=".HelloWebView"
android:label="#string/app_name"
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>
</application>
</manifest>
mWebView = (WebView) findViewById(R.id.webview);
WebSettings setting =mWebView.getSettings();
mWebView.setWebViewClient(new WebViewClient() {
public boolean shouldOverrideUrlLoading(WebView view, String url) {
return true;
}
mWebView.loadUrl("http://www.google.com");
Use this code .shouldOverrideUrlLoading() not use compulsary.use this code and please reply me this code work or not
Your code looks fine. I would make sure internet is working correctly on the emulator by browsing a few pages on the Android Browser. I have had problems before where the emulator would lose network access.