-1

I am creating an android application that consists of database registration.In the other activity I placed a button to retrieve data from database displayed in a text view. I did some thing to do like this but it was showing an error called NoClassDefFoundError. Please Help me with this. Please excuse if there is any mistakes. Thanks in advance. This is my main activity:

package com.developer.and;


import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;

import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;

public class Modes extends Activity {

    Button auto,manual,adminsettings;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.modes);


        auto = (Button)findViewById(R.id.button_auto);
        auto.setOnClickListener(new View.OnClickListener() {

            public void onClick(View v) {
                Intent auto = new Intent(Modes.this,Auto.class);
                startActivity(auto);
            }
        });

        manual = (Button)findViewById(R.id.button_manualmode);
        manual.setOnClickListener(new View.OnClickListener() {

            public void onClick(View v) {

                Intent manual = new Intent(Modes.this,Manual.class);
                startActivity(manual);

            }
        });
        adminsettings = (Button)findViewById(R.id.button_Adminsettings);

        savedInstanceState = getIntent().getExtras();
        if(savedInstanceState!=null){
            String value_username = savedInstanceState.getString("USERNAME"); //getting username key,value pairs sent from previous intents

            String value_password = savedInstanceState.getString("PASSWORD"); //getting password key,value pairs sent from previous intents

            if(value_username.equals("medequip") && value_password.equals("medequip")){   //Comparing username and password sent from previous intent activity to display admin settings button or not...

            adminsettings.setVisibility(View.VISIBLE);                          //setting visibility for a button
            adminsettings.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    Intent retriving_database = new Intent (Modes.this,AdminSettings.class);
                    startActivity(retriving_database);

                }
            });


            }
            else
            adminsettings.setVisibility(View.GONE);
        }

    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.modes, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();
        if (id == R.id.action_settings) {
            return true;
        }
        return super.onOptionsItemSelected(item);
    }
}

This is my second activity to fetch database results

package com.developer.and;

import android.database.Cursor;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import com.developer.milanandroid.LoginDataBaseAdapter;

public class AdminSettings extends ActionBarActivity {
    LoginDataBaseAdapter logindatabase_adapter_child;
    Button fetch_database;
    TextView text_fetched_database_results;
    String username,password;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.admin_settings);

        fetch_database = (Button)findViewById(R.id.Button_Fetch_Database);
        fetch_database.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                Cursor c = logindatabase_adapter_child.db.rawQuery("select * from MilanloginRegistration", null);
                text_fetched_database_results.setText("");
                c.moveToFirst();
                do{
                    username = c.getString(c.getColumnIndex("USERNAME"));
                    password = c.getString(1);
                    text_fetched_database_results.append("USERNAME::-->"+username+"PASSWORD::-->"+password+"\n");

                }while(c.moveToNext());
            }
        });
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.admin_settings, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();
        if (id == R.id.action_settings) {
            return true;
        }
        return super.onOptionsItemSelected(item);
    }
}

MainActivity.xml:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.developer.and.Modes" >

   <Button
        android:id="@+id/button_Adminsettings"
        android:layout_width="450dp"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:text="@string/Adminsettings" />

</RelativeLayout>

This is my second activity xml:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.developer.and.AdminSettings" >

    <LinearLayout
        android:id="@+id/linearLayout1"
        android:layout_width="@dimen/Retriving_database_ll_width"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:orientation="vertical" >

        <Button
            android:id="@+id/Button_Fetch_Database"
            style="?android:attr/buttonStyleSmall"
            android:layout_width="@dimen/Retriving_database_Button_width"
            android:layout_height="wrap_content"
            android:text="@string/Retriving_database" />
    </LinearLayout>

    <ScrollView
        android:id="@+id/scrollView_db_contacts"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true"
        android:layout_toRightOf="@+id/linearLayout1" >

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical" >

            <TextView
                android:id="@+id/textView_fetched_database_results"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:textSize="20sp" />
        </LinearLayout>
    </ScrollView>

</RelativeLayout>

This is my logcat:

04-27 11:32:41.910: E/AndroidRuntime(13452): FATAL EXCEPTION: main
04-27 11:32:41.910: E/AndroidRuntime(13452): Process: com.developer.milanandroid, PID: 13452
04-27 11:32:41.910: E/AndroidRuntime(13452): java.lang.NoClassDefFoundError: com.developer.milanandroid.AdminSettings
04-27 11:32:41.910: E/AndroidRuntime(13452):    at com.developer.milanandroid.Modes$3.onClick(Modes.java:56)
04-27 11:32:41.910: E/AndroidRuntime(13452):    at android.view.View.performClick(View.java:4438)
04-27 11:32:41.910: E/AndroidRuntime(13452):    at android.view.View$PerformClick.run(View.java:18422)
04-27 11:32:41.910: E/AndroidRuntime(13452):    at android.os.Handler.handleCallback(Handler.java:733)
04-27 11:32:41.910: E/AndroidRuntime(13452):    at android.os.Handler.dispatchMessage(Handler.java:95)
04-27 11:32:41.910: E/AndroidRuntime(13452):    at android.os.Looper.loop(Looper.java:136)
04-27 11:32:41.910: E/AndroidRuntime(13452):    at android.app.ActivityThread.main(ActivityThread.java:5017)
04-27 11:32:41.910: E/AndroidRuntime(13452):    at java.lang.reflect.Method.invokeNative(Native Method)
04-27 11:32:41.910: E/AndroidRuntime(13452):    at java.lang.reflect.Method.invoke(Method.java:515)
04-27 11:32:41.910: E/AndroidRuntime(13452):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
04-27 11:32:41.910: E/AndroidRuntime(13452):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
04-27 11:32:41.910: E/AndroidRuntime(13452):    at dalvik.system.NativeStart.main(Native Method)
Sundeep
  • 81
  • 1
  • 3
  • 12

2 Answers2

1

Your Class AdminSetting and Mode is in package com.developer.and but not com.developer.milanandroid. Change the package name in line 1 of two files, then compiler can find the class.

Desmond Yao
  • 545
  • 1
  • 4
  • 10
  • sorry dude formy project sake i changed packages names on this post actually it was com.developer.milanandroid was there in above two classes@Desmond Yao – Sundeep Apr 27 '15 at 11:50
0

Your classes AdminSettings and Modes is in package com.developer.and and not in com.developer.milanandroid. So either change package name in your project explore or in AndroidManifest to match each other. Currently in your project you have package com.developer.and but in your AndroidManifest it seems you are using package com.developer.milanandroid.

Rajen Raiyarela
  • 5,526
  • 4
  • 21
  • 41
  • sorry dude formy project sake i changed packages names on this post actually it was com.developer.milanandroid was there in above two classes @Rajen Raiyarela – Sundeep Apr 27 '15 at 12:00