I'm trying to build my Android plugin for Unity. But when I do, I get the follow error log in Logcat:
12-11 14:45:38.745: E/AndroidRuntime(26806): FATAL EXCEPTION: main
12-11 14:45:38.745: E/AndroidRuntime(26806): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.marc/com.example.marc.CompassActivity}: java.lang.ClassNotFoundException: Didn't find class "com.example.marc.CompassActivity" on path: DexPathList[[zip file "/data/app/com.example.marc-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.example.marc-1, /vendor/lib, /system/lib]]
12-11 14:45:38.745: E/AndroidRuntime(26806): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2137)
12-11 14:45:38.745: E/AndroidRuntime(26806): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
12-11 14:45:38.745: E/AndroidRuntime(26806): at android.app.ActivityThread.access$600(ActivityThread.java:141)
12-11 14:45:38.745: E/AndroidRuntime(26806): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
12-11 14:45:38.745: E/AndroidRuntime(26806): at android.os.Handler.dispatchMessage(Handler.java:99)
12-11 14:45:38.745: E/AndroidRuntime(26806): at android.os.Looper.loop(Looper.java:137)
12-11 14:45:38.745: E/AndroidRuntime(26806): at android.app.ActivityThread.main(ActivityThread.java:5103)
12-11 14:45:38.745: E/AndroidRuntime(26806): at java.lang.reflect.Method.invokeNative(Native Method)
12-11 14:45:38.745: E/AndroidRuntime(26806): at java.lang.reflect.Method.invoke(Method.java:525)
12-11 14:45:38.745: E/AndroidRuntime(26806): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
12-11 14:45:38.745: E/AndroidRuntime(26806): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
12-11 14:45:38.745: E/AndroidRuntime(26806): at dalvik.system.NativeStart.main(Native Method)
12-11 14:45:38.745: E/AndroidRuntime(26806): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.example.marc.CompassActivity" on path: DexPathList[[zip file "/data/app/com.example.marc-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.example.marc-1, /vendor/lib, /system/lib]]
12-11 14:45:38.745: E/AndroidRuntime(26806): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:53)
12-11 14:45:38.745: E/AndroidRuntime(26806): at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
12-11 14:45:38.745: E/AndroidRuntime(26806): at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
12-11 14:45:38.745: E/AndroidRuntime(26806): at android.app.Instrumentation.newActivity(Instrumentation.java:1061)
12-11 14:45:38.745: E/AndroidRuntime(26806): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2128)
12-11 14:45:38.745: E/AndroidRuntime(26806): ... 11 more
I did a search on to why this is happening and I discovered it is because of a problem with my intent. And that I needed to add my activity to my Manifest file. However, this is my manifest file:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.marc"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="7"
android:targetSdkVersion="7" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity android:name="com.example.marc.CompassActivity"
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>
And from what I can see, my intent is there in the line <activity android:name="com.example.marc.CompassActivity" unless my thinking behind this is entirely wrong?
Just for completions sake, here is my java file:
package com.example.marc;
import com.unity3d.player.UnityPlayerActivity;
import android.content.Context;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.os.Bundle;
import android.util.Config;
import android.util.Log;
import android.app.Activity;
public class CompassActivity extends UnityPlayerActivity
{
private static final String TAG = "Compass";
private SensorManager mSensorManager;
private Sensor mSensor;
static public float xmag;
static public float ymag;
static public float zmag;
private final SensorEventListener mListener = new SensorEventListener()
{
public void onSensorChanged(SensorEvent event)
{
if (Config.DEBUG) Log.d(TAG,
"sensorChanged (" + event.values[0] + ", " + event.values[1] + ", " + event.values[2] + ")");
xmag = event.values[0];
ymag = event.values[1];
zmag = event.values[2];
}
public void onAccuracyChanged(Sensor sensor, int accuracy)
{
}
};
#Override
protected void onCreate(Bundle icicle)
{
super.onCreate(icicle);
mSensorManager = (SensorManager)getSystemService(Context.SENSOR_SERVICE);
mSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_ORIENTATION);
}
#Override
protected void onResume()
{
if (Config.DEBUG) Log.d(TAG, "onResume");
super.onResume();
mSensorManager.registerListener(mListener, mSensor,
SensorManager.SENSOR_DELAY_GAME);
}
#Override
protected void onStop()
{
if (Config.DEBUG) Log.d(TAG, "onStop");
mSensorManager.unregisterListener(mListener);
super.onStop();
}
public static float getX()
{
return xmag;
}
public static float getY()
{
return ymag;
}
public static float getZ()
{
return zmag;
}
}
Again, as per my thinking, this is what I should be passing to my Manifest file, such, it is called "CompassActivity". Clearly though I must have done something wrong otherwise I wouldn't be getting the errors I am. Could someone please tell me what it is I am doing wrong / missing?
edit
Latest LogCat files:
12-11 16:32:16.957: E/AndroidRuntime(29055): FATAL EXCEPTION: main
12-11 16:32:16.957: E/AndroidRuntime(29055): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.marc/com.example.marc.CompassActivity}: java.lang.ClassNotFoundException: Didn't find class "com.example.marc.CompassActivity" on path: DexPathList[[zip file "/data/app/com.example.marc-2.apk"],nativeLibraryDirectories=[/data/app-lib/com.example.marc-2, /vendor/lib, /system/lib]]
12-11 16:32:16.957: E/AndroidRuntime(29055): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2137)
12-11 16:32:16.957: E/AndroidRuntime(29055): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
12-11 16:32:16.957: E/AndroidRuntime(29055): at android.app.ActivityThread.access$600(ActivityThread.java:141)
12-11 16:32:16.957: E/AndroidRuntime(29055): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
12-11 16:32:16.957: E/AndroidRuntime(29055): at android.os.Handler.dispatchMessage(Handler.java:99)
12-11 16:32:16.957: E/AndroidRuntime(29055): at android.os.Looper.loop(Looper.java:137)
12-11 16:32:16.957: E/AndroidRuntime(29055): at android.app.ActivityThread.main(ActivityThread.java:5103)
12-11 16:32:16.957: E/AndroidRuntime(29055): at java.lang.reflect.Method.invokeNative(Native Method)
12-11 16:32:16.957: E/AndroidRuntime(29055): at java.lang.reflect.Method.invoke(Method.java:525)
12-11 16:32:16.957: E/AndroidRuntime(29055): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
12-11 16:32:16.957: E/AndroidRuntime(29055): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
12-11 16:32:16.957: E/AndroidRuntime(29055): at dalvik.system.NativeStart.main(Native Method)
12-11 16:32:16.957: E/AndroidRuntime(29055): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.example.marc.CompassActivity" on path: DexPathList[[zip file "/data/app/com.example.marc-2.apk"],nativeLibraryDirectories=[/data/app-lib/com.example.marc-2, /vendor/lib, /system/lib]]
12-11 16:32:16.957: E/AndroidRuntime(29055): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:53)
12-11 16:32:16.957: E/AndroidRuntime(29055): at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
12-11 16:32:16.957: E/AndroidRuntime(29055): at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
12-11 16:32:16.957: E/AndroidRuntime(29055): at android.app.Instrumentation.newActivity(Instrumentation.java:1061)
12-11 16:32:16.957: E/AndroidRuntime(29055): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2128)
12-11 16:32:16.957: E/AndroidRuntime(29055): ... 11 more
I think
<activity android:name="com.example.marc.CompassActivity"
SHOULD BE
<activity android:name="CompassActivity"
(you already mentioned "com.example.marc" in package attribute
The value of android:name should be name of activity class only.
Since your manifest file says main activity class is "com.example.marc.CompassActivity", runtime environment looks for it , but it doesn't find it as your main activity class file is named as "CompassAcitvity")
[EDIT]
Main issue is that the runtime is unable to Instantiate the MainActivity because it is not able to find the class "com.example.marc.CompassActivity" in DexPathList
See method "findClass()" line 310-323
If a class is successfully found then a class object is returned other wise null it is returned to BaseDexClassLoader(see line 58) And ClassNotFoundException is thrown in case null is received which is happening in this case.
I think either main activity class is excluded during build process or it has some different name unlike mentioned in manifest.
Your UnityPlayerActivity class is not found actually but Compiler shows as CompassActivity not found.
If you have UnityPlayerActivity in library and that is linked to you app then double check that your Project-->Right Click-->Properties-->Java Build Path--->Order and Export has your project checked.
Following #TNR's answer - Your UnityPlayerActivity class is not found actually but LogCat shows as CompassActivity not found.
What you can try to do is:
Rebuild your project (just for testing) using the original UnityPlayerActivity in your manifest. is it working? (if not then fix this problem first)
Use JD to decompile the JAR where CompassActivity is located. Does it inherit from UnityPlayerActivity? In my case there was a problem with the compiler and it changed the inheritance to NPUnityPlayerActivity which was not found. If this problem occurs you need to recompile your code and make sure the inheritance is correct.
Good Luck!
Related
I'm trying to develop a simple 2D game using libgdx in Android Studio (0.8.14), but at this point (just with a splash and an empty menu) I'm getting an error, with this LogCat output, when I launch the app (I'm testing on device, Sony Xperia Z1):
12-02 18:01:52.146 24248-24248/com.ak.thesoccerball.android D/dalvikvm﹕ Late-enabling CheckJNI
12-02 18:01:52.196 24248-24248/com.ak.thesoccerball.android W/ActivityThread﹕ Application com.ak.thesoccerball.android can be debugged on port 8100...
12-02 18:01:52.246 24248-24248/com.ak.thesoccerball.android D/dalvikvm﹕ Trying to load lib /data/app-lib/com.ak.thesoccerball.android-1/libgdx.so 0x447c06f0
12-02 18:01:52.246 24248-24248/com.ak.thesoccerball.android D/dalvikvm﹕ Added shared lib /data/app-lib/com.ak.thesoccerball.android-1/libgdx.so 0x447c06f0
12-02 18:01:52.246 24248-24248/com.ak.thesoccerball.android D/dalvikvm﹕ No JNI_OnLoad found in /data/app-lib/com.ak.thesoccerball.android-1/libgdx.so 0x447c06f0, skipping init
12-02 18:01:52.246 24248-24248/com.ak.thesoccerball.android W/dalvikvm﹕ Exception Ljava/lang/NullPointerException; thrown while initializing Lcom/ak/thesoccerball/AKGame;
12-02 18:01:52.246 24248-24248/com.ak.thesoccerball.android D/AndroidRuntime﹕ Shutting down VM
12-02 18:01:52.246 24248-24248/com.ak.thesoccerball.android W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0x41618d88)
12-02 18:01:52.256 24248-24248/com.ak.thesoccerball.android E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.ak.thesoccerball.android, PID: 24248
java.lang.ExceptionInInitializerError
at com.ak.thesoccerball.android.AndroidLauncher.onCreate(AndroidLauncher.java:17)
at android.app.Activity.performCreate(Activity.java:5231)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2201)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2286)
at android.app.ActivityThread.access$800(ActivityThread.java:144)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1246)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:212)
at android.app.ActivityThread.main(ActivityThread.java:5135)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:877)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:693)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at com.ak.thesoccerball.AKGame.<clinit>(AKGame.java:9)
at com.ak.thesoccerball.android.AndroidLauncher.onCreate(AndroidLauncher.java:17)
at android.app.Activity.performCreate(Activity.java:5231)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2201)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2286)
at android.app.ActivityThread.access$800(ActivityThread.java:144)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1246)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:212)
at android.app.ActivityThread.main(ActivityThread.java:5135)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:877)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:693)
at dalvik.system.NativeStart.main(Native Method)
The classes involved are as follows:
- AndroidLauncher.java
package com.ak.thesoccerball.android;
import android.os.Bundle;
import com.badlogic.gdx.backends.android.AndroidApplication;
import com.badlogic.gdx.backends.android.AndroidApplicationConfiguration;
import com.ak.thesoccerball.AKGame;
public class AndroidLauncher extends AndroidApplication {
#Override
protected void onCreate (Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
AndroidApplicationConfiguration config = new AndroidApplicationConfiguration();
config.useAccelerometer = false;
config.useCompass = false;
initialize(new AKGame(), config);
}
}
AKGame.java
package com.ak.thesoccerball;
import com.badlogic.gdx.Game;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
public class AKGame extends Game {
public static final int WIDTH = Gdx.graphics.getWidth();
public static final int HEIGHT = Gdx.graphics.getHeight();
public SpriteBatch batch;
#Override
public void create() {
batch = new SpriteBatch();
setScreen(new SplashScreen(this));
}
public void render() {
super.render(); //important!
}
public void dispose() {
batch.dispose();
}
}
And here's the AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.ak.thesoccerball.android"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="21" />
<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/GdxTheme" >
<activity
android:name="com.ak.thesoccerball.android.AndroidLauncher"
android:label="#string/app_name"
android:screenOrientation="portrait"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
What am I missing so hard?
Move this code:
public static final int WIDTH = Gdx.graphics.getWidth();
public static final int HEIGHT = Gdx.graphics.getHeight();
into the create() method, for example:
#Override
public void create() {
WIDTH = Gdx.graphics.getWidth();
HEIGHT = Gdx.graphics.getHeight();
//..
}
The thing is that before the create method gets called the Gdx is still null and cannot be used yet.
I try to reproduce some videos in a sequence, this is the code, and the error message. I create the sd card in eclipse with the option Run -> Debug Configurations, is a 2GB sd card. I copied some videos to the sd card. So, I appreciate your help. Thanks.
MovieG.java
package com.example.movieg;
import java.io.File;
import android.media.MediaPlayer;
import android.media.MediaPlayer.OnCompletionListener;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.os.Message;
import android.widget.MediaController;
import android.widget.VideoView;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.util.Log;
import android.view.Menu;
public class MovieG extends Activity {
public VideoView videoView;
public String ex_name;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_movie_g);
ex_name = getIntent().getExtras().getString("video_name");
MediaController mediaController = new MediaController(this);
mediaController.setAnchorView(videoView);
videoView.setMediaController(new MediaController(this));
handler.sendEmptyMessage(1);
}
#SuppressLint("HandlerLeak")
Handler handler = new Handler(){
public void handleMessage(Message msg){
int pos=msg.what;
if (pos == 1){
File ex_name = null;
videoView.setVideoPath(Environment.getExternalStorageDirectory()+"/"+ex_name+".mp4");
videoView.requestFocus();
videoView.start();
Log.d("Before Video Finish", "i m in before video finish");
videoView.setOnCompletionListener(new OnCompletionListener() {
#Override
public void onCompletion(MediaPlayer mp) {
finish();
}
});
}
}
};
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.movie_g, menu);
return true;
}
}
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.movieg"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="18" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme">
<activity
android:name="com.example.movieg.MovieG"
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>
Error Message
02-24 21:42:54.916: D/AndroidRuntime(278): Shutting down VM
02-24 21:42:54.916: W/dalvikvm(278): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
02-24 21:42:54.946: E/AndroidRuntime(278): FATAL EXCEPTION: main
02-24 21:42:54.946: E/AndroidRuntime(278): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.movieg/com.example.movieg.MovieG}: java.lang.NullPointerException
02-24 21:42:54.946: E/AndroidRuntime(278): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
02-24 21:42:54.946: E/AndroidRuntime(278): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
02-24 21:42:54.946: E/AndroidRuntime(278): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
02-24 21:42:54.946: E/AndroidRuntime(278): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
02-24 21:42:54.946: E/AndroidRuntime(278): at android.os.Handler.dispatchMessage(Handler.java:99)
02-24 21:42:54.946: E/AndroidRuntime(278): at android.os.Looper.loop(Looper.java:123)
02-24 21:42:54.946: E/AndroidRuntime(278): at android.app.ActivityThread.main(ActivityThread.java:4627)
02-24 21:42:54.946: E/AndroidRuntime(278): at java.lang.reflect.Method.invokeNative(Native Method)
02-24 21:42:54.946: E/AndroidRuntime(278): at java.lang.reflect.Method.invoke(Method.java:521)
02-24 21:42:54.946: E/AndroidRuntime(278): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
02-24 21:42:54.946: E/AndroidRuntime(278): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
02-24 21:42:54.946: E/AndroidRuntime(278): at dalvik.system.NativeStart.main(Native Method)
02-24 21:42:54.946: E/AndroidRuntime(278): Caused by: java.lang.NullPointerException
02-24 21:42:54.946: E/AndroidRuntime(278): at com.example.movieg.MovieG.onCreate(MovieG.java:28)
02-24 21:42:54.946: E/AndroidRuntime(278): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
02-24 21:42:54.946: E/AndroidRuntime(278): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
02-24 21:42:54.946: E/AndroidRuntime(278): ... 11 more
You should verify that getIntent() has extras:
if (getIntent().getExtras() != null)
ex_name = getIntent().getExtras().getString("video_name");
You then need to cater for ex_name being null later in the code.
Second thing is, you never initialise videoView variable. You need to create an instance of it before it's used in onCreate().
You have not initialize the videoview:
videoView =(VideoView)findViewById(R.id.your_id);
before 28 th line
I'm trying to integrate admob to my game, but I'm getting nullpointerexcpetion when I'm trying to show interstitial ads. Here is my code..
Inside of onCreate
interstitial = new InterstitialAd(this);
interstitial.setAdUnitId("a1528e2f9897fc5");
AdRequest adRequest = new AdRequest.Builder().build();
interstitial.loadAd(adRequest);
I'm getting error on this line.. interstitial.loadAd(adRequest);
and here is my log
12-11 17:12:41.755: E/AndroidRuntime(9357): FATAL EXCEPTION: main
12-11 17:12:41.755: E/AndroidRuntime(9357): java.lang.RuntimeException: Unable to start activity ComponentInfo{cr.logics.fastfood/cr.logics.fastfood.FastFood}: java.lang.NullPointerException
12-11 17:12:41.755: E/AndroidRuntime(9357): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2100)
12-11 17:12:41.755: E/AndroidRuntime(9357): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2125)
12-11 17:12:41.755: E/AndroidRuntime(9357): at android.app.ActivityThread.access$600(ActivityThread.java:140)
12-11 17:12:41.755: E/AndroidRuntime(9357): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1227)
12-11 17:12:41.755: E/AndroidRuntime(9357): at android.os.Handler.dispatchMessage(Handler.java:99)
12-11 17:12:41.755: E/AndroidRuntime(9357): at android.os.Looper.loop(Looper.java:137)
12-11 17:12:41.755: E/AndroidRuntime(9357): at android.app.ActivityThread.main(ActivityThread.java:4898)
12-11 17:12:41.755: E/AndroidRuntime(9357): at java.lang.reflect.Method.invokeNative(Native Method)
12-11 17:12:41.755: E/AndroidRuntime(9357): at java.lang.reflect.Method.invoke(Method.java:511)
12-11 17:12:41.755: E/AndroidRuntime(9357): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1006)
12-11 17:12:41.755: E/AndroidRuntime(9357): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:773)
12-11 17:12:41.755: E/AndroidRuntime(9357): at dalvik.system.NativeStart.main(Native Method)
12-11 17:12:41.755: E/AndroidRuntime(9357): Caused by: java.lang.NullPointerException
12-11 17:12:41.755: E/AndroidRuntime(9357): at tj.a(SourceFile:191)
12-11 17:12:41.755: E/AndroidRuntime(9357): at tt.onTransact(SourceFile:81)
12-11 17:12:41.755: E/AndroidRuntime(9357): at android.os.Binder.transact(Binder.java:326)
12-11 17:12:41.755: E/AndroidRuntime(9357): at com.google.android.gms.internal.ac$a$a.a(Unknown Source)
12-11 17:12:41.755: E/AndroidRuntime(9357): at com.google.android.gms.ads.InterstitialAd.loadAd(Unknown Source)
12-11 17:12:41.755: E/AndroidRuntime(9357): at cr.logics.fastfood.FastFood.onCreate(FastFood.java:245)
12-11 17:12:41.755: E/AndroidRuntime(9357): at android.app.Activity.performCreate(Activity.java:5206)
12-11 17:12:41.755: E/AndroidRuntime(9357): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1083)
12-11 17:12:41.755: E/AndroidRuntime(9357): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2064)
12-11 17:12:41.755: E/AndroidRuntime(9357): ... 11 more
I have added google-play-services-lib to my project, added meta-data into manifest, did everything as google guide, but I'm facing to this error, (sorry for my beta English).
Any suggestions?
Thanks in advance!
Add the following to your project's proguard-project.txt to prevent it from stripping away the admob classes
-keep public class com.google.android.gms.ads.** {
public *;
}
-keep public class com.google.ads.** {
public *;
}
And also include the following activity to your manifest file
android:name="com.google.android.gms.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
Before show interstitial ad you must check interstitial ad object is null or not and also check ad is loaded.
Full code is given below :
In the onCreate() method of an Activity:
public class MainActivity extends Activity {
public static InterstitialAd mInterstitialAd;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
MobileAds.initialize(this, new OnInitializationCompleteListener() {
#Override
public void onInitializationComplete(InitializationStatus initializationStatus) {}
});
mInterstitialAd = new InterstitialAd(this);
mInterstitialAd.setAdUnitId("ca-app-pub-3940256099942544/1033173712");
mInterstitialAd.loadAd(new AdRequest.Builder().build());
mInterstitialAd.setAdListener(new AdListener() {
#Override
public void onAdLoaded() {
// Code to be executed when an ad finishes loading.
}
#Override
public void onAdFailedToLoad(int errorCode) {
// Code to be executed when an ad request fails.
}
#Override
public void onAdClosed() {
// Load the next interstitial Ad
mInterstitialAd.loadAd(new AdRequest.Builder().build());
}
});
}
}
To show the ad I used static method.So that I can call this method from another activity.
public static void showInterstitialAd() {
if (mInterstitialAd != null) {
if (mInterstitialAd.isLoaded()) {
mInterstitialAd.show();
} else {
mInterstitialAd.loadAd(new AdRequest.Builder().build());
}
}
}
You have to check that the ad is loaded before showing:
if (interstitial!=null && interstitial.isLoaded())
{
interstitial.show();
}
I am using shared preferences to store data on whether or not a certain objective was completed for my class using a boolean shared preference. When I try and run this part of my code the logcat prints out this:
10-28 00:35:09.771: E/AndroidRuntime(429): FATAL EXCEPTION: main
10-28 00:35:09.771: E/AndroidRuntime(429): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.selectstartgo.physics281/com.selectstartgo.physics281.Grading}: java.lang.NullPointerException
10-28 00:35:09.771: E/AndroidRuntime(429): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
10-28 00:35:09.771: E/AndroidRuntime(429): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
10-28 00:35:09.771: E/AndroidRuntime(429): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
10-28 00:35:09.771: E/AndroidRuntime(429): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
10-28 00:35:09.771: E/AndroidRuntime(429): at android.os.Handler.dispatchMessage(Handler.java:99)
10-28 00:35:09.771: E/AndroidRuntime(429): at android.os.Looper.loop(Looper.java:123)
10-28 00:35:09.771: E/AndroidRuntime(429): at android.app.ActivityThread.main(ActivityThread.java:3683)
10-28 00:35:09.771: E/AndroidRuntime(429): at java.lang.reflect.Method.invokeNative(Native Method)
10-28 00:35:09.771: E/AndroidRuntime(429): at java.lang.reflect.Method.invoke(Method.java:507)
10-28 00:35:09.771: E/AndroidRuntime(429): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
10-28 00:35:09.771: E/AndroidRuntime(429): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
10-28 00:35:09.771: E/AndroidRuntime(429): at dalvik.system.NativeStart.main(Native Method)
10-28 00:35:09.771: E/AndroidRuntime(429): Caused by: java.lang.NullPointerException
10-28 00:35:09.771: E/AndroidRuntime(429): at android.preference.PreferenceManager.getDefaultSharedPreferencesName(PreferenceManager.java:353)
10-28 00:35:09.771: E/AndroidRuntime(429): at android.preference.PreferenceManager.getDefaultSharedPreferences(PreferenceManager.java:348)
10-28 00:35:09.771: E/AndroidRuntime(429): at com.selectstartgo.physics281.PhysSharedPrefs.getSharPrefBoolean(PhysSharedPrefs.java:36)
10-28 00:35:09.771: E/AndroidRuntime(429): at com.selectstartgo.physics281.Grading.findCLevel(Grading.java:270)
10-28 00:35:09.771: E/AndroidRuntime(429): at com.selectstartgo.physics281.Grading.initialize(Grading.java:24)
10-28 00:35:09.771: E/AndroidRuntime(429): at com.selectstartgo.physics281.Grading.onCreate(Grading.java:16)
10-28 00:35:09.771: E/AndroidRuntime(429): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
10-28 00:35:09.771: E/AndroidRuntime(429): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
Here is my shared preference manager
package com.selectstartgo.physics281;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.preference.PreferenceManager;
public class PhysSharedPrefs {
public static void putSharPrefInt(Context context, String key, int value) {
SharedPreferences pref = PreferenceManager
.getDefaultSharedPreferences(context);
Editor edit = pref.edit();
edit.putInt(key, value);
edit.commit();
}
public static void putSharPrefBoolean(Context context, String key,
boolean value) {
SharedPreferences pref = PreferenceManager
.getDefaultSharedPreferences(context);
Editor edit = pref.edit();
edit.putBoolean(key, value);
edit.commit();
}
public static int getSharPrefInt(Context context, String key, int _default) {
SharedPreferences pref = PreferenceManager
.getDefaultSharedPreferences(context);
return pref.getInt(key, _default);
}
public static boolean getSharPrefBoolean(Context context, String key,
boolean _default) {
SharedPreferences pref = PreferenceManager
.getDefaultSharedPreferences(context);
return pref.getBoolean(key, _default);
}
}
And here's a chunk of code that is not working
if (PhysSharedPrefs.getSharPrefBoolean(MyApplication.getAppContext(),
"bKey101", false))
i++;
if (PhysSharedPrefs.getSharPrefBoolean(MyApplication.getAppContext(),
"bKey102", false))
i++;
if (PhysSharedPrefs.getSharPrefBoolean(MyApplication.getAppContext(),
"bKey103", false))
i++;
if (PhysSharedPrefs.getSharPrefBoolean(MyApplication.getAppContext(),
"bKey104", false))
And my MyApplication code looks like this:
package com.selectstartgo.physics281;
import android.app.Application;
import android.content.Context;
public class MyApplication extends Application {
private static Context context;
public void onCreate() {
super.onCreate();
MyApplication.context = getApplicationContext();
}
public static Context getAppContext() {
return MyApplication.context;
}
}
Thanks for any help I can get!
Since you have made a subclass of Application, for global access to the application context, have you remembered to edit your AndroidManifest.xml?
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:name="MyApplication"> <!-- This line -->
the error means MyApplication.getAppContext() ==null,you can check your code MyApplication
getAppContext() method ,
I try to implement an application based on rscm (middleware). When I try to run on emulator, I get the errors listed below:
Error :03-27 16:58:20.490: E/Trace(1508): error opening trace file: No
such file or directory (2)
03-27 21:53:21.610: D/AndroidRuntime(3803): Shutting down VM 03-27
21:53:21.610: W/dalvikvm(3803): threadid=1: thread exiting with
uncaught exception (group=0x40a71930) 03-27 21:53:21.760:
E/AndroidRuntime(3803): FATAL EXCEPTION: main 03-27 21:53:21.760:
E/AndroidRuntime(3803): java.lang.RuntimeException: Unable to
instantiate activity
ComponentInfo{com.example.context_application/com.example.context_application.MyContextAwareActivity}:
java.lang.ClassNotFoundException: Didn't find class
"com.example.context_application.MyContextAwareActivity" on path:
/data/app/com.example.context_application-2.apk 03-27 21:53:21.760:
E/AndroidRuntime(3803): at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2106)
03-27 21:53:21.760: E/AndroidRuntime(3803): at
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
03-27 21:53:21.760: E/AndroidRuntime(3803): at
android.app.ActivityThread.access$600(ActivityThread.java:141) 03-27
21:53:21.760: E/AndroidRuntime(3803): at
android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
03-27 21:53:21.760: E/AndroidRuntime(3803): at
android.os.Handler.dispatchMessage(Handler.java:99) 03-27
21:53:21.760: E/AndroidRuntime(3803): at
android.os.Looper.loop(Looper.java:137) 03-27 21:53:21.760:
E/AndroidRuntime(3803): at
android.app.ActivityThread.main(ActivityThread.java:5041) 03-27
21:53:21.760: E/AndroidRuntime(3803): at
java.lang.reflect.Method.invokeNative(Native Method) 03-27
21:53:21.760: E/AndroidRuntime(3803): at
java.lang.reflect.Method.invoke(Method.java:511) 03-27 21:53:21.760:
E/AndroidRuntime(3803): at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
03-27 21:53:21.760: E/AndroidRuntime(3803): at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560) 03-27
21:53:21.760: E/AndroidRuntime(3803): at
dalvik.system.NativeStart.main(Native Method) 03-27 21:53:21.760:
E/AndroidRuntime(3803): Caused by: java.lang.ClassNotFoundException:
Didn't find class
"com.example.context_application.MyContextAwareActivity" on path:
/data/app/com.example.context_application-2.apk 03-27 21:53:21.760:
E/AndroidRuntime(3803): at
dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:65)
03-27 21:53:21.760: E/AndroidRuntime(3803): at
java.lang.ClassLoader.loadClass(ClassLoader.java:501) 03-27
21:53:21.760: E/AndroidRuntime(3803): at
java.lang.ClassLoader.loadClass(ClassLoader.java:461) 03-27
21:53:21.760: E/AndroidRuntime(3803): at
android.app.Instrumentation.newActivity(Instrumentation.java:1054)
03-27 21:53:21.760: E/AndroidRuntime(3803): at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2097)
03-27 21:53:21.760: E/AndroidRuntime(3803): ... 11 more
Can anyone help?
package com.example.context;
import android.os.Bundle;
import android.widget.TextView;
import android.widget.Toast;
import org.aspectsense.rscm.ContextValue;
import org.aspectsense.rscm.context.client.ContextListenerActivity;
import org.json.JSONException;
import java.util.Date;
public class MyContextAwareActivity extends ContextListenerActivity
{
#Override public String[] getRequestedScopes()
{
return new String[] { "battery.level" };
}
private TextView messageTextView;
#Override protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
messageTextView = new TextView(this);
setContentView(messageTextView);
appendMessage("Activity created");
}
private void appendMessage(final String message)
{
final String currentMessage = messageTextView.getText().toString();
messageTextView.setText(currentMessage + "\n" + message);
}
#Override public void onContextValueChanged(ContextValue contextValue)
{
try
{
appendMessage(new Date() + ": The battery level is " + contextValue.getValueAsInteger() + "%");
}
catch (JSONException jsone)
{
Toast.makeText(this, "Error while displaying context event: " + contextValue, Toast.LENGTH_SHORT).show();
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.context"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.context.MyContextAwareActivity"
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 are telling it to write to external storage. Have you set up an SD card in eclipse?
Do any of these answers help? error opening trace file: No such file or directory (2)