user1427230
user1427230

Reputation: 11

Android sdk 3.2. Class.forName() problems

All i am doig is tyrying to switch from one window to the next but i keep getting errors. i have searched google and have not been able to figure out where im going wrong. i hope someone out there can tell me what is going on. here is the error log. Im getting a classnotfound but cant understand why. its in my manifest.

05-30 23:52:51.129: W/System.err(593): java.lang.ClassNotFoundException: com.jmedia.hvacanalizer.NEWCUSTOMER
05-30 23:52:51.149: W/System.err(593):  at java.lang.Class.classForName(Native >Method)
05-30 23:52:51.149: W/System.err(593):  at java.lang.Class.forName(Class.java:227)
05-30 23:52:51.149: W/System.err(593):  at java.lang.Class.forName(Class.java:174)
05-30 23:52:51.149: W/System.err(593):  at com.jmedia.hvacanalizer.HVACAnalizerActivity$1.onClick(HVACAnalizerActivity.java:30)
05-30 23:52:51.169: W/System.err(593):  at android.view.View.performClick(View.java:3110)
05-30 23:52:51.169: W/System.err(593):  at android.view.View$PerformClick.run(View.java:11934)
05-30 23:52:51.169: W/System.err(593):  at android.os.Handler.handleCallback(Handler.java:587)
05-30 23:52:51.179: W/System.err(593):  at android.os.Handler.dispatchMessage(Handler.java:92)
05-30 23:52:51.179: W/System.err(593):  at android.os.Looper.loop(Looper.java:132)
05-30 23:52:51.190: W/System.err(593):  at android.app.ActivityThread.main(ActivityThread.java:4123)
05-30 23:52:51.190: W/System.err(593):  at java.lang.reflect.Method.invokeNative(Native Method)
05-30 23:52:51.190: W/System.err(593):  at java.lang.reflect.Method.invoke(Method.java:491)
05-30 23:52:51.190: W/System.err(593):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
05-30 23:52:51.199: W/System.err(593):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
05-30 23:52:51.199: W/System.err(593):  at dalvik.system.NativeStart.main(Native Method)
05-30 23:52:51.199: W/System.err(593): Caused by: java.lang.NoClassDefFoundError: com.jmedia.hvacanalizer.NEWCUSTOMER
05-30 23:52:51.212: W/System.err(593):  ... 15 more
05-30 23:52:51.219: W/System.err(593): Caused by: java.lang.ClassNotFoundException: com.jmedia.hvacanalizer.NEWCUSTOMER in loader dalvik.system.PathClassLoader[/data/app/com.jmedia.hvacanalizer-2.apk]

05-30 23:52:51.234: W/System.err(593):  at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:251)
05-30 23:52:51.234: W/System.err(593):  at java.lang.ClassLoader.loadClass(ClassLoader.java:540)
05-30 23:52:51.239: W/System.err(593):  at java.lang.ClassLoader.loadClass(ClassLoader.java:500)
05-30 23:52:51.239: W/System.err(593):  ... 15 more

and here is the code from my manifest...

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.jmedia.hvacanalizer"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk android:minSdkVersion="13" />

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >
        <activity
            android:name=".HVACAnalizerActivity"
            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=".newcustomer"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="com.jmedia.hvacanalizer.NEWCUSTOMER" />

                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>
    </application>

</manifest>

and here is the code from my class...

public class HVACAnalizerActivity extends Activity {

    Button bNew, bLookUp;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        initialize();
    }

    public void initialize() {
        bNew = (Button) findViewById(R.id.bNewCustomer);
        bLookUp = (Button) findViewById(R.id.bLUCustomer);
        bNew.setOnClickListener(new View.OnClickListener() {

            //@Override
            public void onClick(View arg0) {
                // TODO Auto-generated method stub
                try {
                    Class<?> newCustomerClass = Class.forName("com.jmedia.hvacanalizer.NEWCUSTOMER");
                    Intent newCustomerIntent = new Intent(
                            HVACAnalizerActivity.this, newCustomerClass);
                    startActivity(newCustomerIntent);

                } catch (ClassNotFoundException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
        });
        bLookUp.setOnClickListener(new View.OnClickListener() {

            //@Override
            public void onClick(View arg0) {
                // TODO Auto-generated method stub
                // Class newCustomerClass = null;

            }
        });
    }

if someone can help me out here that would be great. this is my first attempt at coding for the android and im already about to pull my hair out.

Upvotes: 0

Views: 762

Answers (1)

user1427230
user1427230

Reputation: 11

Just as a reference for others i want to post the answer. I was looking in the wrong spot. The problem was a coding error in the initialize method in the newcustomer class. I think it was where i had referenced the same button that is in my hvacanalizeractivity class by mistake. hope this helps other beginners like me.

Upvotes: 1

Related Questions