0
我收到以下錯誤「類型不匹配:不能從字符串轉換成URI」從以下線路類型不匹配:不能從字符串轉換成開放的
list_item_bac = i.getStringExtra("list_item_bac");
list_item_bac已經確定有一個開放的,因爲它填充通過JSON數據的圖像,所以我不想從Uri更改爲字符串,因爲我沒有返回文本,而是我將投影到圖像視圖的圖像。
下面是整個代碼:
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)
感謝您的及時回覆。現在它更有意義。在應用此更改時,我在eclipse中的活動中收到以下錯誤:「類型NetworkImageView中的方法setImageUrl(String,ImageLoader)不適用於參數(Uri,ImageLoader)」,位於hsvimage1.setImageUrl行(url1 ,mImageLoader);如果您可以提供另一個建議,這將會非常有幫助。 – John 2014-08-29 17:15:27
在這種情況下,你需要一個字符串,而不是一個URI。由於setInageUrl方法需要一個字符串,因此在將它傳遞給 – user1282637 2014-08-30 17:02:00
之前,您需要將URI轉換爲字符串。感謝您的回覆。這樣做,我遇到了一個空指針異常錯誤。我已經在我的初始文章的更新部分中添加了日誌貓消息。 – John 2014-08-30 19:46:54