我收到以下错误"类型不匹配:无法从String转换为Uri"从以下一行
list_item_bac = i.getStringExtra("list_item_bac");
已经识别出list_item_bac有一个Uri,因为它通过JSON数据填充图像,所以我不想将它从Uri更改为String,因为我没有返回文本,而是我将转换为imageview的图像。
以下是整个代码:
public class CasualEventsSingleItemActivity extends Activity {
// Declare Variables
String list_item_name;
String list_item_description;
Uri list_item_bac;
String list_item_price;
String list_item_location;
String single_list_item_description;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_events_single_item);
ImageLoader mImageLoader = new ImageLoader(Volley.newRequestQueue(this),
new ImageLoader.ImageCache() {
private final LruCache<String, Bitmap>
cache = new LruCache<String, Bitmap>(20);
@Override
public Bitmap getBitmap(String url) {
return cache.get(url);
}
@Override
public void putBitmap(String url, Bitmap bitmap) {
cache.put(url, bitmap);
}
});
Intent i = getIntent();
list_item_name = i.getStringExtra("list_item_name");
list_item_location = i.getStringExtra("list_item_location");
list_item_bac = i.getStringExtra("list_item_bac");
single_list_item_description = i.getStringExtra("single_list_item_description");
TextView txtname = (TextView) findViewById(R.id.name);
TextView txtlocation = (TextView) findViewById(R.id.location);
TextView txtsdescription = (TextView) findViewById(R.id.sdescription);
NetworkImageView hsvimage1 = (NetworkImageView) findViewById(R.id.hsvimage1);
NetworkImageView hsvimage2 = (NetworkImageView) findViewById(R.id.hsvimage2);
NetworkImageView hsvimage3 = (NetworkImageView) findViewById(R.id.hsvimage3);
// Get image URLs from your previous network request...
// I could not determine where this is stored from code in your question.
Uri url1 = list_item_bac; // e.g. http://example.com/images/image1.png
Uri url2 = list_item_bac;
Uri url3 = list_item_bac;
// Set the URL of the image that should be loaded into this view, and
// specify the ImageLoader that will be used to make the request.
hsvimage1.setImageUrl(url1, mImageLoader);
hsvimage2.setImageUrl(url2, mImageLoader);
hsvimage3.setImageUrl(url3, mImageLoader);
// Set results to the TextViews
txtname.setText(list_item_name);
txtlocation.setText(list_item_location);
txtsdescription.setText(single_list_item_description);
Button mConfirm2 = (Button)findViewById(R.id.bConfirm2);
mConfirm2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
ParseUser currentUser = ParseUser.getCurrentUser();
// Create the class and the columns
currentUser.saveInBackground();
currentUser.put("ActivityName", list_item_name);
currentUser.saveInBackground(new SaveCallback() {
@Override
public void done(ParseException e) {
setProgressBarIndeterminateVisibility(false);
if (e == null) {
// Success!
Intent intent = new Intent(CasualEventsSingleItemActivity.this, usermatch.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity(intent);
}
else {
AlertDialog.Builder builder = new AlertDialog.Builder(CasualEventsSingleItemActivity.this);
builder.setMessage(e.getMessage())
.setTitle(R.string.signup_error_title)
.setPositiveButton(android.R.string.ok, null);
AlertDialog dialog = builder.create();
dialog.show();
}
}
});
//CasualEventsSingleItemActivity.this.startActivity(new Intent(CasualEventsSingleItemActivity.this, MatchingActivity.class));
}
});
}
}
非常感谢任何帮助。 提前谢谢。
更新
08-29 13:15:32.355: E/AndroidRuntime(1247): FATAL EXCEPTION: main
08-29 13:15:32.355: E/AndroidRuntime(1247): Process: com.dooba.beta, PID: 1247
08-29 13:15:32.355: E/AndroidRuntime(1247): java.lang.NullPointerException
08-29 13:15:32.355: E/AndroidRuntime(1247): at com.android.volley.Request.<init>(Request.java:130)
08-29 13:15:32.355: E/AndroidRuntime(1247): at com.android.volley.toolbox.ImageRequest.<init>(ImageRequest.java:71)
08-29 13:15:32.355: E/AndroidRuntime(1247): at com.android.volley.toolbox.ImageLoader.get(ImageLoader.java:220)
08-29 13:15:32.355: E/AndroidRuntime(1247): at com.android.volley.toolbox.ImageLoader.get(ImageLoader.java:171)
08-29 13:15:32.355: E/AndroidRuntime(1247): at com.android.volley.toolbox.NetworkImageView.loadImageIfNecessary(NetworkImageView.java:140)
08-29 13:15:32.355: E/AndroidRuntime(1247): at com.android.volley.toolbox.NetworkImageView.onLayout(NetworkImageView.java:180)
08-29 13:15:32.355: E/AndroidRuntime(1247): at android.view.View.layout(View.java:14817)
08-29 13:15:32.355: E/AndroidRuntime(1247): at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1671)
08-29 13:15:32.355: E/AndroidRuntime(1247): at android.widget.LinearLayout.layoutHorizontal(LinearLayout.java:1660)
08-29 13:15:32.355: E/AndroidRuntime(1247): at android.widget.LinearLayout.onLayout(LinearLayout.java:1436)
08-29 13:15:32.355: E/AndroidRuntime(1247): at android.view.View.layout(View.java:14817)
08-29 13:15:32.355: E/AndroidRuntime(1247): at android.view.ViewGroup.layout(ViewGroup.java:4631)
08-29 13:15:32.355: E/AndroidRuntime(1247): at android.widget.FrameLayout.layoutChildren(FrameLayout.java:453)
08-29 13:15:32.355: E/AndroidRuntime(1247): at android.widget.HorizontalScrollView.onLayout(HorizontalScrollView.java:1474)
08-29 13:15:32.355: E/AndroidRuntime(1247): at android.view.View.layout(View.java:14817)
08-29 13:15:32.355: E/AndroidRuntime(1247): at android.view.ViewGroup.layout(ViewGroup.java:4631)
08-29 13:15:32.355: E/AndroidRuntime(1247): at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1055)
08-29 13:15:32.355: E/AndroidRuntime(1247): at android.view.View.layout(View.java:14817)
08-29 13:15:32.355: E/AndroidRuntime(1247): at android.view.ViewGroup.layout(ViewGroup.java:4631)
08-29 13:15:32.355: E/AndroidRuntime(1247): at android.widget.FrameLayout.layoutChildren(FrameLayout.java:453)
08-29 13:15:32.355: E/AndroidRuntime(1247): at android.widget.FrameLayout.onLayout(FrameLayout.java:388)
08-29 13:15:32.355: E/AndroidRuntime(1247): at android.view.View.layout(View.java:14817)
08-29 13:15:32.355: E/AndroidRuntime(1247): at android.view.ViewGroup.layout(ViewGroup.java:4631)
08-29 13:15:32.355: E/AndroidRuntime(1247): at com.android.internal.widget.ActionBarOverlayLayout.onLayout(ActionBarOverlayLayout.java:374)
08-29 13:15:32.355: E/AndroidRuntime(1247): at android.view.View.layout(View.java:14817)
08-29 13:15:32.355: E/AndroidRuntime(1247): at android.view.ViewGroup.layout(ViewGroup.java:4631)
08-29 13:15:32.355: E/AndroidRuntime(1247): at android.widget.FrameLayout.layoutChildren(FrameLayout.java:453)
08-29 13:15:32.355: E/AndroidRuntime(1247): at android.widget.FrameLayout.onLayout(FrameLayout.java:388)
08-29 13:15:32.355: E/AndroidRuntime(1247): at android.view.View.layout(View.java:14817)
08-29 13:15:32.355: E/AndroidRuntime(1247): at android.view.ViewGroup.layout(ViewGroup.java:4631)
08-29 13:15:32.355: E/AndroidRuntime(1247): at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:1987)
08-29 13:15:32.355: E/AndroidRuntime(1247): at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1744)
08-29 13:15:32.355: E/AndroidRuntime(1247): at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1000)
08-29 13:15:32.355: E/AndroidRuntime(1247): at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5670)
08-29 13:15:32.355: E/AndroidRuntime(1247): at android.view.Choreographer$CallbackRecord.run(Choreographer.java:761)
08-29 13:15:32.355: E/AndroidRuntime(1247): at android.view.Choreographer.doCallbacks(Choreographer.java:574)
08-29 13:15:32.355: E/AndroidRuntime(1247): at android.view.Choreographer.doFrame(Choreographer.java:544)
08-29 13:15:32.355: E/AndroidRuntime(1247): at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:747)
08-29 13:15:32.355: E/AndroidRuntime(1247): at android.os.Handler.handleCallback(Handler.java:733)
08-29 13:15:32.355: E/AndroidRuntime(1247): at android.os.Handler.dispatchMessage(Handler.java:95)
08-29 13:15:32.355: E/AndroidRuntime(1247): at android.os.Looper.loop(Looper.java:136)
08-29 13:15:32.355: E/AndroidRuntime(1247): at android.app.ActivityThread.main(ActivityThread.java:5017)
08-29 13:15:32.355: E/AndroidRuntime(1247): at java.lang.reflect.Method.invokeNative(Native Method)
08-29 13:15:32.355: E/AndroidRuntime(1247): at java.lang.reflect.Method.invoke(Method.java:515)
08-29 13:15:32.355: E/AndroidRuntime(1247): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
08-29 13:15:32.355: E/AndroidRuntime(1247): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
08-29 13:15:32.355: E/AndroidRuntime(1247): at dalvik.system.NativeStart.main(Native Method)
答案 0 :(得分:1)
您正在检索字符串并尝试将其设置为URI。你必须解析它。试试这个:
list_item_bac = Uri.parse(i.getStringExtra("list_item_bac"));