How to fix noClassDefFoundError: com.facebook.android.facebook - android

Integrating facebook sdk with android app.before integrating app working fine but once working with facebook app stopped unexpectedly here i am placing the code.suggest me how to fix this
public class MainActivity extends Activity implements OnClickListener {
Button btnTOLogin, btnTOPost, logOut;
String APP_ID;
Facebook fb;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
APP_ID = "308180782571605";
fb = new Facebook(APP_ID);
try {
btnTOLogin = (Button) findViewById(R.id.button1);
btnTOPost = (Button) findViewById(R.id.button2);
logOut = (Button) findViewById(R.id.button3);
btnTOLogin.setOnClickListener(this);
btnTOPost.setOnClickListener(this);
logOut.setOnClickListener(this);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
here logs
08-15 22:08:52.531: E/AndroidRuntime(2151): FATAL EXCEPTION: main
08-15 22:08:52.531: E/AndroidRuntime(2151): java.lang.NoClassDefFoundError: com.facebook.android.Facebook
08-15 22:08:52.531: E/AndroidRuntime(2151): at com.sri.z4globalsoft.MainActivity.onCreate(MainActivity.java:25)
08-15 22:08:52.531: E/AndroidRuntime(2151): at android.app.Activity.performCreate(Activity.java:4465)
08-15 22:08:52.531: E/AndroidRuntime(2151): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
08-15 22:08:52.531: E/AndroidRuntime(2151): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1919)
08-15 22:08:52.531: E/AndroidRuntime(2151): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1980)
08-15 22:08:52.531: E/AndroidRuntime(2151): at android.app.ActivityThread.access$600(ActivityThread.java:122)
08-15 22:08:52.531: E/AndroidRuntime(2151): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1146)
08-15 22:08:52.531: E/AndroidRuntime(2151): at android.os.Handler.dispatchMessage(Handler.java:99)
08-15 22:08:52.531: E/AndroidRuntime(2151): at android.os.Looper.loop(Looper.java:137)
08-15 22:08:52.531: E/AndroidRuntime(2151): at android.app.ActivityThread.main(ActivityThread.java:4340)
08-15 22:08:52.531: E/AndroidRuntime(2151): at java.lang.reflect.Method.invokeNative(Native Method)
08-15 22:08:52.531: E/AndroidRuntime(2151): at java.lang.reflect.Method.invoke(Method.java:511)
08-15 22:08:52.531: E/AndroidRuntime(2151): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
08-15 22:08:52.531: E/AndroidRuntime(2151): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
08-15 22:08:52.531: E/AndroidRuntime(2151): at dalvik.system.NativeStart.main(Native Method)

Go to Project -> Properties -> Java Build Path -> Order & Export and make sure facebook library is ticked.

clean the project..|
go to libs folder select facebookjar right click and select add to build path
(or) Java Build Path -> Order & Export and make sure facebook library is ticked.
some times it depends on order of libraries in order and export move up and down check it may come

Related

Android hello world is not working

