I was trying to run a sample code While launching the application in the android 1.5 emulator , I got these errors.... Any one have some hint..?
ERROR from LogCat:<
For me, my package string in AndroidManifest.xml
was incorrect (copied from a tutorial).
Make sure the package string in this file is the same as where your main activity is, e.g.
package="com.example.app"
An easy way to do this is to open the AndroidManifest.xml file in the "Manifest" tab, and type it in the text box next to Package, or use the Browse button.
Also, the package string for my activity was wrong, e.g.
<activity android:name="com.example.app.MainActivity" android:label="@string/app_name">
I (stupidly) got the same error weeks later when I renamed my package name. If you do this, make sure you update the AndroidManifest.xml
file too.
Ok, I am fairly experienced on the iPhone but new to android. I got this issue when I had:
Button infoButton = (Button)findViewById(R.id.InfoButton);
this line of code above:
@Override
public void onCreate (Bundle savedInstanceState) {
}
May be I am sleep deprived :P
If you have Android Studio 2.3.3 and Android Studio 3.0.0 installed, then switching between the two programs for development will cause this error. This is because there exist situations where classes supported in one program is not supported by the other and vice versa. It is important to maintain consistency in which version of Android Studio is being used to develop a project.
This error can also be the ultimate sign of a dumb mistake (like when I - I mean, cough, like when a friend of mine who showed me their code once) where they try to execute code outside of a method like trying to do this:
SQLiteDatabase db = openOrCreateDatabase("DB", MODE_PRIVATE, null); //trying to perform function where you can only set up objects, primitives, etc
@Override
public void onCreate(Bundle savedInstanceState) {
....
}
rather than this:
SQLiteDatabase db;
@Override
public void onCreate(Bundle savedInstanceState) {
db = openOrCreateDatabase("DB", MODE_PRIVATE, null);
....
}
As suggested by djjeck
in comment in this answer I missed to put public
modifier for my class.
It should be
public class MyActivity extends AppCompatActivity {
It may help some like me.
This can happen if your activity class is inside a default package. I fixed it by moving the activity class to a new package. and changing the manifest.xml
before
activity android:name=".MainActivity"
after
activity android:name="new_package.MainActivity"