1

在我的项目中,我必须将活动添加到 Tabhost。其中一个活动是 InventoryView。当它被加载到 tabHost 时,会发生堆栈溢出错误和基本字节缓冲区错误。我不知道如何解决它。如果有人知道,请帮助我。

编码:

public class **TabActivityView** extends TabActivity
{
    public void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.listmonth);

        Resources res = getResources(); // Resource object to get Drawables
        TabHost tabHost = getTabHost(); // The activity TabHost

        Intent intent = new Intent(this,InventoryView.class);
        tabHost.addTab(tabHost                         // Error Occur While it is Set.
                    .newTabSpec("Week")
                    .setIndicator("Weekly", res.getDrawable(R.drawable.ic_tab_main))
                    .setContent(intent));
    }
}

在 Inventory 类中包含:

package com.experts.IVScreen;

import com.experts.clssfile.*;
import java.util.Calendar;
import android.content.Intent;
import com.experts.IVScreen.R;
import android.app.Activity;
import android.database.sqlite.SQLiteDatabase;
import android.database.Cursor;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.*;
import android.widget.AdapterView.OnItemSelectedListener;

public class InventoryView extends Activity{

    public String       spintext;
    GetDetails          gt        =   new GetDetails(); 
    Databasecreation    db  =   new Databasecreation();
    String              query;
    GridView            list_disp=null;
    DatePicker          sel_date;
    TextView            disp_amt,  date_text;
    Button              btnDwnchart,  btnDwnOk,  btnDwnCancel;
    public int          focus;
    ImageView           btnNext,   btnPre=null;

    SQLiteDatabase       dbase;
    public StringBuffer  buff = null;
    String           mylog="Invent";
    public String    str;
    public String    doentry;
    int tot_amt;
    public int       iSelectedMonth;
    public String    month[]={"January","February","March","April","May","June","July",
                        "August","September","October","November","December"};    

    public void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.listviewinvent);

        dbase       =  db.getdb();        
        Calendar    csCalendar  = Calendar.getInstance();
        iSelectedMonth =  csCalendar.get(Calendar.MONTH);
        Spinner   mon_spin=(Spinner)findViewById(R.id.Spin_year);
        list_disp   =    (GridView)findViewById(R.id.gridView1);
        btnDwnchart =    (Button) findViewById(R.id.btnChart);
        disp_amt    =    (TextView)findViewById(R.id.dispTotAmt);

        btnNext     =    (ImageView)findViewById(R.id.imageView1);
        btnPre      =    (ImageView)findViewById(R.id.imageView2);
        date_text   =    (TextView)findViewById(R.id.textView1);        

        ArrayAdapter NoCoreAdapter =  new ArrayAdapter(this,android.R.layout.simple_spinner_item,  month);
        NoCoreAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

        mon_spin.setAdapter(NoCoreAdapter);
        mon_spin.setOnItemSelectedListener(new MyOnItemSelectedListener());

        date_text.setText(month[iSelectedMonth]);
        tot_amt     =    gt.getMonthlist(0,null, iSelectedMonth);
        dis_grid(tot_amt);

        btnDwnchart.setOnClickListener(new OnClickListener() 
        {
            public void onClick(View v) 
            {
                Intent intent   =  null;
                intent        =    new Intent(InventoryView.this,NewChart.class);
                startActivity(intent);
            }
        });
    }

    public void btnDwnNext(View v)
    {
        if (iSelectedMonth < 11)
        {
            iSelectedMonth++;
        }
        else
        {
            iSelectedMonth  = 0;
        }
        date_text.setText(""+month[iSelectedMonth]);

        tot_amt     =     gt.getMonthlist(0,null, iSelectedMonth);
        dis_grid(tot_amt);
    }

    public void btnDwnPre(View v)
    {
        if (iSelectedMonth > 0)
        {
            iSelectedMonth--;
        }
        else
        {
            iSelectedMonth  = 11;
        }

        date_text.setText(""+month[iSelectedMonth]);
        tot_amt=gt.getMonthlist(0,null, iSelectedMonth);
        dis_grid(tot_amt);
    }

    public void dis_grid(int total)
    {
        String    query1    =      "Select DOENTRY1,NETAMOUNT1 as _id from Invent_Month";

        Cursor     mon      =      dbase.rawQuery(query1, null);

        mon.moveToFirst();
        startManagingCursor(mon);
        SimpleCursorAdapter ada =   new SimpleCursorAdapter(this, R.layout.showlist,
                    mon, new String[] { "DOENTRY1", "_id" }, new int[] { R.id.Entry,R.id.sales });
        list_disp.setAdapter(ada);

        String       convert    =  String.valueOf(total);
        disp_amt.setText(convert);
    }

    public class MyOnItemSelectedListener implements OnItemSelectedListener 
    {
        public void onItemSelected(AdapterView<?> parent,View view, int pos, long id) 
        {
            spintext=parent.getItemAtPosition(pos).toString();

            /*Toast.makeText(parent.getContext(), "The planet is " +
            parent.getItemAtPosition(pos).toString(), Toast.LENGTH_LONG).show();*/
        }

        public void onNothingSelected(AdapterView parent) 
        {
            // Do nothing.
        }
    }
}

