Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PhoneGap class not found error in android

I am facing some problem with my PhoneGap(Android) application. So far I understand, I have done everything well. Here is what I have done.

  1. After creating a project in Eclipse, I have added cordova-2.2.0.jar in my libs folder.
  2. Then I edited AndroidManifest.xml and MainActivity.java
  3. I created www folder inside assets folder and keep cordova-2.2.0.js and index.html

So, far everything was OK. But when I run this program, it is showing an error. I have attached a screenshot and sample code.

enter image description here

AndroidManifest.xml

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.hellopgap"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="15" />

    <supports-screens
        android:largeScreens="true"
        android:normalScreens="true"
        android:smallScreens="true"
        android:xlargeScreens="true"
        android:resizeable="true"
        android:anyDensity="true"
        />

    <uses-permission android:name="android.permission.CAMERA" />
    <uses-permission android:name="android.permission.VIBRATE" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.RECEIVE_SMS" />
    <uses-permission android:name="android.permission.RECORD_AUDIO" />
    <uses-permission android:name="android.permission.RECORD_VIDEO"/>
    <uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
    <uses-permission android:name="android.permission.READ_CONTACTS" />
    <uses-permission android:name="android.permission.WRITE_CONTACTS" />   
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />   
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.GET_ACCOUNTS" />
    <uses-permission android:name="android.permission.BROADCAST_STICKY" />

    <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>

MainActivity.java

package com.example.hellopgap;

import android.app.Activity;
import android.os.Bundle;
import org.apache.cordova.*;

public class MainActivity extends DroidGap {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        super.loadUrl("file:///android_asset/www/index.html");
    }   
}

index.html

<!DOCTYPE html>

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <meta name="format-detection" content="telephone=no" />
        <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height, target-densitydpi=device-dpi" />
        <script type="text/javascript" charset="utf-8" src="cordova-2.2.0.js"></script>
        <script type="text/javascript" charset="utf-8">

            // Wait for Cordova to load
            //
            document.addEventListener("deviceready", onDeviceReady, false);

            // Cordova is ready
            //
            function onDeviceReady() {
                // Empty

            }

            // alert dialog dismissed
            function alertDismissed() {
                // do something
            }

            // Show a custom alertDismissed
            //
            function showAlert() {
                navigator.notification.alert(
                    'You are the winner!',  // message
                    alertDismissed,         // callback
                    'Game Over',            // title
                    'Done'                  // buttonName
                );
            }

    </script>

        <title>Notification Example</title>
    </head>
    <body>
        <div class="app">
            <h1>Apache Cordova</h1>
            <h3>This is sample PhoneGap apps</h3>
            <p><a href="#" onclick="showAlert(); return false;">Show Alert</a></p>
        </div>

    </body>
</html>

Thanks, in advance.

like image 892
Shahjalal Avatar asked Jan 14 '23 08:01

Shahjalal


2 Answers

I was having same issue before. I have just follow below steps and it starts working :

  • Go to Selected project's Properties
  • Go to java build path
  • Select 'Order and Export'
  • Enable all the checks (dependent projects)
  • Now just clean and run application again.

It works for me...

like image 144
Nirav Shah Avatar answered Jan 21 '23 06:01

Nirav Shah


Seems like you are missing config.xml in your apps res/xml directory. It is included as part of the phonegap distribution,at lib/android/res/xml/config.xml. Copy that file into your res/xml directory and you should be fine.

like image 20
roxxypoxxy Avatar answered Jan 21 '23 06:01

roxxypoxxy