我不是一个设计师,但当我得到这个项目,我不能打开特别的一些屏幕,我认为他们是屏幕,我们只重用一些布局已经创建。不管怎么说谁能帮帮我吗?@override public void onBindViewHolder(@nonnull final ProductsAdapter.ViewHolder holder,final int position){String imageUrl=ProductsList.Get(position).GetImage();
holder.itemName.setText(ProductsList.get(position).getName());
Picasso.with(context).load(imageUrl).into(holder.itemImage);
holder.parentLayot.setOnClickListener(new View.OnClickListener() {
public String currentActivity;
@Override
public void onClick(View v) {
Activity activity = (Activity) v.getContext();
activity.runOnUiThread(bd);
String activityName = activity.getClass().getSimpleName();
// Toast.makeText(activity,ProductsList.get(position).getId(),Toast.LENGTH_SHORT).show();
if (activityName.equals("Product_View")){
// Toast.makeText(activity,"Click and pass",Toast.LENGTH_SHORT).show();
Intent intent = new Intent(activity, Second_Product_View.class);
intent.putExtra("item_name", ProductsList.get(position).getName());
intent.putExtra("item_id", ProductsList.get(position).getId());
intent.putExtra("item_category_name", ProductsList.get(position).getName());
intent.putExtra("item_category_id", ProductsList.get(position).getId());
activity.startActivity(intent);
} else if(activityName.equals("Second_Product_View")){
Intent intent = new Intent(activity, Third_Product_View.class);
intent.putExtra("item_category_name", activity.getIntent().getStringExtra("item_category_name"));
intent.putExtra("item_category_id", activity.getIntent().getStringExtra("item_category_id"));
intent.putExtra("item_subcategory_name", ProductsList.get(position).getName());
intent.putExtra("item_subcategory_id", ProductsList.get(position).getId());
intent.putExtra("item_name", ProductsList.get(position).getName());
intent.putExtra("item_id", ProductsList.get(position).getId());
activity.startActivity(intent);
} else if(activityName.equals("Third_Product_View")){
Intent intent = new Intent(activity, Fourth_Product_View.class);
intent.putExtra("item_category_name", activity.getIntent().getStringExtra("item_category_name"));
intent.putExtra("item_category_id", activity.getIntent().getStringExtra("item_category_id"));
intent.putExtra("item_subcategory_name", activity.getIntent().getStringExtra("item_subcategory_name"));
intent.putExtra("item_subcategory_id", activity.getIntent().getStringExtra("item_subcategory_id"));
intent.putExtra("item_section_name", ProductsList.get(position).getName());
intent.putExtra("item_section_id", ProductsList.get(position).getId());
intent.putExtra("item_name", ProductsList.get(position).getName());
intent.putExtra("item_id", ProductsList.get(position).getId());
activity.startActivity(intent);
} else if(activityName.equals("Fourth_Product_View")){
holder.downloadManager = (DownloadManager)activity.getSystemService(Context.DOWNLOAD_SERVICE);
String file = activity.getString(R.string.base_url) + "files/example-" + ProductsList.get(position).getId() + ".pdf";
Uri uri = Uri.parse(file);
DownloadManager.Request request = new DownloadManager.Request(uri);
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
Long reference = holder.downloadManager.enqueue(request);
} else if (activityName.equals("Formation_View")){
Intent intent = new Intent(activity, Second_Formation_View.class);
intent.putExtra("item_name", ProductsList.get(position).getName());
intent.putExtra("item_id", ProductsList.get(position).getId());
intent.putExtra("item_category_name", ProductsList.get(position).getName());
intent.putExtra("item_category_id", ProductsList.get(position).getId());
activity.startActivity(intent);
} else if(activityName.equals("Second_Formation_View")){
Intent intent = new Intent(activity, Third_Formation_View.class);
intent.putExtra("item_category_name", activity.getIntent().getStringExtra("item_category_name"));
intent.putExtra("item_category_id", activity.getIntent().getStringExtra("item_category_id"));
intent.putExtra("item_subcategory_name", ProductsList.get(position).getName());
intent.putExtra("item_subcategory_id", ProductsList.get(position).getId());
intent.putExtra("item_name", ProductsList.get(position).getName());
intent.putExtra("item_id", ProductsList.get(position).getId());
activity.startActivity(intent);
} else if(activityName.equals("Third_Formation_View")){
holder.downloadManager = (DownloadManager)activity.getSystemService(Context.DOWNLOAD_SERVICE);
String file = activity.getString(R.string.base_url) + "files/example-" + ProductsList.get(position).getId() + ".pdf";
Uri uri = Uri.parse(file);
DownloadManager.Request request = new DownloadManager.Request(uri);
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
Long reference = holder.downloadManager.enqueue(request);
} else if (activityName.equals("Tools_View")){
Intent intent = new Intent(activity, Second_Tools_View.class);
intent.putExtra("item_name", ProductsList.get(position).getName());
intent.putExtra("item_id", ProductsList.get(position).getId());
intent.putExtra("item_category_name", ProductsList.get(position).getName());
intent.putExtra("item_category_id", ProductsList.get(position).getId());
activity.startActivity(intent);
} else if(activityName.equals("Second_Tools_View")){
holder.downloadManager = (DownloadManager)activity.getSystemService(Context.DOWNLOAD_SERVICE);
String file = activity.getString(R.string.base_url) + "files/example-" + ProductsList.get(position).getId() + ".pdf";
Uri uri = Uri.parse(file);
DownloadManager.Request request = new DownloadManager.Request(uri);
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
Long reference = holder.downloadManager.enqueue(request);
}
}
});
}
logcat显示了这一点
java.lang.ClassCastException: android.view.ContextThemeWrapper cannot be cast to android.app.Activity
at android.view.View.performClick(View.java:6256)
at android.view.View$PerformClick.run(View.java:24701)
at android.os.Handler.handleCallback(Handler.java:789)
at android.os.Handler.dispatchMessage(Handler.java:98)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6541)
at java.lang.reflect.Method.invoke(Native Method)
at
Kotlin中的递归解法;
fun Context.getActivity(): Activity? {
return when (this) {
is Activity -> this
is ContextWrapper -> this.baseContext.getActivity()
else -> null
}
}
在使用view.getContext()
的情况下选中。
这句台词很可能就是罪魁祸首:
Activity activity = (Activity) v.getContext();
传递给onClick()
方法的视图V
与您为侦听器分配的视图相同,因此V
与Holder.ParentLayot
相同。我不知道holder.parentlayot
到底从何而来,但很有可能(在XML中)这个视图(或其父视图之一)具有android:theme
属性。
当视图具有android:theme
属性时,它不会直接使用其activity的上下文。相反,android框架将activity的上下文“包装”在ContextThemeWrapper
中,以便修改视图的主题。
要从这个包装器访问activity,您必须“打开”它。试试这样的方法:
private static Activity unwrap(Context context) {
while (!(context instanceof Activity) && context instanceof ContextWrapper) {
context = ((ContextWrapper) context).getBaseContext();
}
return (Activity) context;
}
然后,您可以在onclick()
中使用此方法,而不是直接强制转换上下文:
Activity activity = unwrap(v.getContext());
MainActivity.java 对不起,我的英语很差。
问题内容: 我有。我想使用获得最大结果。这是我的代码: 这是我的: 现在我得到了。怎么了? 问题答案: 您的错误可能在以下行中: 其中query.list()返回BigInteger列表而不是Long列表。尝试将其更改为。
我有一个用java实现的Web服务项目,它还包含jsp页面。我在我的机器上的jetty 8.1.5上部署它,它可以正常工作。但是当我使用jetty 8.1.3在windows server 2003上部署时,它会出现此异常: 这是完整的跟踪: 知道这个异常是什么吗?以及如何修复它?
在我的应用程序中,我为gcm ccs(xmpp)运行这些代码,代码显示以下错误执行时出错,这是代码:
我正试图通过登录从报头中发送的API密钥对一个用户进行身份验证,而没有任何用户详细信息。然后,我会得到一个转换异常,因为我试图将主体转换为字符串。
我正在做一个java项目,我遇到了这个问题,不知道如何修复它。 } 当我尝试运行该程序时,它给出了错误: 线程“main”java.lang.ClassCastException中出现异常:无法将Stock强制转换为java.lang.Comparable 有人知道怎么了吗?