My logcat error and code is given below:
public class MainActivity extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
Logcat:
08-15 11:42:43.735: D/AndroidRuntime(1864): Shutting down VM
08-15 11:42:43.735: W/dalvikvm(1864): threadid=1: thread exiting with uncaught exception (group=0xb1d54ce8)
08-15 11:42:43.755: E/AndroidRuntime(1864): FATAL EXCEPTION: main
08-15 11:42:43.755: E/AndroidRuntime(1864): Process: com.example.helloworld, PID: 1864
08-15 11:42:43.755: E/AndroidRuntime(1864): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.helloworld/com.example.helloworld.MainActivity}: android.util.AndroidRuntimeException: You cannot combine swipe dismissal and the action bar.
08-15 11:42:43.755: E/AndroidRuntime(1864): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2197)
08-15 11:42:43.755: E/AndroidRuntime(1864): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2258)
08-15 11:42:43.755: E/AndroidRuntime(1864): at android.app.ActivityThread.access$800(ActivityThread.java:138)
08-15 11:42:43.755: E/AndroidRuntime(1864): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1209)
08-15 11:42:43.755: E/AndroidRuntime(1864): at android.os.Handler.dispatchMessage(Handler.java:102)
08-15 11:42:43.755: E/AndroidRuntime(1864): at android.os.Looper.loop(Looper.java:136)
08-15 11:42:43.755: E/AndroidRuntime(1864): at android.app.ActivityThread.main(ActivityThread.java:5026)
08-15 11:42:43.755: E/AndroidRuntime(1864): at java.lang.reflect.Method.invokeNative(Native Method)
08-15 11:42:43.755: E/AndroidRuntime(1864): at java.lang.reflect.Method.invoke(Method.java:515)
08-15 11:42:43.755: E/AndroidRuntime(1864): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:777)
08-15 11:42:43.755: E/AndroidRuntime(1864): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:602)
08-15 11:42:43.755: E/AndroidRuntime(1864): at dalvik.system.NativeStart.main(Native Method)
08-15 11:42:43.755: E/AndroidRuntime(1864): Caused by: android.util.AndroidRuntimeException: You cannot combine swipe dismissal and the action bar.
08-15 11:42:43.755: E/AndroidRuntime(1864): at com.android.internal.policy.impl.PhoneWindow.requestFeature(PhoneWindow.java:275)
08-15 11:42:43.755: E/AndroidRuntime(1864): at com.android.internal.policy.impl.PhoneWindow.generateLayout(PhoneWindow.java:2872)
08-15 11:42:43.755: E/AndroidRuntime(1864): at com.android.internal.policy.impl.PhoneWindow.installDecor(PhoneWindow.java:3129)
08-15 11:42:43.755: E/AndroidRuntime(1864): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:303)
08-15 11:42:43.755: E/AndroidRuntime(1864): at android.app.Activity.setContentView(Activity.java:1930)
08-15 11:42:43.755: E/AndroidRuntime(1864): at com.example.helloworld.MainActivity.onCreate(MainActivity.java:14)
08-15 11:42:43.755: E/AndroidRuntime(1864): at android.app.Activity.performCreate(Activity.java:5242)
08-15 11:42:43.755: E/AndroidRuntime(1864): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
08-15 11:42:43.755: E/AndroidRuntime(1864): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2161)
08-15 11:42:43.755: E/AndroidRuntime(1864): ... 11 more
In your manifest .xml change target-sdk to 19.!
I think you are targeting the wrong device. If memory serves me right, it sounds like you might be targeting Android Wear.
If you are developing a mobile application, change your target sdk to API 19

