我不明白错误发生在哪里,我的应用程序倾向于“强制关闭”。这个你能帮我吗。我以前从未见过这样的错误。这是我的 xml 文件:
<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/black_red_texture"
tools:context=".AddictionDetails" >
<ImageView
android:id="@+id/imageViewAddictionDetailsBack"
android:layout_width="25dp"
android:layout_height="25dp"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:src="@drawable/arrow_left"
android:clickable="true" />
<TextView
android:id="@+id/textViewAddictionDetails"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/imageView1"
android:layout_centerHorizontal="true"
android:text="Addiction Details"
android:textSize="20sp" />
<TableLayout
android:layout_width="250dp"
android:layout_height="wrap_content"
android:layout_alignParentEnd="false"
android:layout_below="@id/textViewAddictionDetails"
android:layout_centerHorizontal="true"
android:background="#AAA8A8A8"
android:shrinkColumns="1" >
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="10dp" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="right"
android:text="Today:" />
<TextView
android:id="@+id/textview_today"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_weight="1"
android:text="today" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="10dp" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="right"
android:text="Yesterday:" />
<TextView
android:id="@+id/textview_yesterday"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_weight="1"
android:text="yesterday" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="10dp" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="right"
android:text="This Week:" />
<TextView
android:id="@+id/textview_this_week"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_weight="1"
android:text="this week" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="10dp" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="right"
android:text="This Month:" />
<TextView
android:id="@+id/textview_this_month"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_weight="1"
android:text="this month" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="10dp"
android:paddingTop="10dp" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="right"
android:text="Total:" />
<TextView
android:id="@+id/textview_total"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_weight="1"
android:text="total" />
</TableRow>
</TableLayout>
</RelativeLayout>
这是我的源文件:
package com.addictioncounterapp;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import android.app.Activity;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.TextView;
public class AddictionDetails extends Activity
{
TextView tv_addiction_name, tv_today, tv_yesterday, tv_this_week, tv_this_month, tv_total;
ImageView iv_back;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_addiction_details);
tv_addiction_name = (TextView) findViewById(R.id.textViewAddictionDetails);
tv_total = (TextView) findViewById(R.id.textview_total);
tv_today = (TextView) findViewById(R.id.textview_today);
tv_yesterday = (TextView) findViewById(R.id.textview_yesterday);
tv_this_week = (TextView) findViewById(R.id.textview_this_week);
tv_this_month = (TextView) findViewById(R.id.textview_this_month);
iv_back = (ImageView) findViewById(R.id.imageViewAddictionDetailsBack);
iv_back.setClickable(true);
iv_back.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v)
{
Intent intent = new Intent(AddictionDetails.this, StartActivity.class);
startActivity(intent);
}
}
);
Intent intent = getIntent();
String cat_name = intent.getStringExtra("cat_name");
tv_addiction_name.setText(cat_name);
SQLiteDatabase db = openOrCreateDatabase("AddictionCounter.db", SQLiteDatabase.OPEN_READWRITE, null);
Cursor cursor = db.query("category", new String[]{"cat_id"}, "cat_name=?", new String[]{cat_name}, null, null, null);
//----------------------fetching id-------------------
int cat_id = 0;
if(cursor.getCount() > 0)
while(cursor.moveToNext())
cat_id = cursor.getInt(0);
cursor.close();
//----------------------fetching total-------------------
int total;
cursor = db.query("counter", new String[]{"cat_id"}, "cat_id=?", new String[]{cat_id+""}, null, null, null);
total = cursor.getCount();
tv_total.setText(total+"");
//----------------------fetching today's count---------------
cursor = db.query("counter", new String[]{"counter_entry_date"}, "cat_id=?", new String[]{cat_id+""}, null, null, null);
Calendar cal1 = Calendar.getInstance();
SimpleDateFormat dateFormat1 = new SimpleDateFormat("dd/MM/yyyy");
String todays_date = dateFormat1.format(cal1.getTime());
String cursor_date;
int counter = 0;
if(cursor.getCount() > 0)
{
while(cursor.moveToNext())
{
cursor_date = cursor.getString(0)+"";
if(cursor_date.equals(todays_date))
counter++;
}
}
tv_today.setText(counter+"");
//----------------------fetching yesterdays count------------------
Calendar cal2 = Calendar.getInstance();
SimpleDateFormat dateFormat2 = new SimpleDateFormat("dd/MM/yyyy");
cal2.add(Calendar.DATE, -1);
String yesterdays_date = dateFormat2.format(cal2.getTime());
counter = 0;
cursor.moveToFirst();
if(cursor.getCount() > 0)
{
while(cursor.moveToNext())
{
cursor_date = cursor.getString(0)+"";
if(cursor_date.equals(yesterdays_date))
counter++;
}
}
tv_yesterday.setText(counter+"");
//-------------------------fetching current week count--------------------
ArrayList<String> current_week_dates = new ArrayList<String>();
Calendar c = Calendar.getInstance();
c.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY);
SimpleDateFormat df = new SimpleDateFormat("dd/MM/yyyy");
for (int i = 0; i < 7; i++)
{
current_week_dates.add(df.format(c.getTime()));
c.add(Calendar.DATE, 1);
}
counter=0;
cursor.moveToFirst();
while(cursor.moveToNext())
{
if(current_week_dates.contains(cursor.getString(0)))
{
counter++;
}
}
tv_this_week.setText(counter+"");
//----------------------fetching current month count--------------------
cursor.moveToFirst();
counter=0;
Date date = new Date();
SimpleDateFormat sdf;
sdf = new SimpleDateFormat("MM/yyyy");
String current_month= sdf.format(date);
// Toast.makeText(getBaseContext(), current_month, Toast.LENGTH_SHORT).show();
while(cursor.moveToNext())
{
if((cursor.getString(0)).matches("(.*)"+current_month))
{
counter++;
}
}
// Toast.makeText(getBaseContext(), counter+"", Toast.LENGTH_SHORT).show();
tv_this_month.setText(counter+"");
cursor.close();
}
}
这是我的错误日志:
02-01 10:58:03.904: D/dalvikvm(403): GC_EXTERNAL_ALLOC freed 53K, 53% free 2559K/5379K, external 716K/1038K, paused 76ms
02-01 10:58:10.544: D/dalvikvm(403): GC_EXTERNAL_ALLOC freed 25K, 52% free 2620K/5379K, external 8173K/8699K, paused 65ms
02-01 10:58:10.584: E/dalvikvm-heap(403): 6400000-byte external allocation too large for this process.
02-01 10:58:10.704: E/GraphicsJNI(403): VM won't let us allocate 6400000 bytes
02-01 10:58:10.714: D/dalvikvm(403): GC_FOR_MALLOC freed 2K, 52% free 2618K/5379K, external 8173K/8699K, paused 50ms
02-01 10:58:10.714: D/skia(403): --- decoder->decode returned false
02-01 10:58:10.714: D/AndroidRuntime(403): Shutting down VM
02-01 10:58:10.714: W/dalvikvm(403): threadid=1: thread exiting with uncaught exception (group=0x40015560)
02-01 10:58:10.755: E/AndroidRuntime(403): FATAL EXCEPTION: main
02-01 10:58:10.755: E/AndroidRuntime(403): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.addictioncounterapp/com.addictioncounterapp.AddictionDetails}: android.view.InflateException: Binary XML file line #1: Error inflating class <unknown>
02-01 10:58:10.755: E/AndroidRuntime(403): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
02-01 10:58:10.755: E/AndroidRuntime(403): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
02-01 10:58:10.755: E/AndroidRuntime(403): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
02-01 10:58:10.755: E/AndroidRuntime(403): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
02-01 10:58:10.755: E/AndroidRuntime(403): at android.os.Handler.dispatchMessage(Handler.java:99)
02-01 10:58:10.755: E/AndroidRuntime(403): at android.os.Looper.loop(Looper.java:123)
02-01 10:58:10.755: E/AndroidRuntime(403): at android.app.ActivityThread.main(ActivityThread.java:3683)
02-01 10:58:10.755: E/AndroidRuntime(403): at java.lang.reflect.Method.invokeNative(Native Method)
02-01 10:58:10.755: E/AndroidRuntime(403): at java.lang.reflect.Method.invoke(Method.java:507)
02-01 10:58:10.755: E/AndroidRuntime(403): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
02-01 10:58:10.755: E/AndroidRuntime(403): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
02-01 10:58:10.755: E/AndroidRuntime(403): at dalvik.system.NativeStart.main(Native Method)
02-01 10:58:10.755: E/AndroidRuntime(403): Caused by: android.view.InflateException: Binary XML file line #1: Error inflating class <unknown>
02-01 10:58:10.755: E/AndroidRuntime(403): at android.view.LayoutInflater.createView(LayoutInflater.java:518)
02-01 10:58:10.755: E/AndroidRuntime(403): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
02-01 10:58:10.755: E/AndroidRuntime(403): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:568)
02-01 10:58:10.755: E/AndroidRuntime(403): at android.view.LayoutInflater.inflate(LayoutInflater.java:386)
02-01 10:58:10.755: E/AndroidRuntime(403): at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
02-01 10:58:10.755: E/AndroidRuntime(403): at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
02-01 10:58:10.755: E/AndroidRuntime(403): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:207)
02-01 10:58:10.755: E/AndroidRuntime(403): at android.app.Activity.setContentView(Activity.java:1657)
02-01 10:58:10.755: E/AndroidRuntime(403): at com.addictioncounterapp.AddictionDetails.onCreate(AddictionDetails.java:27)
02-01 10:58:10.755: E/AndroidRuntime(403): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
02-01 10:58:10.755: E/AndroidRuntime(403): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
02-01 10:58:10.755: E/AndroidRuntime(403): ... 11 more
02-01 10:58:10.755: E/AndroidRuntime(403): Caused by: java.lang.reflect.InvocationTargetException
02-01 10:58:10.755: E/AndroidRuntime(403): at java.lang.reflect.Constructor.constructNative(Native Method)
02-01 10:58:10.755: E/AndroidRuntime(403): at java.lang.reflect.Constructor.newInstance(Constructor.java:415)
02-01 10:58:10.755: E/AndroidRuntime(403): at android.view.LayoutInflater.createView(LayoutInflater.java:505)
02-01 10:58:10.755: E/AndroidRuntime(403): ... 21 more
02-01 10:58:10.755: E/AndroidRuntime(403): Caused by: java.lang.OutOfMemoryError: bitmap size exceeds VM budget
02-01 10:58:10.755: E/AndroidRuntime(403): at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
02-01 10:58:10.755: E/AndroidRuntime(403): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:460)
02-01 10:58:10.755: E/AndroidRuntime(403): at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:336)
02-01 10:58:10.755: E/AndroidRuntime(403): at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:697)
02-01 10:58:10.755: E/AndroidRuntime(403): at android.content.res.Resources.loadDrawable(Resources.java:1709)
02-01 10:58:10.755: E/AndroidRuntime(403): at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
02-01 10:58:10.755: E/AndroidRuntime(403): at android.view.View.<init>(View.java:1951)
02-01 10:58:10.755: E/AndroidRuntime(403): at android.view.View.<init>(View.java:1899)
02-01 10:58:10.755: E/AndroidRuntime(403): at android.view.ViewGroup.<init>(ViewGroup.java:286)
02-01 10:58:10.755: E/AndroidRuntime(403): at android.widget.RelativeLayout.<init>(RelativeLayout.java:173)
02-01 10:58:10.755: E/AndroidRuntime(403): ... 24 more
02-01 10:58:12.765: I/Process(403): Sending signal. PID: 403 SIG: 9