原木猫:

06-15 16:26:27.328: E/AndroidRuntime(320): FATAL EXCEPTION: main
06-15 16:26:27.328: E/AndroidRuntime(320): java.lang.StackOverflowError
06-15 16:26:27.328: E/AndroidRuntime(320):  at java.nio.ByteBuffer.<init>(ByteBuffer.java:128)
06-15 16:26:27.328: E/AndroidRuntime(320):  at java.nio.BaseByteBuffer.<init>(BaseByteBuffer.java:26)
06-15 16:26:27.328: E/AndroidRuntime(320):  at java.nio.HeapByteBuffer.<init>(HeapByteBuffer.java:49)
06-15 16:26:27.328: E/AndroidRuntime(320):  at java.nio.HeapByteBuffer.<init>(HeapByteBuffer.java:41)
06-15 16:26:27.328: E/AndroidRuntime(320):  at java.nio.ReadWriteHeapByteBuffer.<init>(ReadWriteHeapByteBuffer.java:43)
06-15 16:26:27.328: E/AndroidRuntime(320):  at java.nio.BufferFactory.newByteBuffer(BufferFactory.java:38)
06-15 16:26:27.328: E/AndroidRuntime(320):  at java.nio.ByteBuffer.wrap(ByteBuffer.java:82)
06-15 16:26:27.328: E/AndroidRuntime(320):  at java.nio.charset.CharsetEncoder.isLegalReplacement(CharsetEncoder.java:646)
06-15 16:26:27.328: E/AndroidRuntime(320):  at java.nio.charset.CharsetEncoder.replaceWith(CharsetEncoder.java:752)
06-15 16:26:27.328: E/AndroidRuntime(320):  at java.nio.charset.CharsetEncoder.<init>(CharsetEncoder.java:184)
06-15 16:26:27.328: E/AndroidRuntime(320):  at com.ibm.icu4jni.charset.CharsetEncoderICU.<init>(CharsetEncoderICU.java:75)
06-15 16:26:27.328: E/AndroidRuntime(320):  at com.ibm.icu4jni.charset.CharsetICU.newEncoder(CharsetICU.java:74)
06-15 16:26:27.328: E/AndroidRuntime(320):  at java.nio.charset.Charset.encode(Charset.java:692)
06-15 16:26:27.328: E/AndroidRuntime(320):  at java.nio.charset.Charset.encode(Charset.java:713)
06-15 16:26:27.328: E/AndroidRuntime(320):  at java.io.File.newCString(File.java:214)
06-15 16:26:27.328: E/AndroidRuntime(320):  at java.io.File.init(File.java:205)
06-15 16:26:27.328: E/AndroidRuntime(320):  at java.io.File.<init>(File.java:175)
06-15 16:26:27.328: E/AndroidRuntime(320):  at java.io.File.<init>(File.java:142)
06-15 16:26:27.328: E/AndroidRuntime(320):  at com.experts.IVScreen.Databasecreation.createDirIfNotExists(Databasecreation.java:67)
06-15 16:26:27.328: E/AndroidRuntime(320):  at com.experts.IVScreen.Databasecreation.getExternalStorageSdCard(Databasecreation.java:34)
06-15 16:26:27.328: E/AndroidRuntime(320):  at com.experts.IVScreen.Databasecreation.<init>(Databasecreation.java:21)
06-15 16:26:27.328: E/AndroidRuntime(320):  at com.experts.clssfile.GetDetails.<init>(GetDetails.java:19)
06-15 16:26:27.328: E/AndroidRuntime(320):  at com.experts.IVScreen.WeekActivity.<init>(WeekActivity.java:22)
06-15 16:26:27.328: E/AndroidRuntime(320):  at com.experts.clssfile.GetDetails.<init>(GetDetails.java:20)
06-15 16:26:27.328: E/AndroidRuntime(320):  at com.experts.IVScreen.WeekActivity.<init>(WeekActivity.java:22)
06-15 16:26:27.328: E/AndroidRuntime(320):  at com.experts.clssfile.GetDetails.<init>(GetDetails.java:20)
4

1 回答 1

0

我从 Get Details 类文件中意识到了我的错误。在那个文件上,我导入了太多的类。所以活动进入堆栈溢出。

于 2012-06-16T09:48:53.410 回答