Run time exception: unable to instantiate activity component [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Closed 9 years ago.
Improve this question
Trying to Integrate facebook sdk to android app but my app is not starting. There are the logs. How can I fix this runtime exception?
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ImageView pic = (ImageView) findViewById(R.id.imageView1);
Button btn = (Button) findViewById(R.id.button1);
btn.setOnClickListener(this);
}
08-15 11:48:21.712: E/AndroidRuntime(564): FATAL EXCEPTION: main
08-15 11:48:21.712: E/AndroidRuntime(564): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.sri.z4globalsoft/com.sri.z4globalsoft.MainActivity}: java.lang.NullPointerException
08-15 11:48:21.712: E/AndroidRuntime(564): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1879)
08-15 11:48:21.712: E/AndroidRuntime(564): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1980)
08-15 11:48:21.712: E/AndroidRuntime(564): at android.app.ActivityThread.access$600(ActivityThread.java:122)
08-15 11:48:21.712: E/AndroidRuntime(564): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1146)
08-15 11:48:21.712: E/AndroidRuntime(564): at android.os.Handler.dispatchMessage(Handler.java:99)
08-15 11:48:21.712: E/AndroidRuntime(564): at android.os.Looper.loop(Looper.java:137)
08-15 11:48:21.712: E/AndroidRuntime(564): at android.app.ActivityThread.main(ActivityThread.java:4340)
08-15 11:48:21.712: E/AndroidRuntime(564): at java.lang.reflect.Method.invokeNative(Native Method)
08-15 11:48:21.712: E/AndroidRuntime(564): at java.lang.reflect.Method.invoke(Method.java:511)
08-15 11:48:21.712: E/AndroidRuntime(564): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
08-15 11:48:21.712: E/AndroidRuntime(564): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
08-15 11:48:21.712: E/AndroidRuntime(564): at dalvik.system.NativeStart.main(Native Method)
08-15 11:48:21.712: E/AndroidRuntime(564): Caused by: java.lang.NullPointerException
08-15 11:48:21.712: E/AndroidRuntime(564): at android.content.ContextWrapper.getResources(ContextWrapper.java:81)
08-15 11:48:21.712: E/AndroidRuntime(564): at com.sri.z4globalsoft.MainActivity.<init>(MainActivity.java:23)
08-15 11:48:21.712: E/AndroidRuntime(564): at java.lang.Class.newInstanceImpl(Native Method)
08-15 11:48:21.712: E/AndroidRuntime(564): at java.lang.Class.newInstance(Class.java:1319)
08-15 11:48:21.712: E/AndroidRuntime(564): at android.app.Instrumentation.newActivity(Instrumentation.java:1023)
08-15 11:48:21.712: E/AndroidRuntime(564): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1870)
08-15 11:48:21.712: E/AndroidRuntime(564): ... 11 more
Tried by changing the code ap per your answers given below then also having problem
08-15 12:25:00.800: E/AndroidRuntime(712): FATAL EXCEPTION: main
08-15 12:25:00.800: E/AndroidRuntime(712): java.lang.NoClassDefFoundError: com.facebook.android.Facebook
08-15 12:25:00.800: E/AndroidRuntime(712): at com.sri.z4globalsoft.MainActivity.<init>(MainActivity.java:25)
08-15 12:25:00.800: E/AndroidRuntime(712): at java.lang.Class.newInstanceImpl(Native Method)
08-15 12:25:00.800: E/AndroidRuntime(712): at java.lang.Class.newInstance(Class.java:1319)
08-15 12:25:00.800: E/AndroidRuntime(712): at android.app.Instrumentation.newActivity(Instrumentation.java:1023)
08-15 12:25:00.800: E/AndroidRuntime(712): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1870)
08-15 12:25:00.800: E/AndroidRuntime(712): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1980)
08-15 12:25:00.800: E/AndroidRuntime(712): at android.app.ActivityThread.access$600(ActivityThread.java:122)
08-15 12:25:00.800: E/AndroidRuntime(712): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1146)
08-15 12:25:00.800: E/AndroidRuntime(712): at android.os.Handler.dispatchMessage(Handler.java:99)
08-15 12:25:00.800: E/AndroidRuntime(712): at android.os.Looper.loop(Looper.java:137)
08-15 12:25:00.800: E/AndroidRuntime(712): at android.app.ActivityThread.main(ActivityThread.java:4340)
08-15 12:25:00.800: E/AndroidRuntime(712): at java.lang.reflect.Method.invokeNative(Native Method)
08-15 12:25:00.800: E/AndroidRuntime(712): at java.lang.reflect.Method.invoke(Method.java:511)
08-15 12:25:00.800: E/AndroidRuntime(712): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
08-15 12:25:00.800: E/AndroidRuntime(712): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
08-15 12:25:00.800: E/AndroidRuntime(712): at dalvik.system.NativeStart.main(Native Method)
It sound like you might be trying to use getResources() before they are technically ready.
If you have this:
String APP_ID = getResources().getString(R.string.APP_ID);
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
...
}
Do this instead:
String APP_ID;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
APP_ID = getResources().getString(R.string.APP_ID);
...
}
08-15 11:48:21.712: E/AndroidRuntime(564): Caused by: java.lang.NullPointerException
08-15 11:48:21.712: E/AndroidRuntime(564): at android.content.ContextWrapper.getResources(ContextWrapper.java:81)
08-15 11:48:21.712: E/AndroidRuntime(564): at com.sri.z4globalsoft.MainActivity.<init>(MainActivity.java:23)
You're trying to initialize a member variable where the initialization is using this as Context. In this case it's the getResources() call. You can only use the Activity as a Context in onCreate() or later in the activity lifecycle.
Specifically (from question comments), change this:
String APP_ID = getResources().getString(R.string.APP_ID);
to something like:
String APP_ID;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
APP_ID = getResources().getString(R.string.APP_ID);
//...

