我正在为一家公司编写移动商务应用程序。在活动中显示产品详细信息时出错。这些是详细信息:
package com.Troyateck.sucukevim;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.util.ArrayList;
import java.util.concurrent.ExecutionException;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;
import android.os.AsyncTask;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.text.Html;
import android.view.Menu;
import android.view.View;
import android.view.Window;
import android.view.View.OnClickListener;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
public class Product extends Activity implements OnClickListener {
ImageButton sepet,sepeteekle;
String id,mail,ad;
TextView greeting;
public String urunid;
@Override
protected void onCreate(Bundle savedInstanceState) {
System.out.println("Mert");
super.onCreate(savedInstanceState);
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_product);
Bundle extras = getIntent().getExtras();
if (extras != null) {
ad=extras.getString("ad");
urunid=extras.getString("urunid");
System.out.println(ad);
greeting=(TextView)findViewById(R.id.greetingsText);
greeting.setText("Hoşgeldiniz, "+extras.getString("ad"));
}
GetProductsData get = new GetProductsData();
try {
icerik=get.execute(new String[] { urunid }).get();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ExecutionException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if(icerik.size()>1)
{
icerik.remove(icerik.size()-1);
}
for (int i = 0; i < icerik.size(); i++) {
try {
LoadContents(i);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ExecutionException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
Kontroller();
TextView t = (TextView)findViewById(R.id.textView1);
t.setText("Şuanda sepetinizde "+Cart.userCart.size()+" ürün bulunmaktadır. \n Sepetinize gitmek için tıklayınız");
}
public ArrayList<ProductIcerik> icerik = new ArrayList<ProductIcerik>();
private void Kontroller() {
sepet =(ImageButton) findViewById(R.id.imageButton2);
sepeteekle =(ImageButton) findViewById(R.id.imageButton3);
sepet.setOnClickListener(this);
sepeteekle.setOnClickListener(this);
}
public void onClick(View view) {
switch (view.getId()) {
case R.id.imageButton1:
break;
case R.id.imageButton2:
try {
Intent intent = new Intent(this, Class.forName("com.Troyateck.sucukevim.Cart"));
intent.putExtra("ad",ad);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
getApplicationContext().startActivity(intent);
} catch (ClassNotFoundException e) {
Toast.makeText(this, "Hata : " + e.toString(),
Toast.LENGTH_SHORT).show();
}
break;
case R.id.imageButton3:
//that's
Cart c = new Cart();
System.out.println(c.userCart.size());
System.out.println("job1");
c.AddToCart(icerik.get(0).id,icerik.get(0).baslik,"1",icerik.get(0).link,icerik.get(0).fiyat,icerik.get(0).kisaca);
System.out.println(c.userCart.size());
TextView t = (TextView)findViewById(R.id.textView1);
t.setText("Şuanda sepetinizde "+Cart.userCart.size()+" ürün bulunmaktadır. \n Sepetinize gitmek için tıklayınız");
break;
}
}
public void LoadContents(int i) throws InterruptedException, ExecutionException
{
ImageView resim = (ImageView)findViewById(R.id.imageView7);
resim.setImageDrawable(LoadImageFromWeb(icerik.get(i).resim));
TextView baslik = (TextView)findViewById(R.id.txtbaslik);
baslik.setText(icerik.get(i).baslik);
TextView fiyat = (TextView)findViewById(R.id.txtfiyat);
fiyat.setText(icerik.get(i).fiyat+" TL");
TextView aciklama = (TextView)findViewById(R.id.txtaciklama);
aciklama.setText(Html.fromHtml(icerik.get(i).detay));
TextView stoka = (TextView)findViewById(R.id.txtstok);
if(icerik.get(i).stok=="1")
{
stoka.setText("Stok Durumu: Stokta Var");
}
else if(icerik.get(i).stok=="0")
{
stoka.setText("Stok Durumu: Stokta Yok");
}
}
public Drawable LoadImageFromWeb(String url)
{
try
{
InputStream is = (InputStream) new URL(url).getContent();
Drawable d = Drawable.createFromStream(is, "src name");
return d;
}catch (Exception e) {
System.out.println("Exc="+e.getMessage());
return null;
}
}
public class ProductIcerik
{
public ProductIcerik()
{
}
public ProductIcerik(int id,String link,String baslik,String fiyat,String kategori,String birim,String indirim,String stok,String etiket,String detay,String resim)
{
this.id=id;
this.link=link;
this.baslik=baslik;
this.fiyat=fiyat;
this.kategori=kategori;
this.birim=birim;
this.indirim=indirim;
this.stok=stok;
this.etiket=etiket;
this.detay=detay;
this.resim=resim;
}
public int id;
public String link;
public String baslik;
public String fiyat;
public String kategori;
public String kisaca;
public String birim;
public String indirim;
public String stok;
public String etiket;
public String detay;
public String resim;
public String anasayfa;
public String secilmis;
public String yeni;
public String satis;
}
private class GetProductsData extends AsyncTask<String, ArrayList<ProductIcerik>, ArrayList<ProductIcerik>> {
@Override
protected ArrayList<ProductIcerik> doInBackground(String... params) {
URL url;
ArrayList<ProductIcerik> productsL = new ArrayList<ProductIcerik>();
try
{
url = new URL("http://www.sucukevim.com/external_services.php?service=get_product&&id="+params[0]);
System.out.println(url);
URLConnection connection;
connection = url.openConnection();
HttpURLConnection httpConnection = (HttpURLConnection)connection;
int responseCode = httpConnection.getResponseCode();
if(responseCode==HttpURLConnection.HTTP_OK)
{
InputStream in = httpConnection.getInputStream();
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document dom = db.parse(in);
Element docEle = dom.getDocumentElement();
NodeList nl = docEle.getElementsByTagName("product");
for (int i = 0; i < nl.getLength(); i++) {
Node childNode = nl.item(i);
Element eElement = (Element)childNode;
productsL.add(new ProductIcerik(Integer.parseInt(getTagValue("id", eElement)),"http://www.sucukevim.com/pictures/products/"+getTagValue("resim",eElement),getTagValue("ad",eElement),getTagValue("fiyat",eElement),getTagValue("kategori",eElement),getTagValue("birim",eElement),getTagValue("indirim",eElement),getTagValue("stok",eElement),getTagValue("etiket",eElement),getTagValue("detay",eElement),"http://www.sucukevim.com/pictures/products/"+getTagValue("resim",eElement)));
System.out.println(getTagValue("ad",eElement));
//productsL.add(new ProductData(Integer.parseInt(getTagValue("id", eElement)),getTagValue("ad", eElement),getTagValue("fiyat", eElement),getTagValue("kisaca", eElement),"http://www.sucukevim.com/pictures/products/"+getTagValue("resim", eElement),Integer.toString(i)));
}
return productsL;
}
}
catch(MalformedURLException e)
{
}
catch(IOException e)
{
}
catch(ParserConfigurationException e){
}
catch(SAXException e)
{
}
return null;
}
public String getTagValue(String tag,Element eElement)
{
String retVal = "NOT FOUND";
if (eElement != null&& eElement.getElementsByTagName(tag).item(0) != null)
{
NodeList nlList = eElement.getElementsByTagName(tag).item(0).getChildNodes();
if (nlList.item(0) != null)
{
Node nValue = (Node) nlList.item(0);
retVal = nValue.getTextContent();
}
}
return retVal;
}
protected void onPostExecute(ArrayList<ProductIcerik> result) {
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.product, menu);
return true;
}
}
<?xml version="1.0" encoding="utf-8"?>
<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:background="@drawable/bg"
tools:context=".Product" >
<ImageButton
android:id="@+id/imageButton1"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:adjustViewBounds="false"
android:background="@null"
android:cropToPadding="false"
android:scaleType="fitXY"
android:src="@drawable/shoppingcart" />
<ImageButton
android:id="@+id/imageButton2"
android:layout_width="220dp"
android:layout_height="100dp"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:background="@null"
android:scaleType="fitXY"
android:src="@drawable/sepetiniz" />
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="45dp"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:adjustViewBounds="false"
android:background="@null"
android:cropToPadding="false"
android:scaleType="fitXY"
android:src="@drawable/header" />
<ImageView
android:id="@+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="25dp"
android:layout_alignParentLeft="true"
android:layout_below="@+id/imageView1"
android:adjustViewBounds="false"
android:background="@null"
android:cropToPadding="false"
android:scaleType="fitXY"
android:src="@drawable/main_head_bg" />
<TextView
android:id="@+id/greetingsText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="6dp"
android:layout_marginTop="12dp"
android:text="Merhaba Mesajı" />
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginBottom="19dp"
android:layout_toRightOf="@+id/imageButton1"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#FFFFFF"
android:textSize="8sp" />
<ImageView
android:id="@+id/imageView4"
android:layout_width="wrap_content"
android:layout_height="25dp"
android:layout_alignBottom="@+id/uyelikBilgileriniz"
android:layout_alignParentLeft="true"
android:adjustViewBounds="false"
android:background="@null"
android:cropToPadding="false"
android:scaleType="fitXY"
android:src="@drawable/main_header" />
<ImageView
android:id="@+id/imageView2"
android:layout_width="130dp"
android:layout_height="100dp"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:background="@null"
android:scaleType="fitXY"
android:src="@drawable/logo_main" />
<Button
android:id="@+id/uyelikBilgileriniz"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/imageView1"
android:background="@null"
android:text="Üyelik Bilgileriniz"
android:textSize="12sp" />
<ScrollView
android:id="@+id/scrollView1"
android:layout_width="wrap_content"
android:layout_height="35dp"
android:layout_above="@+id/imageButton1"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_below="@+id/imageView6"
android:background="@drawable/main_center" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/txtaciklama"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Small Text"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textSize="10sp" />
</LinearLayout>
</ScrollView>
<ImageView
android:id="@+id/imageView5"
android:layout_width="wrap_content"
android:layout_height="20dp"
android:layout_alignBottom="@+id/imageView6"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_below="@+id/imageView2"
android:scaleType="fitXY"
android:src="@drawable/main_top_bg" />
<ImageView
android:id="@+id/imageView6"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_alignLeft="@+id/greetingsText"
android:layout_below="@+id/imageView4"
android:scaleType="fitXY"
android:src="@drawable/img_bg" />
<TextView
android:id="@+id/txtbaslik"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="10sp"
android:layout_above="@+id/imageView5"
android:layout_alignLeft="@+id/txtfiyat"
android:text="Başlık"
android:textAppearance="?android:attr/textAppearanceLarge" />
<Button
android:id="@+id/satinAldiklariniz"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/imageView1"
android:layout_toLeftOf="@+id/imageView2"
android:background="@null"
android:text="Satın Aldıklarınız"
android:textSize="12sp" />
<ImageButton
android:id="@+id/imageButton3"
android:layout_width="70dp"
android:layout_height="70dp"
android:layout_alignParentRight="true"
android:layout_below="@+id/txtbaslik"
android:background="@null"
android:scaleType="fitXY"
android:src="@drawable/sepete_ekle" />
<TextView
android:id="@+id/txtfiyat"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/satinAldiklariniz"
android:layout_alignTop="@+id/imageView5"
android:text="Fiyat"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textSize="12sp" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/txtfiyat"
android:layout_below="@+id/txtfiyat"
android:text="Small Text"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textSize="6sp" />
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView2"
android:layout_below="@+id/textView2"
android:text="Small Text"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textSize="6sp" />
<TextView
android:id="@+id/txtstok"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/textView3"
android:layout_toRightOf="@+id/imageButton1"
android:text="Stok Durumu"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textSize="10sp" />
<ImageView
android:id="@+id/imageView7"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_alignRight="@+id/imageView6"
android:layout_alignTop="@+id/imageView5"
android:src="@drawable/iicon" />
05-26 04:41:44.994: E/AndroidRuntime(1028): 致命异常: main 05-26 04:41:44.994: E/AndroidRuntime(1028): java.lang.RuntimeException: 无法启动活动 ComponentInfo{com. Troyateck.sucukevim/com.Troyateck.sucukevim.Product}:android.view.InflateException:二进制 XML 文件第 134 行:膨胀类 05-26 04:41:44.994 时出错:E/AndroidRuntime(1028):在 android.app。 ActivityThread.performLaunchActivity(ActivityThread.java:2180) 05-26 04:41:44.994: E/AndroidRuntime(1028): 在 android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230) 05-26 04:41:44.994: E/AndroidRuntime(1028): 在 android.app.ActivityThread.access$600(ActivityThread.java:141) 05-26 04:41:44.994: E/AndroidRuntime(1028): 在 android.app.ActivityThread$H.handleMessage( ActivityThread.java:1234) 05-26 04:41:44.994:E/AndroidRuntime(1028): 在 android.os.Handler.dispatchMessage(Handler.java:99) 05-26 04:41:44.994: E/AndroidRuntime(1028): 在 android.os.Looper.loop(Looper.java :137) 05-26 04:41:44.994: E/AndroidRuntime(1028): 在 android.app.ActivityThread.main(ActivityThread.java:5041) 05-26 04:41:44.994: E/AndroidRuntime(1028):在 java.lang.reflect.Method.invokeNative(Native Method) 05-26 04:41:44.994: E/AndroidRuntime(1028): 在 java.lang.reflect.Method.invoke(Method.java:511) 05-26 04:41:44.994: E/AndroidRuntime(1028): 在 com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793) 05-26 04:41:44.994: E/AndroidRuntime(1028):在 com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560) 05-26 04:41:44.994: E/AndroidRuntime(1028): 在 dalvik.system.NativeStart.main(Native Method) 05-26 04:41:44.994:E/AndroidRuntime(1028):引起:android.view.InflateException:二进制 XML 文件行#134:错误膨胀类 05-26 04:41:44.994:E/AndroidRuntime(1028):在 android.view .LayoutInflater.createView(LayoutInflater.java:613) 05-26 04:41:44.994: E/AndroidRuntime(1028): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56) 05- 26 04:41:44.994: E/AndroidRuntime(1028): 在 android.view.LayoutInflater.onCreateView(LayoutInflater.java:660) 05-26 04:41:44.994: E/AndroidRuntime(1028): 在 android.view。 LayoutInflater.createViewFromTag(LayoutInflater.java:685) 05-26 04:41:44.994: E/AndroidRuntime(1028): 在 android.view.LayoutInflater.rInflate(LayoutInflater.java:746) 05-26 04:41:44.994: E/AndroidRuntime(1028):在 android.view.LayoutInflater。inflate(LayoutInflater.java:489) 05-26 04:41:44.994: E/AndroidRuntime(1028): 在 android.view.LayoutInflater.inflate(LayoutInflater.java:396) 05-26 04:41:44.994: E/ AndroidRuntime(1028): 在 android.view.LayoutInflater.inflate(LayoutInflater.java:352) 05-26 04:41:44.994: E/AndroidRuntime(1028): 在 com.android.internal.policy.impl.PhoneWindow.setContentView (PhoneWindow.java:270) 05-26 04:41:44.994: E/AndroidRuntime(1028): 在 android.app.Activity.setContentView(Activity.java:1881) 05-26 04:41:44.994: E/AndroidRuntime (1028): 在 com.Troyateck.sucukevim.Product.onCreate(Product.java:50) 05-26 04:41:44.994: E/AndroidRuntime(1028): 在 android.app.Activity.performCreate(Activity.java: 5104) 05-26 04:41:44.994: E/AndroidRuntime(1028): 在 android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080) 05-26 04:41:44.994: E/AndroidRuntime(1028): 在 android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144) 05-26 04:41:44.994: E/AndroidRuntime(1028): . .. 11 更多 05-26 04:41:44.994: E/AndroidRuntime(1028): 由: java.lang.reflect.InvocationTargetException 05-26 04:41:44.994: E/AndroidRuntime(1028): at java.lang .reflect.Constructor.constructNative(Native Method) 05-26 04:41:44.994: E/AndroidRuntime(1028): at java.lang.reflect.Constructor.newInstance(Constructor.java:417) 05-26 04:41: 44.994: E/AndroidRuntime(1028): 在 android.view.LayoutInflater.createView(LayoutInflater.java:587) 05-26 04:41:44.994: E/AndroidRuntime(1028): ... 24 更多 05-26 04: 41:44.994:E/AndroidRuntime(1028):由:java.lang.OutOfMemoryError 05-26 04:41:44.994:E/AndroidRuntime(1028):在 android。graphics.BitmapFactory.nativeDecodeAsset(Native Method) 05-26 04:41:44.994: E/AndroidRuntime(1028): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:502) 05-26 04:41:44.994: E /AndroidRuntime(1028): 在 android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:355) 05-26 04:41:44.994: E/AndroidRuntime(1028): 在 android.graphics.drawable.Drawable.createFromResourceStream(Drawable. java:785) 05-26 04:41:44.994: E/AndroidRuntime(1028): 在 android.content.res.Resources.loadDrawable(Resources.java:1965) 05-26 04:41:44.994: E/AndroidRuntime( 1028): 在 android.content.res.TypedArray.getDrawable(TypedArray.java:601) 05-26 04:41:44.994: E/AndroidRuntime(1028): 在 android.widget.ImageView.(ImageView.java:120) 05-26 04:41:44.994: E/AndroidRuntime(1028): 在 android.widget.ImageView。(ImageView.java:110) 05-26 04:41:44.994: E/AndroidRuntime(1028): ... 27 更多