错误androidx.appcompat.widget.AppCompatImageView can't use method with RemoteViews: setImageResource

版权声明:本文为博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/wang29169/article/details/83043548

学习使用RemoteViews时,给ImageView设置图片时报错:

     Caused by: android.widget.RemoteViews$ActionException: android.widget.RemoteViews$ActionException: view: androidx.appcompat.widget.AppCompatImageView can't use method with RemoteViews: setImageResource(int)

        at android.widget.RemoteViews$ReflectionAction.apply(RemoteViews.java:1459)

        at android.widget.RemoteViews.performApply(RemoteViews.java:3563)

        at android.widget.RemoteViews.reapply(RemoteViews.java:3517)

        at android.widget.RemoteViews.reapply(RemoteViews.java:3500)

        。。。。。。

Activity.access$updateUI(ShowNotificationWithCustomRemoteViewsActivity.kt:19)

        at com.wx.study.chapter5.activity.customremoteviews.ShowNotificationWithCustomRemoteViewsActivity$mRemoteViewsReceiver$1.onReceive(ShowNotificationWithCustomRemoteViewsActivity.kt:49)

        at android.app.LoadedApk$ReceiverDispatcher$Args.lambda$getRunnable$0(LoadedApk.java:1391)

        at android.app.-$$Lambda$LoadedApk$ReceiverDispatcher$Args$_BumDX2UKsnxLVrE6UJsJZkotuA.run(Unknown Source:2) 

        at android.os.Handler.handleCallback(Handler.java:873) 

        at android.os.Handler.dispatchMessage(Handler.java:99) 

        at android.os.Looper.loop(Looper.java:193) 

        at android.app.ActivityThread.main(ActivityThread.java:6669) 

        at java.lang.reflect.Method.invoke(Native Method) 

        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493) 

        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858) 

     Caused by: android.widget.RemoteViews$ActionException: view: androidx.appcompat.widget.AppCompatImageView can't use method with RemoteViews: setImageResource(int)

        at android.widget.RemoteViews.getMethod(RemoteViews.java:1004)

        at android.widget.RemoteViews.access$400(RemoteViews.java:121)

        at android.widget.RemoteViews$ReflectionAction.apply(RemoteViews.java:1457)

        at android.widget.RemoteViews.performApply(RemoteViews.java:3563) 

        at android.widget.RemoteViews.reapply(RemoteViews.java:3517) 

        at android.widget.RemoteViews.reapply(RemoteViews.java:3500) 

        at com.wx.study.chapter5.activity.customremoteviews.ShowNotificationWithCustomRemoteViewsActivity.updateUI(ShowNotificationWithCustomRemoteViewsActivity.kt:61) 

        at com.wx.study.chapter5.activity.customremoteviews.ShowNotificationWithCustomRemoteViewsActivity.access$updateUI(ShowNotificationWithCustomRemoteViewsActivity.kt:19) 

        at com.wx.study.chapter5.activity.customremoteviews.ShowNotificationWithCustomRemoteViewsActivity$mRemoteViewsReceiver$1.onReceive(ShowNotificationWithCustomRemoteViewsActivity.kt:49) 

        at android.app.LoadedApk$ReceiverDispatcher$Args.lambda$getRunnable$0(LoadedApk.java:1391) 

        at android.app.-$$Lambda$LoadedApk$ReceiverDispatcher$Args$_BumDX2UKsnxLVrE6UJsJZkotuA.run(Unknown Source:2) 

        at android.os.Handler.handleCallback(Handler.java:873) 

        at android.os.Handler.dispatchMessage(Handler.java:99) 

        at android.os.Looper.loop(Looper.java:193) 

        at android.app.ActivityThread.main(ActivityThread.java:6669) 

        at java.lang.reflect.Method.invoke(Native Method) 

        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493) 

        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858) 

 

跟踪RemoteViews源码,从android.widget.RemoteViews#setImageViewResource()开始一路跟踪到报错的位置,在android.widget.RemoteViews#getMethod方法中有这样一段代码