unfortunately camera has stopped android emulator

I am just trying to launch camera from my android emulator and I am getting the above error
unfortunately camera has stopped android emulator and it stopped
My Android Version 4.0.3 and API 15
My Logs are below ,I have already gone through the other posts in stack overflow related to this but no luck
08-15 18:55:53.361: E/EmulatedCamera_QemuClient(38): queryFrame: Query failed: Unable to obtain video frame from the camera
08-15 18:55:53.361: E/EmulatedCamera_QemuDevice(38): inWorkerThread: Unable to get current video frame: Invalid argument
08-15 18:55:53.401: I/dalvikvm(472): Wrote stack traces to '/data/anr/traces.txt'
08-15 18:55:53.561: E/Camera(472): Error 100
08-15 18:55:53.561: E/CameraErrorCallback(472): Got camera error callback. error=100
08-15 18:55:53.571: D/AndroidRuntime(472): Shutting down VM
08-15 18:55:53.571: W/dalvikvm(472): threadid=1: thread exiting with uncaught exception (group=0x409c01f8)
08-15 18:55:53.591: E/AndroidRuntime(472): FATAL EXCEPTION: main
08-15 18:55:53.591: E/AndroidRuntime(472): java.lang.RuntimeException: Media server died.
08-15 18:55:53.591: E/AndroidRuntime(472): at com.android.camera.CameraErrorCallback.onError(CameraErrorCallback.java:31)
08-15 18:55:53.591: E/AndroidRuntime(472): at android.hardware.Camera$EventHandler.handleMessage(Camera.java:736)
08-15 18:55:53.591: E/AndroidRuntime(472): at android.os.Handler.dispatchMessage(Handler.java:99)
08-15 18:55:53.591: E/AndroidRuntime(472): at android.os.Looper.loop(Looper.java:137)
08-15 18:55:53.591: E/AndroidRuntime(472): at android.app.ActivityThread.main(ActivityThread.java:4424)
08-15 18:55:53.591: E/AndroidRuntime(472): at java.lang.reflect.Method.invokeNative(Native Method)
08-15 18:55:53.591: E/AndroidRuntime(472): at java.lang.reflect.Method.invoke(Method.java:511)
08-15 18:55:53.591: E/AndroidRuntime(472): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
08-15 18:55:53.591: E/AndroidRuntime(472): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
08-15 18:55:53.591: E/AndroidRuntime(472): at dalvik.system.NativeStart.main(Native Method)
08-15 18:55:53.621: W/ActivityManager(92): Force finishing activity com.android.camera/.Camera
08-15 18:55:53.631: W/WindowManager(92): Failure taking screenshot for (180x300) to layer 21015
08-15 18:55:53.811: I/Process(92): Sending signal. PID: 472 SIG: 3
08-15 18:55:53.811: I/dalvikvm(472): threadid=3: reacting to signal 3

Exception when downloading XML file from Internet on Android 4 (but it works on Android 2.3)

