0

Possible Duplicate:
How to use an existing database with an Android application

I have to add items to listview by using arrayadapter in android so done the coding, my xml layout file name is "jobs", but i'm getting error as "jobs cannot be resolved or is not a field", i had inlucded this activity in manifest but still same error

public class Jobs extends ListActivity {
private TextView selection;

private static final String[] items={"Computer Hardware", "Featured", "Information Technology", "Software", "Technical"

};
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.jobs);
    ListView list = (ListView)findViewById(R.id.list);
    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
            android.R.layout.jobs, items);
        setListAdapter(adapter);    


 }
public void onListItemClick(ListView parent, View v, int position, long id)
{
    selection.setText(items[position]);
}
 }

This is xml layout file

<?xml version="1.0" encoding="utf-8"?>
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView 
    android:id="@+id/selection"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"/>

<ListView
    android:id="@+id/list"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" >
</ListView>

manifest.xml

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

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

<uses-permission android:name="android.permission.INTERNET" />

<application
    android:icon="@drawable/rebuix"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" 
    android:background="#3D0909">
    <activity
        android:name=".LoadingScreen"
        android:label="@string/title_activity_loading_screen" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity
        android:name=".Rebuix"
        android:label="@string/title_activity_rebuix" >
        <meta-data
            android:name="android.support.PARENT_ACTIVITY"
            android:value="com.rebuix.com.Rebuix" />
    </activity>
    <activity
        android:name=".com.rebuix.com.Jobs"
        android:label="@string/app_name" >

    </activity>
    <activity
        android:name=".Login"
        android:label="@string/title_activity_login" >
        <meta-data
            android:name="android.support.PARENT_ACTIVITY"
            android:value="com.rebuix.com.Rebuix" />
    </activity>
    <activity
        android:name=".About"
        android:label="@string/title_activity_about" >
        <meta-data
            android:name="android.support.PARENT_ACTIVITY"
            android:value="android.support.v4.app.FragmentActivity" />
    </activity>
    <activity
        android:name=".Home"
        android:label="@string/title_activity_home" >
        <meta-data
            android:name="android.support.PARENT_ACTIVITY"
            android:value="android.support.v4.app.FragmentActivity" />
    </activity>
    <activity
        android:name=".Changepassword"
        android:label="@string/title_activity_changepassword" >
        <meta-data
            android:name="android.support.PARENT_ACTIVITY"
            android:value="android.support.v4.app.FragmentActivity" />
    </activity>
   </application>

   </manifest>

logcat output

01-31 12:31:53.133: I/Tutorial(531): Starting task with url: www.google.co.uk
01-31 12:32:03.972: D/dalvikvm(531): GC_EXTERNAL_ALLOC freed 64K, 52% free  2595K/5379K, external 1645K/2137K, paused 52ms
01-31 12:32:04.102: D/dalvikvm(531): GC_EXTERNAL_ALLOC freed 2K, 52% free 2594K/5379K, external 2687K/3355K, paused 45ms
01-31 12:32:08.083: D/AndroidRuntime(531): Shutting down VM
01-31 12:32:08.083: W/dalvikvm(531): threadid=1: thread exiting with uncaught exception (group=0x40015560)
01-31 12:32:08.103: E/AndroidRuntime(531): FATAL EXCEPTION: main
01-31 12:32:08.103: E/AndroidRuntime(531): android.content.ActivityNotFoundException: Unable to find explicit activity class {com.exm.com/com.exm.com.Jobs}; have you declared this activity in your AndroidManifest.xml?
01-31 12:32:08.103: E/AndroidRuntime(531):  at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1405)
01-31 12:32:08.103: E/AndroidRuntime(531):  at android.app.Instrumentation.execStartActivity(Instrumentation.java:1379)
01-31 12:32:08.103: E/AndroidRuntime(531):  at android.app.Activity.startActivityForResult(Activity.java:2827)
01-31 12:32:08.103: E/AndroidRuntime(531):  at android.app.Activity.startActivity(Activity.java:2933)
01-31 12:32:08.103: E/AndroidRuntime(531):  at com.rebuix.com.Rebuix$4.onClick(Rebuix.java:69)
01-31 12:32:08.103: E/AndroidRuntime(531):  at android.view.View.performClick(View.java:2485)
01-31 12:32:08.103: E/AndroidRuntime(531):  at android.view.View$PerformClick.run(View.java:9080)
01-31 12:32:08.103: E/AndroidRuntime(531):  at android.os.Handler.handleCallback(Handler.java:587)
01-31 12:32:08.103: E/AndroidRuntime(531):  at android.os.Handler.dispatchMessage(Handler.java:92)
01-31 12:32:08.103: E/AndroidRuntime(531):  at android.os.Looper.loop(Looper.java:123)
 01-31 12:32:08.103: E/AndroidRuntime(531):     at android.app.ActivityThread.main(ActivityThread.java:3683)
 01-31 12:32:08.103: E/AndroidRuntime(531):     at  java.lang.reflect.Method.invokeNative(Native Method)
