I'm trying to implement drive storage into my app, and I'm having a bit of an issue getting it to run. It compiles fine (no errors), but there's some class files getting lost somewhere. The error when launching my app is as follows:
01-24 18:40:09.747 1038-8218/? I/ActivityManager﹕ Start proc net.rymate.notes for activity net.rymate.notes/.activities.NotesListActivity: pid=6099 uid=10102 gids={50102, 3003}
01-24 18:40:09.748 1038-1103/? D/WifiStateMachine﹕ handleMessage: X
01-24 18:40:09.772 6099-6105/? D/dalvikvm﹕ Debugger has detached; object registry had 1 entries
01-24 18:40:09.814 6099-6099/? I/dalvikvm﹕ Failed resolving Lnet/rymate/notes/storage/GoogleDriveStorage; interface 1582 'Lcom/google/android/gms/common/api/GoogleApiClient$ConnectionCallbacks;'
01-24 18:40:09.815 6099-6099/? W/dalvikvm﹕ Link of class 'Lnet/rymate/notes/storage/GoogleDriveStorage;' failed
01-24 18:40:09.815 6099-6099/? E/dalvikvm﹕ Could not find class 'net.rymate.notes.storage.GoogleDriveStorage', referenced from method net.rymate.notes.activities.NotesListActivity.onCreate
01-24 18:40:09.815 6099-6099/? W/dalvikvm﹕ VFY: unable to resolve new-instance 1949 (Lnet/rymate/notes/storage/GoogleDriveStorage;) in Lnet/rymate/notes/activities/NotesListActivity;
01-24 18:40:09.815 6099-6099/? D/dalvikvm﹕ VFY: replacing opcode 0x22 at 0x0092
01-24 18:40:09.837 6099-6099/? I/dalvikvm﹕ Failed resolving Lnet/rymate/notes/storage/GoogleDriveStorage; interface 1582 'Lcom/google/android/gms/common/api/GoogleApiClient$ConnectionCallbacks;'
01-24 18:40:09.838 6099-6099/? W/dalvikvm﹕ Link of class 'Lnet/rymate/notes/storage/GoogleDriveStorage;' failed
01-24 18:40:09.839 6099-6099/? D/dalvikvm﹕ DexOpt: unable to opt direct call 0x3162 at 0x94 in Lnet/rymate/notes/activities/NotesListActivity;.onCreate
01-24 18:40:09.905 1038-8218/? D/dalvikvm﹕ GC_EXPLICIT freed 1503K, 23% free 26687K/34552K, paused 4ms+10ms, total 111ms
01-24 18:40:09.910 6099-6099/? D/AndroidRuntime﹕ Shutting down VM
01-24 18:40:09.910 6099-6099/? W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0x41616d40)
01-24 18:40:09.912 6099-6099/? E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: net.rymate.notes, PID: 6099
java.lang.NoClassDefFoundError: net.rymate.notes.storage.GoogleDriveStorage
at net.rymate.notes.activities.NotesListActivity.onCreate(NotesListActivity.java:122)
at android.app.Activity.performCreate(Activity.java:5248)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1110)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2173)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2269)
at android.app.ActivityThread.access$800(ActivityThread.java:139)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1210)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5102)
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:779)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:126)
at dalvik.system.NativeStart.main(Native Method)
This is the source for the problem class (my main activity just creates a new instance of this class, it doesn't do anything with it):
package net.rymate.notes.storage;
import android.app.Activity;
import android.content.IntentSender.SendIntentException;
import android.os.Bundle;
import android.util.Log;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GooglePlayServicesUtil;
import com.google.android.gms.common.api.GoogleApiClient;
import com.google.android.gms.common.api.GoogleApiClient.ConnectionCallbacks;
import com.google.android.gms.common.api.GoogleApiClient.OnConnectionFailedListener;
import com.google.android.gms.drive.Drive;
/**
* Created by Ryan on 24/01/14.
*/
public class GoogleDriveStorage implements
ConnectionCallbacks,
OnConnectionFailedListener {
private static final String TAG = "GoogleDriveStorage";
/**
* Extra for account name.
*/
protected static final String EXTRA_ACCOUNT_NAME = "account_name";
/**
* Request code for auto Google Play Services error resolution.
*/
protected static final int REQUEST_CODE_RESOLUTION = 1;
/**
* Next available request code.
*/
protected static final int NEXT_AVAILABLE_REQUEST_CODE = 2;
private final Activity activity;
/**
* Google API client.
*/
private GoogleApiClient mGoogleApiClient;
public GoogleDriveStorage(Activity a) {
if (mGoogleApiClient == null) {
mGoogleApiClient = new GoogleApiClient.Builder(a.getApplication())
.addApi(Drive.API)
.addScope(Drive.SCOPE_FILE)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.build();
}
mGoogleApiClient.connect();
this.activity = a;
}
/**
* Called when {#code mGoogleApiClient} is connected.
*/
#Override
public void onConnected(Bundle connectionHint) {
Log.i(TAG, "GoogleApiClient connected");
}
/**
* Called when {#code mGoogleApiClient} is disconnected.
*/
#Override
public void onDisconnected() {
Log.i(TAG, "GoogleApiClient disconnected");
}
#Override
public void onConnectionFailed(ConnectionResult result) {
Log.i(TAG, "GoogleApiClient connection failed: " + result.toString());
if (!result.hasResolution()) {
// show the localized error dialog.
GooglePlayServicesUtil.getErrorDialog(result.getErrorCode(), activity, 0).show();
return;
}
try {
result.startResolutionForResult(activity, REQUEST_CODE_RESOLUTION);
} catch (SendIntentException e) {
Log.e(TAG, "Exception while starting resolution activity", e);
}
}
}
And my build.gradle
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.6.+'
}
}
apply plugin: 'android'
repositories {
mavenCentral()
mavenLocal()
}
android {
compileSdkVersion 19
buildToolsVersion "19.0.0"
defaultConfig {
minSdkVersion 14
targetSdkVersion 19
}
}
dependencies {
compile project(':libs:ShowcaseView')
// Google Play Services
compile 'com.google.android.gms:play-services:4.1.32'
}
Help will be appreciated!
EDIT: adding manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="net.rymate.notes"
android:versionCode="7"
android:versionName="1.3" >
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="16" />
<uses-permission android:name="android.permission.GET_ACCOUNTS"/>
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" android:hardwareAccelerated="true">
<activity android:name="net.rymate.notes.activities.NotesListActivity" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
<activity
android:name="net.rymate.notes.activities.NoteViewActivity"
android:configChanges="orientation|keyboardHidden|screenSize"
android:windowSoftInputMode="adjustResize" />
<activity
android:name="net.rymate.notes.activities.NoteEditActivity"
android:configChanges="orientation|keyboardHidden|screenSize"
android:windowSoftInputMode="stateVisible|adjustResize" />
</application>
</manifest>
In the project properties under Java Build Path -> Order and Export make sure that "Android Private Libraries" and "Android Dependencies" are checked. Then clean and try again.
Related
i m trying to make custom android app from android Developer site with android studio but my app doesnt run in emulator its shows error
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo
Here is My Main Activity
package firstapp.boysjoys.com.waste;
import android.app.Activity;
import android.hardware.Camera;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.view.View;
import android.widget.Button;
import android.widget.FrameLayout;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
/**
* Created by Varun on 12/24/14.
*/
public class MainActivity extends Activity {
public static final int MEDIA_TYPE_IMAGE = 1;
private Camera mcamera;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mcamera = getcam();
cam mcam = new cam(this, mcamera);
FrameLayout preview = (FrameLayout) findViewById(R.id.camPre);
preview.addView(mcam);
}
public static Camera getcam() {
Camera c = null;
try {
c = Camera.open();
}
catch (Exception e){
e.getMessage();
}
return c;
}
private Camera.PictureCallback mpicturecallback = new Camera.PictureCallback() {
#Override
public void onPictureTaken(byte[] data, Camera camera) {
File pictureFile=getOutPutMediaFile(MEDIA_TYPE_IMAGE);
if (pictureFile==null){
android.util.Log.d("Error","Problem");
return;
}
try {
FileOutputStream fos=new FileOutputStream(pictureFile);
fos.write(data);
fos.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
};
//CREATE A FILE URI FOR SAVING AN IMAGE OR VIDEO
private static Uri getOutPutMediaFileUri(int type){
return Uri.fromFile(getOutPutMediaFile(type));
}
private static File getOutPutMediaFile(int type){
File mediaStorage=new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES),"MyCameraApp");
if (!mediaStorage.exists()){
if (!mediaStorage.mkdirs()) {
android.util.Log.d("Mycamera", "Failed Error");
return null;
}
}
File mediaName;
if (type==MEDIA_TYPE_IMAGE) {
mediaName = new File(mediaStorage.getPath()+File.separator+"Rim_"+".jpg");
}
else {
return null;
}
return mediaName;
}
//Button Listener to the capture button
Button btn= (Button) findViewById(R.id.Capture);
public void clickPic(View view){
mcamera.takePicture(null,null,mpicturecallback);
}
}
And camera preview activity
package firstapp.boysjoys.com.waste;
import android.content.Context;
import android.hardware.Camera;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import java.io.IOException;
public class cam extends SurfaceView implements SurfaceHolder.Callback{
private SurfaceHolder mholder;
private Camera mcamera;
public cam(Context context,Camera camera){
super(context);
mholder=getHolder();
mholder.addCallback(this);
mholder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
}
/**
* This is called immediately after the surface is first created.
* Implementations of this should start up whatever rendering code
* they desire. Note that only one thread can ever draw into
* a {#link android.view.Surface}, so you should not draw into the Surface here
* if your normal rendering will be in another thread.
*
* #param holder The SurfaceHolder whose surface is being created.
*/
#Override
public void surfaceCreated(SurfaceHolder holder) {
try {
mcamera.setPreviewDisplay(holder);
mcamera.startPreview();
} catch (IOException e) {
e.printStackTrace();
}
}
/**
* This is called immediately after any structural changes (format or
* size) have been made to the surface. You should at this point update
* the imagery in the surface. This method is always called at least
* once, after {#link #surfaceCreated}.
*
* #param holder The SurfaceHolder whose surface has changed.
* #param format The new PixelFormat of the surface.
* #param width The new width of the surface.
* #param height The new height of the surface.
*/
#Override
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
if (mholder.getSurface()==null) {
return;
}
mcamera.stopPreview();
//Start Preview WIth New Setting
try {
mcamera.setPreviewDisplay(mholder);
mcamera.startPreview();
} catch (IOException e) {
e.printStackTrace();
}
}
/**
* This is called immediately before a surface is being destroyed. After
* returning from this call, you should no longer try to access this
* surface. If you have a rendering thread that directly accesses
* the surface, you must ensure that thread is no longer touching the
* Surface before returning from this function.
*
* #param holder The SurfaceHolder whose surface is being destroyed.
*/
#Override
public void surfaceDestroyed(SurfaceHolder holder) {
if (mholder.getSurface()!=null){
mholder.getSurface().release();
mcamera=null;
}
}
}
This Is Manifest file
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="firstapp.boysjoys.com.waste" >
<uses-permission android:name="android.permission.CAMERA" ></uses-permission>
<uses-permission android:name="android.permission.write_external_storage"></uses-permission>
<uses-feature android:name="android.hardware.camera2.full" android:required="false">
</uses-feature>
<uses-feature android:name="android.hardware.Camera" android:required="false"></uses-feature>
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity android:name=".MainActivity"
android:label="#string/app_name"
android:screenOrientation="landscape"
>
<intent-filter>
<action android:name="android.intent.action.MAIN">
</action>
<category android:name="android.intent.category.LAUNCHER">
</category>
</intent-filter>
</activity>
</application>
</manifest>
And Here Is Complete LogCat From Android Studio
12-26 15:26:46.284 610-610/firstapp.boysjoys.com.waste D/dalvikvm﹕ Not late-enabling CheckJNI (already on)
12-26 15:26:48.244 610-615/firstapp.boysjoys.com.waste I/dalvikvm﹕ threadid=3: reacting to signal 3
12-26 15:26:48.434 610-615/firstapp.boysjoys.com.waste I/dalvikvm﹕ Wrote stack traces to '/data/anr/traces.txt'
12-26 15:26:48.683 610-615/firstapp.boysjoys.com.waste I/dalvikvm﹕ threadid=3: reacting to signal 3
12-26 15:26:48.754 610-610/firstapp.boysjoys.com.waste D/AndroidRuntime﹕ Shutting down VM
12-26 15:26:48.754 610-610/firstapp.boysjoys.com.waste W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0x409c01f8)
12-26 15:26:48.786 610-615/firstapp.boysjoys.com.waste I/dalvikvm﹕ Wrote stack traces to '/data/anr/traces.txt'
12-26 15:26:48.822 610-610/firstapp.boysjoys.com.waste E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{firstapp.boysjoys.com.waste/firstapp.boysjoys.com.waste.MainActivity}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1880)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
at android.app.ActivityThread.access$600(ActivityThread.java:123)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4424)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at android.app.Activity.findViewById(Activity.java:1794)
at firstapp.boysjoys.com.waste.MainActivity.<init>(MainActivity.java:102)
at java.lang.Class.newInstanceImpl(Native Method)
at java.lang.Class.newInstance(Class.java:1319)
at android.app.Instrumentation.newActivity(Instrumentation.java:1023)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1871)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
at android.app.ActivityThread.access$600(ActivityThread.java:123)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4424)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
at dalvik.system.NativeStart.main(Native Method)
12-26 15:26:49.154 610-615/firstapp.boysjoys.com.waste I/dalvikvm﹕ threadid=3: reacting to signal 3
12-26 15:26:49.234 610-615/firstapp.boysjoys.com.waste I/dalvikvm﹕ Wrote stack traces to '/data/anr/traces.txt'
12-26 15:26:49.654 610-615/firstapp.boysjoys.com.waste I/dalvikvm﹕ threadid=3: reacting to signal 3
12-26 15:26:49.734 610-615/firstapp.boysjoys.com.waste I/dalvikvm﹕ Wrote stack traces to '/data/anr/traces.txt'
12-26 15:27:18.314 610-610/firstapp.boysjoys.com.waste I/Process﹕ Sending signal. PID: 610 SIG: 9
i dont understand from where its throwing RuntimeException
at this line it says in error log
Caused by: java.lang.NullPointerException at android.app.Activity.findViewById(Activity.java:1794)
says it return null its button id in xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/camPre"
android:layout_weight="1"
>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/click"
android:text="Capture"
android:layout_gravity="center"
/>
</FrameLayout>
</LinearLayout>
i tried to debug app but still can get why its throwing null pointer exception
it can be because of button id or this line according to error log line no 102
in main activity
if (!mediaStorage.exists()){
if (!mediaStorage.mkdirs()) {
android.util.Log.d("Mycamera", "Failed Error");
return null;
}
}
Caused by: java.lang.NullPointerException
at android.app.Activity.findViewById(Activity.java:1794)
at firstapp.boysjoys.com.waste.MainActivity.<init>(MainActivity.java:102)
You're calling findViewById() too early, in activity <init> phase that includes e.g. member variable initialization.
You can only call activity methods like findViewById() in onCreate() or later in the activity lifecycle.
Move the findViewById() call to onCreate() to get rid of the NPE. Put it after setContentView() so that it can actually return a non-null value.
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'm integrating Google Ads in Android application. I'm implementing example of google ad mob, which I have getting example from the net. And also I have add external jar file of google-play-service_lib.jar and add the element of
<activity android:name="com.google.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation"/>
</application>
And when I run the app the application is crashes. I'm getting error like this:
= 04-15 12:16:33.713: W/Ads(545): Invalid unknown request error: Cannot determine request type. Is your ad unit id correct?
There was a problem getting an ad response. ErrorCode: 1
Failed to load ad: 1
04-15 12:16:04.713: W/GooglePlayServicesUtil(545): Google Play services is missing.
Here is my code.
The code of BannerAdListener
public class BannerAdListener extends Activity {
/** Your ad unit id*/
private static final String AD_UNIT_ID = "INSERT_YOUR_AD_UNIT_ID_HERE";
/** The log tag. */
private static final String LOG_TAG = "BannerAdListener";
/** The view to show the ad. */
private AdView adView;
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// Create an ad.
adView = new AdView(this);
adView.setAdSize(AdSize.BANNER);
adView.setAdUnitId(AD_UNIT_ID);
// Set the AdListener.
adView.setAdListener(new AdListener() {
/** Called when an ad is clicked and about to return to the application. */
#Override
public void onAdClosed() {
Log.d(LOG_TAG, "onAdClosed");
Toast.makeText(BannerAdListener.this, "onAdClosed", Toast.LENGTH_SHORT).show();
}
/** Called when an ad failed to load. */
#Override
public void onAdFailedToLoad(int error) {
String message = "onAdFailedToLoad: " + getErrorReason(error);
Log.d(LOG_TAG, message);
Toast.makeText(BannerAdListener.this, message, Toast.LENGTH_SHORT).show();
}
/**
* Called when an ad is clicked and going to start a new Activity that will
* leave the application (e.g. breaking out to the Browser or Maps
* application).
*/
#Override
public void onAdLeftApplication() {
Log.d(LOG_TAG, "onAdLeftApplication");
Toast.makeText(BannerAdListener.this, "onAdLeftApplication", Toast.LENGTH_SHORT).show();
}
/**
* Called when an Activity is created in front of the app (e.g. an
* interstitial is shown, or an ad is clicked and launches a new Activity).
*/
#Override
public void onAdOpened() {
Log.d(LOG_TAG, "onAdOpened");
Toast.makeText(BannerAdListener.this, "onAdOpened", Toast.LENGTH_SHORT).show();
}
/** Called when an ad is loaded. */
#Override
public void onAdLoaded() {
Log.d(LOG_TAG, "onAdLoaded");
Toast.makeText(BannerAdListener.this, "onAdLoaded", Toast.LENGTH_SHORT).show();
}
});
// Add the AdView to the view hierarchy.
LinearLayout layout = (LinearLayout) findViewById(R.id.linearLayout);
layout.addView(adView);
// Create an ad request. Check logcat output for the hashed device ID to
// get test ads on a physical device.
AdRequest adRequest = new AdRequest.Builder()
.addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
.addTestDevice("INSERT_YOUR_HASHED_DEVICE_ID_HERE")
.build();
// Start loading the ad in the background.
adView.loadAd(adRequest);
}
#Override
public void onResume() {
super.onResume();
if (adView != null) {
adView.resume();
}
}
#Override
public void onPause() {
if (adView != null) {
adView.pause();
}
super.onPause();
}
/** Called before the activity is destroyed. */
#Override
public void onDestroy() {
if (adView != null) {
// Destroy the AdView.
adView.destroy();
}
super.onDestroy();
}
/** Gets a string error reason from an error code. */
private String getErrorReason(int errorCode) {
String errorReason = "";
switch(errorCode) {
case AdRequest.ERROR_CODE_INTERNAL_ERROR:
errorReason = "Internal error";
break;
case AdRequest.ERROR_CODE_INVALID_REQUEST:
errorReason = "Invalid request";
break;
case AdRequest.ERROR_CODE_NETWORK_ERROR:
errorReason = "Network Error";
break;
case AdRequest.ERROR_CODE_NO_FILL:
errorReason = "No fill";
break;
}
return errorReason;
}
}
Here is manifest file
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.google.example.gms.ads.banneradlistener"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="9"
android:targetSdkVersion="18" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<application android:icon="#drawable/icon" android:label="#string/app_name">
<activity android:name=".BannerAdListener"
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="com.google.android.gms.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>
<meta-data android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
</application>
</manifest>
And the log cat Information is here.
04-15 12:16:04.473: D/dalvikvm(545): DexOpt: couldn't find field Landroid/content/res/Configuration;.smallestScreenWidthDp
04-15 12:16:04.502: W/dalvikvm(545): VFY: unable to resolve instance field 21
04-15 12:16:04.503: D/dalvikvm(545): VFY: replacing opcode 0x52 at 0x0012
04-15 12:16:04.503: D/dalvikvm(545): VFY: dead code 0x0014-0018 in Lcom/google/android/gms/common/GooglePlayServicesUtil;.b (Landroid/content/res/Resources;)Z
04-15 12:16:04.534: E/dalvikvm(545): Could not find class 'android.support.v4.app.FragmentActivity', referenced from method com.google.android.gms.common.GooglePlayServicesUtil.showErrorDialogFragment
04-15 12:16:04.534: W/dalvikvm(545): VFY: unable to resolve instanceof 132 (Landroid/support/v4/app/FragmentActivity;) in Lcom/google/android/gms/common/GooglePlayServicesUtil;
04-15 12:16:04.543: D/dalvikvm(545): VFY: replacing opcode 0x20 at 0x0008
04-15 12:16:04.563: E/dalvikvm(545): Could not find class 'android.support.v4.app.FragmentActivity', referenced from method com.google.android.gms.common.GooglePlayServicesUtil.showErrorDialogFragment
04-15 12:16:04.563: W/dalvikvm(545): VFY: unable to resolve check-cast 132 (Landroid/support/v4/app/FragmentActivity;) in Lcom/google/android/gms/common/GooglePlayServicesUtil;
04-15 12:16:04.563: D/dalvikvm(545): VFY: replacing opcode 0x1f at 0x000c
04-15 12:16:04.563: I/dalvikvm(545): Could not find method android.app.Activity.getFragmentManager, referenced from method com.google.android.gms.common.GooglePlayServicesUtil.showErrorDialogFragment
04-15 12:16:04.563: W/dalvikvm(545): VFY: unable to resolve virtual method 9: Landroid/app/Activity;.getFragmentManager ()Landroid/app/FragmentManager;
04-15 12:16:04.563: D/dalvikvm(545): VFY: replacing opcode 0x6e at 0x0023
04-15 12:16:04.563: D/dalvikvm(545): VFY: dead code 0x000e-001c in Lcom/google/android/gms/common/GooglePlayServicesUtil;.showErrorDialogFragment (ILandroid/app/Activity;ILandroid/content/DialogInterface$OnCancelListener;)Z
04-15 12:16:04.563: D/dalvikvm(545): VFY: dead code 0x0026-0030 in Lcom/google/android/gms/common/GooglePlayServicesUtil;.showErrorDialogFragment (ILandroid/app/Activity;ILandroid/content/DialogInterface$OnCancelListener;)Z
04-15 12:16:04.713: W/GooglePlayServicesUtil(545): Google Play services is missing.
04-15 12:16:05.428: I/dalvikvm(545): Total arena pages for JIT: 11
04-15 12:16:05.428: I/dalvikvm(545): Total arena pages for JIT: 12
04-15 12:16:05.562: D/dalvikvm(545): DexOpt: --- BEGIN 'ads-1292075482.jar' (bootstrap=0) ---
04-15 12:16:07.143: D/dalvikvm(545): DexOpt: --- END 'ads-1292075482.jar' (success) ---
04-15 12:16:07.165: D/dalvikvm(545): DEX prep '/data/data/com.google.example.gms.ads.banneradlistener/cache/ads-1292075482.jar': unzip in 14ms, rewrite 1622ms
04-15 12:16:07.655: I/Ads(545): Use AdRequest.Builder.addTestDevice("B3EEABB8EE11C2BE770B684D95219ECB") to get test ads on this device.
04-15 12:16:07.674: I/Ads(545): Starting ad request.
04-15 12:16:18.945: W/GooglePlayServicesUtil(545): Google Play services is missing.
04-15 12:16:18.980: E/GooglePlayServicesUtil(545): GooglePlayServices not available due to error 1
04-15 12:16:21.044: D/dalvikvm(545): GC_EXTERNAL_ALLOC freed 343K, 49% free 2925K/5703K, external 2032K/2137K, paused 171ms
04-15 12:16:21.044: D/webviewglue(545): nativeDestroy view: 0x36ab88
04-15 12:16:33.713: W/Ads(545): Invalid unknown request error: Cannot determine request type. Is your ad unit id correct?
04-15 12:16:33.763: W/Ads(545): There was a problem getting an ad response. ErrorCode: 1
04-15 12:16:33.763: W/Ads(545): Failed to load ad: 1
04-15 12:16:33.763: D/BannerAdListener(545): onAdFailedToLoad: Invalid request
You need to provide your AdUnitId.
private static final String AD_UNIT_ID = "INSERT_YOUR_AD_UNIT_ID_HERE";
Is not a valid AdUnitId. Go to your Admob dashboard and get your AdunitId and plug it into the code above.
I was working with Google Ads and this is a basic example
This is my AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.tunapuisor.banner"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="9"
android:targetSdkVersion="18" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<application android:icon="#drawable/ic_launcher" android:label="#string/app_name">
<activity android:name=".AdPuisorSample "
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="com.google.android.gms.ads.AdActivity" android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" android:theme="#android:style/Theme.Translucent"/>
<meta-data android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
</application>
</manifest>
I was working with the last version of GooglePlay Services, so this is my integers.xml
<resources>
<integer name="google_play_services_version">5089000</integer>
</resources>
This is my "test" activity, I've got from a sdk example:
package com.tunapuisor.banner;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdSize;
import com.google.android.gms.ads.AdView;
import android.app.Activity;
import android.os.Bundle;
import android.widget.LinearLayout;
public class AdPuisorSample extends Activity {
private AdView adView;
private static final String AD_UNIT_ID = "INSERT_YOUR_AD_UNIT_ID_HERE";
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Create an ad.
adView = new AdView(this);
adView.setAdSize(AdSize.BANNER);
adView.setAdUnitId(AD_UNIT_ID);
// Add the AdView to the view hierarchy. The view will have no size
// until the ad is loaded.
LinearLayout layout = (LinearLayout) findViewById(R.id.linearLayout);
layout.addView(adView);
// Create an ad request. Check logcat output for the hashed device ID to
// get test ads on a physical device.
AdRequest adRequest = new AdRequest.Builder()
.addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
.addTestDevice("INSERT_YOUR_HASHED_DEVICE_ID_HERE")
.build();
// Start loading the ad in the background.
adView.loadAd(adRequest);
}
#Override
public void onResume() {
super.onResume();
if (adView != null) {
adView.resume();
}
}
#Override
public void onPause() {
if (adView != null) {
adView.pause();
}
super.onPause();
}
/** Called before the activity is destroyed. */
#Override
public void onDestroy() {
// Destroy the AdView.
if (adView != null) {
adView.destroy();
}
super.onDestroy();
}
}
I was adding the Google Cloud Messaging service to my App and altered my manifest file. I get the following StackTrace.
02-27 18:58:11.282: E/AndroidRuntime(988): FATAL EXCEPTION: main
02-27 18:58:11.282: E/AndroidRuntime(988): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.phptest/com.example.phptest.MainActivity}: java.lang.ClassNotFoundException: com.example.phptest.MainActivity
02-27 18:58:11.282: E/AndroidRuntime(988): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1983)
02-27 18:58:11.282: E/AndroidRuntime(988): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
02-27 18:58:11.282: E/AndroidRuntime(988): at android.app.ActivityThread.access$600(ActivityThread.java:130)
02-27 18:58:11.282: E/AndroidRuntime(988): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
02-27 18:58:11.282: E/AndroidRuntime(988): at android.os.Handler.dispatchMessage(Handler.java:99)
02-27 18:58:11.282: E/AndroidRuntime(988): at android.os.Looper.loop(Looper.java:137)
02-27 18:58:11.282: E/AndroidRuntime(988): at android.app.ActivityThread.main(ActivityThread.java:4745)
02-27 18:58:11.282: E/AndroidRuntime(988): at java.lang.reflect.Method.invokeNative(Native Method)
02-27 18:58:11.282: E/AndroidRuntime(988): at java.lang.reflect.Method.invoke(Method.java:511)
02-27 18:58:11.282: E/AndroidRuntime(988): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
02-27 18:58:11.282: E/AndroidRuntime(988): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
02-27 18:58:11.282: E/AndroidRuntime(988): at dalvik.system.NativeStart.main(Native Method)
02-27 18:58:11.282: E/AndroidRuntime(988): Caused by: java.lang.ClassNotFoundException: com.example.phptest.MainActivity
02-27 18:58:11.282: E/AndroidRuntime(988): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
02-27 18:58:11.282: E/AndroidRuntime(988): at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
02-27 18:58:11.282: E/AndroidRuntime(988): at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
02-27 18:58:11.282: E/AndroidRuntime(988): at android.app.Instrumentation.newActivity(Instrumentation.java:1053)
02-27 18:58:11.282: E/AndroidRuntime(988): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1974)
02-27 18:58:11.282: E/AndroidRuntime(988): ... 11 more
Here is my Manifest file:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.phptest"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="10"
android:targetSdkVersion="16" />
<uses-configuration />
<permission
android:name="com.example.phptest.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="com.example.phptest.permission.C2D_MESSAGE" />
<!-- App receives GCM messages. -->
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<!-- GCM connects to Google Services. -->
<uses-permission android:name="android.permission.INTERNET" />
<!-- GCM requires a Google account. -->
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<!-- Keeps the processor from sleeping when a message is received. -->
<uses-permission android:name="android.permission.WAKE_LOCK" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.phptest.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>
<service android:name=".GCMIntentService" />
<receiver
android:name="com.google.android.gcm.GCMBroadcastReceiver"
android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<category android:name="com.example.phptest" />
</intent-filter>
</receiver>
</application>
</manifest>
MainActivity:
package com.example.phptest;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import com.example.phptest.DeviceLogin.LoginReply;
import com.google.android.gcm.GCMRegistrar;
import android.os.Bundle;
import android.app.Activity;
import android.util.Log;
import android.view.Menu;
public class MainActivity extends Activity implements LoginReply {
String TAG = "Main Activity";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
DeviceLogin d = new DeviceLogin(this);
d.execute("xxxx","12345");
GCMRegistrar.checkDevice(this);
GCMRegistrar.checkManifest(this);
final String regId = GCMRegistrar.getRegistrationId(this);
if (regId.equals("")) {
GCMRegistrar.register(this, GCMIntentService.senderId);
} else {
Log.v(TAG, "Already registered");
}
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
public static String makeCall(String scriptName) {
String address = "http://10.0.2.2/" + scriptName + ".php";
HttpPost httpPost = new HttpPost(address);
HttpClient httpClient = new DefaultHttpClient();
StringBuilder total = new StringBuilder();
try {
//httpPost.setEntity(new UrlEncodedFormEntity(params));
// Execute HTTP Post Request
HttpResponse response = httpClient.execute(httpPost);
InputStream is = response.getEntity().getContent();
BufferedReader rd = new BufferedReader(new InputStreamReader(is));
String line = "";
// Read response until the end
while ((line = rd.readLine()) != null) {
total.append(line);
}
// Return full string
System.out.println("TOTAL: " + total.toString());
return total.toString();
} catch (Exception e) {
e.printStackTrace();
}
return "empty";
}
public void onDevicesDownloaded(String login) {
// TODO Auto-generated method stub
}
}
Any ideas?
I have seen Android apps get finicky when the full path is specified in the name attribute unless the package the class is in differs from the one you specify at the top of the manifest file. Try changing it to just ".MainActivity" and see if that makes it happy.
Solution was to clean project, D'oh! xD
I have viewed most of the other threads regarding this error but have not found an answer.
I started a new project a couple of weeks ago using a plugin and the example project with the plugin. Added various of my own features and designs and no problems running the project.
Then updated to ADT 17 2 days ago and this seriously messed things up for me. Started getting class path errors to name a few. I then reverted back to adt 16 which fixed the errors and my project compiles fine but as soon as i run it it crashes on the test device.
I have checked that my compliance level is correct, checked library paths, api versions, manifest xml, basically everything. I do not get how something that use to work perfectly can now just not work.
I proceeded to unistall everything and did a reinstall on the sdk's ADT and java, but to no avail, even just trying to run the example project just crashes.
I have aslo uninstalled the app from the device and rbooted the device and cleared the cache. I am at the end of my rope. Like i say, i have checked libraries and everything, its just this runtime error.
I also increased the connection time out, and added "android:installLocation="preferExternal" to my manifest, no change.
Please help, there cant be an issue with the code as it worked perfectly.
Please see the code for the starting activity:
package com.yourcompany.junaioplugin.template;
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import com.yourcompany.junaioplugin.template.R;
import com.metaio.junaio.plugin.JunaioPlugin;
public class SplashActivity extends Activity
{
static
{
JunaioPlugin.loadNativeLibs();
}
/**
* standard tag used for all the debug messages
*/
public static final String TAG = "junaioPluginTemplate";
/**
* Display log messages with debug priority
*
* #param msg Message to display
* #see Log#d(String, String)
*/
public static void log(String msg)
{
if (msg != null)
Log.d(TAG, msg);
}
/**
* Progress dialog
*/
private ProgressDialog progressDialog;
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView( R.layout.main );
JunaioStarterTask junaioStarter = new JunaioStarterTask();
junaioStarter.execute(1);
}
private class JunaioStarterTask extends AsyncTask<Integer, Integer, Integer>
{
#Override
protected void onPreExecute()
{
progressDialog = ProgressDialog.show(SplashActivity.this, "junaio", "Starting up...");
}
#Override
protected Integer doInBackground(Integer... params)
{
// Set authentication if a private channel is used
// JunaioPlugin.setAuthentication("username", "password");
// Start junaio, this will initialize everything the plugin need
int result = JunaioPlugin.startJunaio(this, getApplicationContext());
return result;
}
#Override
protected void onProgressUpdate(Integer... progress)
{
}
#Override
protected void onPostExecute(Integer result)
{
if (progressDialog != null)
{
progressDialog.cancel();
progressDialog = null;
}
switch (result)
{
case JunaioPlugin.ERROR_EXSTORAGE:
SplashActivity.log("External storage is not available, closing...");
finish();
break;
case JunaioPlugin.ERROR_INSTORAGE:
SplashActivity.log("Internal storage is not available, closing...");
finish();
break;
case JunaioPlugin.CANCELLED:
SplashActivity.log("Starting junaio cancelled");
break;
case JunaioPlugin.SUCCESS:
JunaioPlugin.setAuthentication("junaioTester", "test123");
launchLiveView();
break;
}
}
}
/**
* Launch junaio live view
*/
private void launchLiveView()
{
startActivity(new Intent(this, JunaioARViewTestActivity.class));
finish();
}
#Override
protected void onResume()
{
super.onResume();
}
#Override
protected void onPause()
{
super.onPause();
}
#Override
protected void onStop()
{
super.onStop();
if (progressDialog != null)
{
progressDialog.cancel();
progressDialog = null;
}
}
}
Here is the logcat:
03-27 10:47:47.543: I/dalvikvm(10641): Could not find method com.metaio.junaio.plugin.JunaioPlugin.loadNativeLibs, referenced from method com.yourcompany.junaioplugin.template.SplashActivity.<clinit>
03-27 10:47:47.543: W/dalvikvm(10641): VFY: unable to resolve static method 65: Lcom/metaio/junaio/plugin/JunaioPlugin;.loadNativeLibs ()V
03-27 10:47:47.543: D/dalvikvm(10641): VFY: replacing opcode 0x71 at 0x0000
03-27 10:47:47.543: D/dalvikvm(10641): VFY: dead code 0x0003-0003 in Lcom/yourcompany/junaioplugin/template/SplashActivity;.<clinit> ()V
03-27 10:47:47.543: W/dalvikvm(10641): Unable to resolve superclass of Lcom/yourcompany/junaioplugin/template/JunaioARViewTestActivity; (48)
03-27 10:47:47.543: W/dalvikvm(10641): Link of class 'Lcom/yourcompany/junaioplugin/template/JunaioARViewTestActivity;' failed
03-27 10:47:47.547: E/dalvikvm(10641): Could not find class 'com.yourcompany.junaioplugin.template.JunaioARViewTestActivity', referenced from method com.yourcompany.junaioplugin.template.SplashActivity.launchLiveView
03-27 10:47:47.547: W/dalvikvm(10641): VFY: unable to resolve const-class 78 (Lcom/yourcompany/junaioplugin/template/JunaioARViewTestActivity;) in Lcom/yourcompany/junaioplugin/template/SplashActivity;
03-27 10:47:47.547: D/dalvikvm(10641): VFY: replacing opcode 0x1c at 0x0002
03-27 10:47:47.547: D/dalvikvm(10641): VFY: dead code 0x0004-000d in Lcom/yourcompany/junaioplugin/template/SplashActivity;.launchLiveView ()V
03-27 10:47:47.547: W/dalvikvm(10641): Exception Ljava/lang/NoClassDefFoundError; thrown during Lcom/yourcompany/junaioplugin/template/SplashActivity;.<clinit>
03-27 10:47:47.547: W/dalvikvm(10641): Class init failed in newInstance call (Lcom/yourcompany/junaioplugin/template/SplashActivity;)
03-27 10:47:47.547: D/AndroidRuntime(10641): Shutting down VM
03-27 10:47:47.547: W/dalvikvm(10641): threadid=1: thread exiting with uncaught exception (group=0x4001d7d0)
03-27 10:47:47.555: E/AndroidRuntime(10641): FATAL EXCEPTION: main
03-27 10:47:47.555: E/AndroidRuntime(10641): java.lang.ExceptionInInitializerError
03-27 10:47:47.555: E/AndroidRuntime(10641): at java.lang.Class.newInstanceImpl(Native Method)
03-27 10:47:47.555: E/AndroidRuntime(10641): at java.lang.Class.newInstance(Class.java:1429)
03-27 10:47:47.555: E/AndroidRuntime(10641): at android.app.Instrumentation.newActivity(Instrumentation.java:1023)
03-27 10:47:47.555: E/AndroidRuntime(10641): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2577)
03-27 10:47:47.555: E/AndroidRuntime(10641): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
03-27 10:47:47.555: E/AndroidRuntime(10641): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
03-27 10:47:47.555: E/AndroidRuntime(10641): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
03-27 10:47:47.555: E/AndroidRuntime(10641): at android.os.Handler.dispatchMessage(Handler.java:99)
03-27 10:47:47.555: E/AndroidRuntime(10641): at android.os.Looper.loop(Looper.java:123)
03-27 10:47:47.555: E/AndroidRuntime(10641): at android.app.ActivityThread.main(ActivityThread.java:4627)
03-27 10:47:47.555: E/AndroidRuntime(10641): at java.lang.reflect.Method.invokeNative(Native Method)
03-27 10:47:47.555: E/AndroidRuntime(10641): at java.lang.reflect.Method.invoke(Method.java:521)
03-27 10:47:47.555: E/AndroidRuntime(10641): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
03-27 10:47:47.555: E/AndroidRuntime(10641): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
03-27 10:47:47.555: E/AndroidRuntime(10641): at dalvik.system.NativeStart.main(Native Method)
03-27 10:47:47.555: E/AndroidRuntime(10641): Caused by: java.lang.NoClassDefFoundError: com.metaio.junaio.plugin.JunaioPlugin
03-27 10:47:47.555: E/AndroidRuntime(10641): at com.yourcompany.junaioplugin.template.SplashActivity.<clinit>(SplashActivity.java:19)
03-27 10:47:47.555: E/AndroidRuntime(10641): ... 15 more
Here is the manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
android:versionCode="3"
android:versionName="3.5.1" package="com.yourcompany.junaioplugin.template"
android:installLocation="preferExternal">
<!-- The application must be compiled using Google APIs (Android 3.0) -->
<!-- However, target and min SDK can be 8 (Android 2.2) -->
<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="8"/>
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.ACCESS_SURFACE_FLINGER" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<uses-permission android:name="android.permission.WAKE_LOCK"/>
<uses-feature android:name="android.hardware.camera" android:required="false"/>
<uses-feature android:name="android.hardware.camera.autofocus" android:required="false"/>
<uses-feature android:name="android.hardware.location.gps" android:required="false"/>
<uses-feature android:name="android.hardware.sensor.accelerometer" android:required="false"/>
<uses-feature android:name="android.hardware.sensor.compass" android:required="false"/>
<uses-feature android:glEsVersion="0x00020000" android:required="true" />
<application
android:label="#string/app_name"
android:icon="#drawable/icon"
android:debuggable="true">
<uses-library android:name="com.google.android.maps" />
<!-- Start screen -->
<activity android:name=".SplashActivity"
android:theme="#style/Theme.Fullscreen"
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>
<!-- junaio AR view activity -->
<activity
android:name=".JunaioARViewTestActivity"
android:theme="#style/Theme.Fullscreen"
android:configChanges="orientation"
android:screenOrientation="landscape">
</activity>
<activity
android:name="com.metaio.junaio.plugin.view.POIDetailDialog"
android:theme="#style/Theme.POIDialog"
android:screenOrientation="landscape">
</activity>
<activity
android:name="com.metaio.junaio.plugin.view.WebViewActivity"
android:theme="#style/Theme.Fullscreen"
android:configChanges="orientation">"
</activity>
<activity
android:name="com.metaio.junaio.plugin.view.ImageViewActivity"
android:theme="#style/Theme.Fullscreen"
android:configChanges="orientation">
</activity>
</application>
</manifest>
For me, when I installed ADT 17 I have problems using 3rd party libraries (It kept telling me there were duplications). It turns out that they no longer need to be added to the build path; just kept in a folder in the root of your project called "libs". Could this be the same problem?