I have a problem with downloading XML file from Internet in Android. I wrote some code and it works on Android 2.3 emulator. However, it doesn't work on Android 4.03 emulator and it doesn't work on real Android 4 device either.
Here is my code:
public String getXmlFromUrl(String url) {
String xml = null;
try {
// defaultHttpClient
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(url);
HttpResponse httpResponse = httpClient.execute(httpPost);
HttpEntity httpEntity = httpResponse.getEntity();
xml = EntityUtils.toString(httpEntity);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
// return XML
return xml;
}
I have error on line:
HttpResponse httpResponse = httpClient.execute(httpPost);
Here is log from LogCat:
08-15 16:59:32.436: E/AndroidRuntime(623): FATAL EXCEPTION: main
08-15 16:59:32.436: E/AndroidRuntime(623): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.testy/com.example.testy.MainActivity}: android.os.NetworkOnMainThreadException
08-15 16:59:32.436: E/AndroidRuntime(623): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956)
08-15 16:59:32.436: E/AndroidRuntime(623): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
08-15 16:59:32.436: E/AndroidRuntime(623): at android.app.ActivityThread.access$600(ActivityThread.java:123)
08-15 16:59:32.436: E/AndroidRuntime(623): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
08-15 16:59:32.436: E/AndroidRuntime(623): at android.os.Handler.dispatchMessage(Handler.java:99)
08-15 16:59:32.436: E/AndroidRuntime(623): at android.os.Looper.loop(Looper.java:137)
08-15 16:59:32.436: E/AndroidRuntime(623): at android.app.ActivityThread.main(ActivityThread.java:4424)
08-15 16:59:32.436: E/AndroidRuntime(623): at java.lang.reflect.Method.invokeNative(Native Method)
08-15 16:59:32.436: E/AndroidRuntime(623): at java.lang.reflect.Method.invoke(Method.java:511)
08-15 16:59:32.436: E/AndroidRuntime(623): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
08-15 16:59:32.436: E/AndroidRuntime(623): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
08-15 16:59:32.436: E/AndroidRuntime(623): at dalvik.system.NativeStart.main(Native Method)
08-15 16:59:32.436: E/AndroidRuntime(623): Caused by: android.os.NetworkOnMainThreadException
08-15 16:59:32.436: E/AndroidRuntime(623): at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1099)
08-15 16:59:32.436: E/AndroidRuntime(623): at java.net.InetAddress.lookupHostByName(InetAddress.java:391)
08-15 16:59:32.436: E/AndroidRuntime(623): at java.net.InetAddress.getAllByNameImpl(InetAddress.java:242)
08-15 16:59:32.436: E/AndroidRuntime(623): at java.net.InetAddress.getAllByName(InetAddress.java:220)
08-15 16:59:32.436: E/AndroidRuntime(623): at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:137)
08-15 16:59:32.436: E/AndroidRuntime(623): at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164)
08-15 16:59:32.436: E/AndroidRuntime(623): at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119)
08-15 16:59:32.436: E/AndroidRuntime(623): at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:360)
08-15 16:59:32.436: E/AndroidRuntime(623): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
08-15 16:59:32.436: E/AndroidRuntime(623): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
08-15 16:59:32.436: E/AndroidRuntime(623): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465)
08-15 16:59:32.436: E/AndroidRuntime(623): at com.example.testy.XMLParser.getXmlFromUrl(XMLParser.java:54)
08-15 16:59:32.436: E/AndroidRuntime(623): at com.example.testy.MainActivity.onCreate(MainActivity.java:34)
08-15 16:59:32.436: E/AndroidRuntime(623): at android.app.Activity.performCreate(Activity.java:4465)
08-15 16:59:32.436: E/AndroidRuntime(623): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
08-15 16:59:32.436: E/AndroidRuntime(623): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
08-15 16:59:32.436: E/AndroidRuntime(623): ... 11 more
What can I do with it?
You're performing a (potentially slow) network operation on the main thread. If your target SDK is 11 (Honeycomb) or higher this will throw a NetworkOnMainThreadException on Honeycomb or above, because this behaviour can block the UI and lead to an unresponsive app. Even on pre-Honeycomb devices this behaviour is discouraged.
You could use an AsyncTask to get around this, loading the data in its doInBackground(..).
You are using network feature on the main thread. You need to use AsyncTask to accomplish this.
Starting from Honeycomb Strictmode checking is enabled by default. So Network operations raise an exception. Strictmode was not enabled in Gingerbread. Hence it is working in gingerbread but not in ICS

LogCATError while starting new activities

