I've got the following Button declared in my main.xml
<Button android:name="#+id/clickedStartService"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:onClick="clickedStartService"
android:text="Start"
/>
<Button android:name="#+id/clickedStopService"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:onClick="clickedStopService"
android:text="Stop"
/>
And I have the following methods in the activity..
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
public void clickedStartService(View v)
{
startService(new Intent(this, LocalService.class));
}
public void clickedStopService(View v)
{
stopService(new Intent(this, LocalService.class));
}
I'm getting the following error when I click the button. I have tried rebuilding the project in my IDE and have also restarted the emulator, but same error re-appears. I've followed the documentation on the Android developers site, and I've had this working in a separate project, I just can't get it to work here..
ERROR/AndroidRuntime(335): FATAL EXCEPTION: main
java.lang.IllegalStateException: Could not find a method clickedStartService(View) in the activity class com.jameselsey.observerpattern.MyApp for onClick handler on view class android.widget.Button
at android.view.View$1.onClick(View.java:2059)
at android.view.View.performClick(View.java:2408)
at android.view.View$PerformClick.run(View.java:8816)
at android.os.Handler.handleCallback(Handler.java:587)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:4627)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:521)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NoSuchMethodException
at java.lang.Class.getDeclaredMethods(Native Method)
at java.lang.ClassCache.getDeclaredPublicMethods(ClassCache.java:166)
at java.lang.ClassCache.getDeclaredMethods(ClassCache.java:179)
at java.lang.ClassCache.findAllMethods(ClassCache.java:249)
at java.lang.ClassCache.getFullListOfMethods(ClassCache.java:223)
at java.lang.ClassCache.getAllPublicMethods(ClassCache.java:204)
at java.lang.Class.getMethod(Class.java:984)
at android.view.View$1.onClick(View.java:2052)
... 11 more
XML click listeners were added in Android 1.6. Check your AndroidManifest to verify that your min SDK version isn't set to cupcake (1.5, or API level 3) -
If you're using Eclipse with the ADT plugin, also check project properties > Android and check the build target, make sure it's Donut or higher.
You need to do:
import android.view.View
instead of:
import view.View
Related
I am using Brightcove sdk for android.
I added the sdk in libs folder and added it in the dependencies also.
and the code that i am using is
public class MainActivity extends BrightcovePlayer {
//private final String TAG = this.getClass().getSimpleName();
private EventEmitter eventEmitter;
// BrightcoveVideoView brightcoveVideoView;
//private GoogleIMAComponent googleIMAComponent;
private String adRulesURL = "http://pubads.g.doubleclick.net/gampad/ads?sz=640x480&iu=%2F15018773%2Feverything2&ciu_szs=300x250%2C468x60%2C728x90&impl=s&gdfp_req=1&env=vp&output=xml_vast2&unviewed_position_start=1&url=dummy&correlator=[timestamp]&cmsid=133&vid=10XWSh7W4so&ad_rule=1";
#Override
protected void onCreate(Bundle savedInstanceState) {
// When extending the BrightcovePlayer, we must assign the BrightcoveVideoView before
// entering the superclass. This allows for some stock video player lifecycle
// management.
setContentView(R.layout.activity_main);
BrightcoveVideoView brightcoveVideoView = (BrightcoveVideoView) findViewById(R.id.brightcove_video_view);
super.onCreate(savedInstanceState);
brightcoveVideoView.add(Video.createVideo("http://solutions.brightcove.com/bcls/assets/videos/Bird_Titmouse.mp4", DeliveryType.MP4));
brightcoveVideoView.start();
and the layout file
<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"
android:orientation="vertical"
tools:context=".MainActivity">
<com.brightcove.player.view.BrightcoveVideoView
android:id="#+id/brightcove_video_view"
android:layout_width="match_parent"
android:layout_height="280dp"
android:layout_gravity="center_horizontal|center_vertical" />
and the error i got is
6366-6366/E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.NoClassDefFoundError: com.brightcove.player.R$layout
at com.brightcove.player.controller.BrightcoveClosedCaptioningController.makeCaptionsDialog(BrightcoveClosedCaptioningController.java:114)
at com.brightcove.player.controller.BrightcoveClosedCaptioningController.<init>(BrightcoveClosedCaptioningController.java:102)
at com.brightcove.player.view.BaseVideoView.setEventEmitter(BaseVideoView.java:298)
at com.brightcove.player.view.BrightcoveVideoView.setEventEmitter(BrightcoveVideoView.java:149)
at com.brightcove.player.view.BaseVideoView.onFinishInflate(BaseVideoView.java:255)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:747)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:742)
at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:274)
at android.app.Activity.setContentView(Activity.java:1835)
at com.testproject.myapplication.MainActivity.onCreate(MainActivity.java:50)
at android.app.Activity.performCreate(Activity.java:4470)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1053)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1934)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1995)
at android.app.ActivityThread.access$600(ActivityThread.java:128)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1161)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4517)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:993)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:760)
at dalvik.system.NativeStart.main(Native Method)
What is the error. I couldn't understand.
We recently added support for customizing closed captioning styles on pre-Kitkat and the dialog requires some resources, like the layout. These resources are included in the .aar file, which should be used when compiling with gradle and Android Studio. Android Studio has reached 1.0, so we recommend using that or gradle on the command line for development with the Brightcove SDK. For legacy Eclipse development, we ship legacy jars, but now that resources are required, you'll also have to use apklib files. The SDK apklib file was missing from the 4.3.0 release, but it will be included in the next release. If you can't get off Eclipse, to get unblocked, you should go back to using the 4.2.7 release until 4.3.1 comes out.
to complement this question:
Note: Support for Android versions 2.3.3 and 4.0 is now deprecated.
Learn more about why Brightcove is removing support for these versions
as of January 1, 2016 in this announcement.
http://docs.brightcove.com/en/perform/mobile-sdks/brightcove-player-sdk-for-android/index.html
I have a main activity and I call a second "demo from android studio" activity when I click on a button of the first activity like this :
public void createNetworkButtonClicked (View view) {
Intent intent = new Intent(this, WiFiDirectActivity.class); // that works
startActivity(intent); // that does not work
}
I get this error :
E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.IllegalStateException: Could not execute method of the activity
at android.view.View$1.onClick(View.java:3698)
at android.view.View.performClick(View.java:4222)
at android.view.View$PerformClick.run(View.java:17337)
at android.os.Handler.handleCallback(Handler.java:615)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4895)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:994)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:761)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.reflect.InvocationTargetException
Thanks for your help
There can be possibly two reasons for it.
1) Check your method name in onClick attribute of XML file. It should match with the name of the method in java.
2) Create an activity instead of creating individual XML file and Java file for the second class. You can create Activity by right clicking on app folder-->new-->activity-->empty activity.
Im newbie at developing Android apps but even the simpliest app always crashes when I try to add click listener I tried to google my problem but with no success. I also tried to change API to different versions at new project screen. Im able to run Hello World app but when I try to add listener to my app then Im no longer able to run it. Here is my error log.
03-02 21:13:49.153 19700-19700/com.example.app E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.app/com.example.app.MainActivity}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2205)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2240)
at android.app.ActivityThread.access$600(ActivityThread.java:139)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1262)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:156)
at android.app.ActivityThread.main(ActivityThread.java:4977)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at com.example.app.MainActivity.onCreate(MainActivity.java:32)
at android.app.Activity.performCreate(Activity.java:4538)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1071)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2161)
at android.app.ActivityThread.access$600(ActivityThread.java:139)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2240)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1262)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:156)
at android.app.ActivityThread.main(ActivityThread.java:4977)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
at dalvik.system.NativeStart.main(Native Method)
03-02 21:13:49.163 1598-1922/? E/EmbeddedLogger﹕ App crashed! Process: com.example.app
03-02 21:13:49.163 1598-1922/? E/EmbeddedLogger﹕ App crashed! Package: com.example.app v1 (1.0)
03-02 21:13:49.163 1598-1922/? E/EmbeddedLogger﹕ Application Label: My Application 7
03-02 21:13:51.566 19729-19729/? E/ActivityThread﹕ Failed to find provider info for com.google.android.gallery3d.GooglePhotoProvider
03-02 21:13:56.871 19959-19959/? E/ActivityThread﹕ Failed to find provider info for com.google.android.gallery3d.GooglePhotoProvider
And here only piece of code where I changed something (I added button in design)
public class MainActivity extends ActionBarActivity {
Button btn = null;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if (savedInstanceState == null) {
getSupportFragmentManager().beginTransaction()
.add(R.id.container, new PlaceholderFragment())
.commit();
}
btn = (Button)findViewById(R.id.button);
btn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
btn.setText("Hi");
}
});
}
According to your comment on the last answer, you do not import any R file.
You need to import it this way:
import com.<package_name>.<app_name>.R;
That will import the ids generated file available into your Java code and the Button id button will be visible.
Look at the line 32 of the file MainActivity.java. Sounds like you're trying to call a method on a null object.
For example, are you sure your layout activity_main.xml contains a Button with an id R.id.button?
The problem is either that R.id.button doesn't exist in your activity_main.xml layout, or that there is something null in this code:
if (savedInstanceState == null) {
getSupportFragmentManager().beginTransaction()
.add(R.id.container, new PlaceholderFragment())
.commit();
}
Try them both out separately and figure out which one isn't working. Go from there.
By the way, the NullPointerException occurs on line 32.
i'm trying to initialize my textview using a static string whenever i launch this activity but emulator always force closes the activity.. can anyone help me out?
Here's the code:
// ServiceAct.java
public class ServiceAct extends Activity
{
static String[] phoneno = {"No Number", "No Number", "No Number"};
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// to set the contacts value in status module
TextView v1 = (TextView) findViewById(R.id.stat_con1);
v1.setText(phoneno[0]);
//remaining code of the activity
....
}
}
here's the logcat
FATAL EXCEPTION: main java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.service/com.example.service.ServiceAct}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
at android.app.ActivityThread.access$1500(ActivityThread.java:117)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:3683)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at com.example.service.ServiceAct.onCreate(ServiceAct.java:31)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
here's the layout code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:weightSum="1" android:layout_height="fill_parent" android:orientation="horizontal" android:layout_width="fill_parent" android:background="#color/background" >
<RelativeLayout android:layout_height="match_parent" android:layout_width="match_parent" android:layout_gravity="center" android:id="#+id/relativeLayout2">
<TextView android:text="No Number" android:id="#+id/stat_con1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceLarge" />
</RelativeLayout>
</LinearLayout>
Have you tried to clean your project? This looks just like such kind of error (because everything else seems perfectly fine). If you develop in Eclipse go to project -> clean. Select all projects. Afterwords you might need to also rebuild. Also if this does nto help, try restarting your IDE.
From the code you posted, I can see two possible errors:
TextView v1 is null, which means the layout file doesn't have any TextView with the id R.id.stat_con1
the view with the id R.id.stat_con1 is not a TextView and you fail when casting to a TextView
Update:
Caused by: java.lang.NullPointerException
at com.example.service.ServiceAct.onCreate(ServiceAct.java:31)
Check line 31... something in that line is null.
I do have lots of plain old activity-based apps in the Play Store. Since two days I try to do my first steps with Fragments. I still don't get it. I've read mostly all docs and blogs and guides about Fragments but my stupid simple test app refuses to start with an ClassNotFoundException on MyActivity.
So here's what I did so far:
The starting FragmentActivity called MyActivity:
public class MyActivity extends FragmentActivity {
#Override
public void onCreate(Bundle bundle) {
super.onCreate(bundle);
setContentView(R.layout.myactivity);
}
}
Here's the layout/myactivity.xml:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<fragment
class="com.test.app.Table1List"
android:id="#+id/table1list"
android:layout_height="match_parent"
android:layout_width="match_parent" />
</LinearLayout>
This is the ListFragment with its XML file:
public class Table1List extends ListFragment {
#Override
public View onCreateView(LayoutInflater layoutInflater, ViewGroup viewGroup, Bundle bundle) {
if (viewGroup == null) {
return null;
}
return layoutInflater.inflate(R.layout.table1list, viewGroup);
}
}
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<ListView
android:drawSelectorOnTop="false"
android:fastScrollEnabled="true"
android:id="#id/android:list"
android:layout_height="fill_parent"
android:layout_width="fill_parent" />
<TextView
style="#style/TextViewMedium"
android:id="#id/android:empty"
android:text="#string/txt_noresult" />
</LinearLayout>
Call me stupid but I always do get an ActivityNotFoundException during start of the FragmentActivity called MyActivity.
Any help is highly appreciated.
EDIT:
I took the latest v4 Compatibility Package from several days ago. I issued clean projects nearly every 10 minutes - no go.
Here's the Manifest:
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
android:versionCode="1"
android:versionName="1.0"
package="com.test.app" >
<uses-sdk
android:minSdkVersion="7"
android:targetSdkVersion="11" />
<application
android:hardwareAccelerated="true"
android:icon="#drawable/ic_launcher"
android:label="#string/txt_appname" >
<activity
android:label="#string/txt_appname"
android:name="MyActivity" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
EDIT 2: Here's the LogCat:
Unable to resolve superclass of Lcom/test/app/MyActivity; (25)
Link of class 'Lcom/test/app/MyActivity;' failed
Shutting down VM
threadid=3: thread exiting with uncaught exception (group=0x4001b188)
Uncaught handler: thread main exiting due to uncaught exception
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.test.app/com.test.app.MyActivity}: java.lang.ClassNotFoundException: com.test.app.MyActivity in loader dalvik.system.PathClassLoader#44bfda38
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2417)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2512)
at android.app.ActivityThread.access$2200(ActivityThread.java:119)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1863)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:4363)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:521)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassNotFoundException: com.test.app.MyActivity in loader dalvik.system.PathClassLoader#44bfda38
at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:243)
at java.lang.ClassLoader.loadClass(ClassLoader.java:573)
at java.lang.ClassLoader.loadClass(ClassLoader.java:532)
at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2409)
... 11 more
EDIT 3: I did re-install the support package, created a new project with Compatability Package v4, stripped down everything to just the MyActivity and one fragment --> same error. I even tested with the previous Support v4 package (Release 6).
These are my first steps with Fragments after nearly three years with Android development (lots of apps in the market). Seems that this whole thing is broken.
This is the project tree in eclipse - any help still highly required.
I don't know if this will fix your problem but looking at your screenshot, everything looks correct to me except the Referenced Libraries item. That shouldn't be there any more because the latest ADT version 17 automatically detects all jars in the libs folder. You can get rid of the Referenced Libraries item by removing the explicit reference to the android support jar from your build path.
I had a very similar problem and was completely stumped for a while until I read this blog post which has a lot of information about this issue so it might be worth a read even if removing the Referenced Libraries doesn't work.
Something seems to be not working as expected.
Copy the compatibility jar to a folder libs and then recompile and repackage