if (!method.isAnnotationPresent(RemotableViewMethod.class)) {

    throw new ActionException("view: " + klass.getName()

            + " can't use method with RemoteViews: "

            + methodName + getParameters(paramType));

}

这段代码的意思是没有RemotableViewMethod注解的View是不能被RemoteViews设置属性值的

查看androidx.appcompat.widget.AppCompatImageView类中对应的setImageViewResource()方法果然是没有RemotableViewMethod注解,虽然它的父类android.widget.ImageView对应的方法是有注解的,但是由于RemotableViewMethod注解在声明时没有设置可以继承,所以在子类中是没有注解的

 

所以将AppCompatImageView改为ImageView即可,需要注意的是当Activity使用的是AppCompatActivity时也要改为Activity。在AppCompatActivity中布局中使用的ImageView和TextView等也会在加载布局时被转换成对应的兼容类,兼容类都是这些类的子类,有些方法被继承后没有加上RemotableViewMethod注解,不能被RemoteViews使用

 

 

 

展开阅读全文

Sqoop错误GENERIC_JDBC_CONNECTOR_0016:Can't fetch schema -

03-04

这几天使用Sqoop 1.99.7 的Java API编一个程序,将MySQL数据库recommend中的rate表信息导入hdfs中。但是一直提示不能fetch数据库schema,看错误信息,貌似将传入的schema名称字符串连同双引号一起作为了schema名称。请大家看看这个问题怎么解?忧郁了好几天了。。。。希望大家能帮忙找出问题所在,感谢!!!!rnprivate void mysqlToHDFS() rnrn String url = "http://192.168.2.100:12000/sqoop/";rn SqoopClient client = new SqoopClient(url);rnrn MLink fromLink = client.createLink("generic-jdbc-connector");rn fromLink.setName("jdbc connector");rn fromLink.setCreationUser("Potala");rn MLinkConfig fromLinkConfig = fromLink.getConnectorLinkConfig();rn fromLinkConfig.getStringInput("linkConfig.connectionString")rn .setValue("jdbc:mysql://192.168.2.128:3306/recommend");rn fromLinkConfig.getStringInput("linkConfig.jdbcDriver").setValue("com.mysql.jdbc.Driver");rn fromLinkConfig.getStringInput("linkConfig.username").setValue("root");rn fromLinkConfig.getStringInput("linkConfig.password").setValue("1234");rn client.saveLink(fromLink);rnrn MLink toLink = client.createLink("hdfs-connector");rn toLink.setName("hdfs connector");rn toLink.setCreationUser("Potala");rn MLinkConfig toLinkConfig = toLink.getConnectorLinkConfig();rn toLinkConfig.getStringInput("linkConfig.uri").setValue("hdfs://192.168.2.100:9000");rn client.saveLink(toLink);rnrn MJob job = client.createJob("jdbc connector", "hdfs connector");rn job.setName("MySQL to HDFS job");rn job.setCreationUser("Potala");rnrn MFromConfig fromJobConfig = job.getFromJobConfig();rn [color=#FF0000]fromJobConfig.getStringInput("fromJobConfig.tableName").setValue("recommend");rn fromJobConfig.getStringInput("fromJobConfig.tableName").setValue("rate");rn fromJobConfig.getStringInput("fromJobConfig.partitionColumn").setValue("rateId");[/color]rnrn MToConfig toJobConfig = job.getToJobConfig();rn toJobConfig.getStringInput("toJobConfig.outputDirectory").setValue("/data/rate");rnrn MDriverConfig driverConfig = job.getDriverConfig();rn driverConfig.getIntegerInput("throttlingConfig.numExtractors").setValue(3);rnrn client.saveJob(job);rnrn client.startJob("MySQL to HDFS job");rn client.deleteJob(job.getName());rn client.deleteLink(fromLink.getName());rn client.deleteLink(toLink.getName());rn rnrn错误信息如下:rnException in thread "Thread-7" org.apache.sqoop.common.SqoopException: CLIENT_0001:Server has returned exceptionrn at org.apache.sqoop.client.request.ResourceRequest.doHttpRequest(ResourceRequest.java:137)rn at org.apache.sqoop.client.request.ResourceRequest.put(ResourceRequest.java:187)rn at org.apache.sqoop.client.request.JobResourceRequest.start(JobResourceRequest.java:113)rn at org.apache.sqoop.client.request.SqoopResourceRequests.startJob(SqoopResourceRequests.java:170)rn at org.apache.sqoop.client.SqoopClient.startJob(SqoopClient.java:477)rn at com.recommender.util.RecommendThread.mysqlToHDFS(RecommendThread.java:69)rn at com.recommender.util.RecommendThread.run(RecommendThread.java:19)rnCaused by: org.apache.sqoop.common.SqoopException: [color=#FF0000]GENERIC_JDBC_CONNECTOR_0016:Can't fetch schema -[/color] rn at org.apache.sqoop.connector.jdbc.GenericJdbcFromInitializer.initialize(GenericJdbcFromInitializer.java:64)rn at org.apache.sqoop.connector.jdbc.GenericJdbcFromInitializer.initialize(GenericJdbcFromInitializer.java:47)rn at org.apache.sqoop.driver.JobManager$1.call(JobManager.java:520)rn at org.apache.sqoop.driver.JobManager$1.call(JobManager.java:517)rn at org.apache.sqoop.utils.ClassUtils.executeWithClassLoader(ClassUtils.java:281)rn at org.apache.sqoop.driver.JobManager.initializeConnector(JobManager.java:516)rn at org.apache.sqoop.driver.JobManager.createJobRequest(JobManager.java:423)rn at org.apache.sqoop.driver.JobManager.start(JobManager.java:317)rn at org.apache.sqoop.handler.JobRequestHandler.startJob(JobRequestHandler.java:353)rn at org.apache.sqoop.handler.JobRequestHandler.handleEvent(JobRequestHandler.java:114)rn at org.apache.sqoop.server.v1.JobServlet.handlePutRequest(JobServlet.java:84)rn at org.apache.sqoop.server.SqoopProtocolServlet.doPut(SqoopProtocolServlet.java:81)rn at javax.servlet.http.HttpServlet.service(HttpServlet.java:710)rn at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)rn at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:808)rn at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1669)rn at org.apache.hadoop.security.authentication.server.AuthenticationFilter.doFilter(AuthenticationFilter.java:574)rn at org.apache.hadoop.security.token.delegation.web.DelegationTokenAuthenticationFilter.doFilter(DelegationTokenAuthenticationFilter.java:269)rn at org.apache.hadoop.security.authentication.server.AuthenticationFilter.doFilter(AuthenticationFilter.java:544)rn at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1652)rn at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:585)rn at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1127)rn at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:515)rn at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1061)rn at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)rn at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:97)rn at org.eclipse.jetty.server.Server.handle(Server.java:499)rn at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:310)rn at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:257)rn at org.eclipse.jetty.io.AbstractConnection$2.run(AbstractConnection.java:540)rn at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)rn at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)rn at java.lang.Thread.run(Thread.java:745)rnCaused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near[color=#FF0000] '"recommend"."rate"'[/color] at line 1rn at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)rn at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)rn at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)rn at java.lang.reflect.Constructor.newInstance(Constructor.java:422)rn at com.mysql.jdbc.Util.handleNewInstance(Util.java:409)rn at com.mysql.jdbc.Util.getInstance(Util.java:384)rn at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1054)rn at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3566)rn at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3498)rn at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1959)rn at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2113)rn at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2568)rn at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2113)rn at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:2275)rn at org.apache.sqoop.connector.jdbc.GenericJdbcFromInitializer.configurePartitionProperties(GenericJdbcFromInitializer.java:257)rn at org.apache.sqoop.connector.jdbc.GenericJdbcFromInitializer.initialize(GenericJdbcFromInitializer.java:61)rn ... 32 more 论坛

没有更多推荐了,返回首页