My problem is in starting new activities.
I have ListView, items of it are defined from string-array by this code:
listBanksUA = getResources().getStringArray(R.array.list_banks_ua);
setListAdapter(new ArrayAdapter<String(this,android.R.layout.simple_list_item_1,listBanksUA));
List is defined in layout as:
<ListView android:id="#+id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:drawSelectorOnTop="false"/>
So, I'd like to start new activity after click on item of ListView. Sure, I have created new XML-layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ListView
android:id="#+id/listRegions"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:drawSelectorOnTop="false"/>
</LinearLayout>
and Java-class for it: ListRegionsActivity.class.
In my first Activity I use the follow code to start new Activity:
#Override
protected void onListItemClick(ListView l, View v, int position, long id)
{
startActivity(new Intent(MainActivity.this,ListRegionsActivity.class));
}
and after clicking in started application I'm getting an error, that my application has been closed with advice to try again. Sadness...
So, really I'll be glad for any help for me.
BTW: of course, I added new activity to manifest file.
UPD: my LogCAT with Error flag
08-15 13:46:45.458: ERROR/AndroidRuntime(516): Uncaught handler: thread main exiting due to uncaught exception
08-15 13:46:45.488: ERROR/AndroidRuntime(516): java.lang.RuntimeException: Unable to start activity ComponentInfo{ua.donetsk.jeston.android/ua.donetsk.jeston.android.ListRegionsActivity}: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'
08-15 13:46:45.488: ERROR/AndroidRuntime(516): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2401)
08-15 13:46:45.488: ERROR/AndroidRuntime(516): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2417)
08-15 13:46:45.488: ERROR/AndroidRuntime(516): at android.app.ActivityThread.access$2100(ActivityThread.java:116)
08-15 13:46:45.488: ERROR/AndroidRuntime(516): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1794)
08-15 13:46:45.488: ERROR/AndroidRuntime(516): at android.os.Handler.dispatchMessage(Handler.java:99)
08-15 13:46:45.488: ERROR/AndroidRuntime(516): at android.os.Looper.loop(Looper.java:123)
08-15 13:46:45.488: ERROR/AndroidRuntime(516): at android.app.ActivityThread.main(ActivityThread.java:4203)
08-15 13:46:45.488: ERROR/AndroidRuntime(516): at java.lang.reflect.Method.invokeNative(Native Method)
08-15 13:46:45.488: ERROR/AndroidRuntime(516): at java.lang.reflect.Method.invoke(Method.java:521)
08-15 13:46:45.488: ERROR/AndroidRuntime(516): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791)
08-15 13:46:45.488: ERROR/AndroidRuntime(516): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:549)
08-15 13:46:45.488: ERROR/AndroidRuntime(516): at dalvik.system.NativeStart.main(Native Method)
08-15 13:46:45.488: ERROR/AndroidRuntime(516): Caused by: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'
08-15 13:46:45.488: ERROR/AndroidRuntime(516): at android.app.ListActivity.onContentChanged(ListActivity.java:236)
08-15 13:46:45.488: ERROR/AndroidRuntime(516): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:316)
08-15 13:46:45.488: ERROR/AndroidRuntime(516): at android.app.Activity.setContentView(Activity.java:1620)
08-15 13:46:45.488: ERROR/AndroidRuntime(516): at ua.donetsk.jeston.android.ListRegionsActivity.onCreate(ListRegionsActivity.java:15)
08-15 13:46:45.488: ERROR/AndroidRuntime(516): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1123)
08-15 13:46:45.488: ERROR/AndroidRuntime(516): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2364)
08-15 13:46:45.488: ERROR/AndroidRuntime(516): ... 11 more
UPD: the problem is solved. The reason was in incorrect mistake in opening avtivity - setContentView should be deleted.
Since you did not showed us the LogCat trace, I can do the guess.
Try this in the ListView click listener
MainActivity.this.startActivity(new Intent(MainActivity.this,ListRegionsActivity.class))
And dont forget to add the new activity in your manifest.
Check you're not importing android.R in your app instead of your.package.R

Categories

Resources