01-31 12:32:08.103: E/AndroidRuntime(531):  at java.lang.reflect.Method.invoke(Method.java:507)
01-31 12:32:08.103: E/AndroidRuntime(531):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
 01-31 12:32:08.103: E/AndroidRuntime(531):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
  01-31 12:32:08.103: E/AndroidRuntime(531):    at dalvik.system.NativeStart.main(Native Method)
Community
  • 1
  • 1
DD.
  • 973
  • 2
  • 10
  • 32

8 Answers8

3

because you are extending ListActivity then declare ListView is as in xml:

android:id="@android:id/list"

and get ListView reference as :

ListView list = (ListView)findViewById(android.R.id.list);

OR

   ListView list = this.getListView();
ρяσѕρєя K
  • 132,198
  • 53
  • 198
  • 213
1

Your problem is:

 ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
            android.R.layout.jobs, items);
        setListAdapter(adapter);    

Remove android:

 ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
            R.layout.jobs, items);
        setListAdapter(adapter);    
Subburaj
  • 5,114
  • 10
  • 44
  • 87
1

try this

public class Jobs extends ListActivity {



 private TextView selection;

private static final String[] items = { "Computer Hardware", "Featured", "Information Technology",
        "Software", "Technical"

};

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.jobs);
    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, items);
    setListAdapter(adapter);

}

public void onListItemClick(ListView parent, View v, int position, long id) {
    selection.setText(items[position]);
}

}

<?xml version="1.0" encoding="utf-8"?>
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView 
    android:id="@+id/selection"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"/>

<ListView
    android:id="@android:id/list"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" >
</ListView>

Explanation :

1 ) So you list in the custom view should be having id android:id="@android:id/list". If you want to add them in a ListActivity .

2 ) You don't map the Items to list-view, rather to list-items. So you have to use either a custom list item or use the android default while adding new ArrayAdapter(this, android.R.layout.simple_list_item_1, items);

Nimish Choudhary
  • 2,048
  • 18
  • 17
  • android.R.layout.simple_list_item_1 ?? i have given my layout name as "jobs" so y should i give "simple_list_item"? – DD. Jan 31 '13 at 06:48
0

Instead of

android.R.layout.jobs

use

R.layout.jobs
Anukool
  • 5,301
  • 8
  • 29
  • 41
0

Looks like you have used the wrong R class. You are referring to your jobs definition as android.R.layout.jobs (which is Android's R class and probably doesn't contain a jobs definition). This should be something like <your package>/R.layout.jobs.

csoltenborn
  • 1,127
  • 1
  • 12
  • 22
0

May your problem is: android.R.layout.jobs

In

ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.jobs, items);
setListAdapter(adapter);

Try it :

ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, items);
Pratik Butani
  • 60,504
  • 58
  • 273
  • 437
0

As your extending your activity by ListActivity then you must need to declare listview id as @android:id/list

android:id="@android:id/list"

in your activity there is no need to declare listview. or otherwise if you want to declare then do as follows

ListView list = (ListView)findViewById(android.R.id.list);
Ram kiran Pachigolla
  • 20,897
  • 15
  • 57
  • 78
0

Not that hard to notice the error, pay attention to the stack trace when you're getting errors.

01-31 12:32:08.103: E/AndroidRuntime(531): android.content.ActivityNotFoundException: Unable to find explicit activity class {com.exm.com/com.exm.com.Jobs}; have you declared this activity in your AndroidManifest.xml?

JanithaR
  • 1,094
  • 2
  • 11
  • 23