我是android的新手,在片段的新波士顿教程中,我几乎做了我应该做的事情,但我面对片段异常:
我的主要活动:
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
public class MainActivity extends ActionBarActivity implements TopSection.TopSectionListener {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
@Override
public void createMeme(String top, String bottom)
{
pictureFragment b = (pictureFragment) getSupportFragmentManager().findFragmentById(R.id.fragment2);
b.setMemeText(top, bottom);
}
我的TopSection片段:
import android.app.Activity;
import android.support.v4.app.Fragment;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.text.Editable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class TopSection extends Fragment
{
private static EditText topTextInput;
private static EditText bottomTextInput;
TopSectionListener activityCommander;
public interface TopSectionListener
{
public void createMeme(String top, String bottom);
}
@Override
public void onAttach(Activity activity)
{
super.onAttach(activity);
try
{
activityCommander = (TopSectionListener) activity;
}
catch(ClassCastException e)
{
throw new ClassCastException(activity.toString());
}
}
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState)
{
View view = inflater.inflate(R.layout.my_frame, container, false);
topTextInput = (EditText) view.findViewById(R.id.topTextFeild);
bottomTextInput = (EditText) view.findViewById(R.id.bottomTextFeild);
final Button button = (Button) view.findViewById(R.id.button);
button.setOnClickListener(
new Button.OnClickListener()
{
public void onClick(View v)
{
ButtonClicked(v);
}
}
);
return view;
}
public void ButtonClicked(View v)
{
activityCommander.createMeme(topTextInput.getText().toString(), bottomTextInput.getText().toString());
}
}
my PictureFragment:
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
public class PictureFragment extends Fragment
{
private static TextView topText;
private static TextView bottomText;
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState)
{
View view = inflater.inflate(R.layout.picture_fragment, container, false);
topText = (TextView) view.findViewById(R.id.topTextView);
bottomText = (TextView) view.findViewById(R.id.bottomTextView);
return view;
}
public void setMemeText(String top, String bottom)
{
topText.setText(top);
bottomText.setText(bottom);
}
}
最后日志是:
08-11 06:04:29.594 1500-1500/? D/dalvikvm﹕ Late-enabling CheckJNI
08-11 06:04:30.094 1500-1500/? I/dalvikvm﹕ Could not find method android.content.res.TypedArray.getChangingConfigurations, referenced from method android.support.v7.internal.widget.TintTypedArray.getChangingConfigurations
08-11 06:04:30.094 1500-1500/com.example.yahya.fragments W/dalvikvm﹕ VFY: unable to resolve virtual method 408: Landroid/content/res/TypedArray;.getChangingConfigurations ()I
08-11 06:04:30.094 1500-1500/com.example.yahya.fragments D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x0002
08-11 06:04:30.094 1500-1500/com.example.yahya.fragments I/dalvikvm﹕ Could not find method android.content.res.TypedArray.getType, referenced from method android.support.v7.internal.widget.TintTypedArray.getType
08-11 06:04:30.094 1500-1500/com.example.yahya.fragments W/dalvikvm﹕ VFY: unable to resolve virtual method 430: Landroid/content/res/TypedArray;.getType (I)I
08-11 06:04:30.094 1500-1500/com.example.yahya.fragments D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x0002
08-11 06:04:30.146 1500-1500/com.example.yahya.fragments I/dalvikvm﹕ Could not find method android.content.res.Resources.getDrawable, referenced from method android.support.v7.internal.widget.ResourcesWrapper.getDrawable
08-11 06:04:30.146 1500-1500/com.example.yahya.fragments W/dalvikvm﹕ VFY: unable to resolve virtual method 371: Landroid/content/res/Resources;.getDrawable (ILandroid/content/res/Resources$Theme;)Landroid/graphics/drawable/Drawable;
08-11 06:04:30.146 1500-1500/com.example.yahya.fragments D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x0002
08-11 06:04:30.146 1500-1500/com.example.yahya.fragments I/dalvikvm﹕ Could not find method android.content.res.Resources.getDrawableForDensity, referenced from method android.support.v7.internal.widget.ResourcesWrapper.getDrawableForDensity
08-11 06:04:30.146 1500-1500/com.example.yahya.fragments W/dalvikvm﹕ VFY: unable to resolve virtual method 373: Landroid/content/res/Resources;.getDrawableForDensity (IILandroid/content/res/Resources$Theme;)Landroid/graphics/drawable/Drawable;
08-11 06:04:30.146 1500-1500/com.example.yahya.fragments D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x0002
08-11 06:04:31.170 1500-1500/com.example.yahya.fragments D/dalvikvm﹕ GC_FOR_ALLOC freed 164K, 8% free 3178K/3424K, paused 4ms, total 4ms
08-11 06:04:31.170 1500-1500/com.example.yahya.fragments I/dalvikvm-heap﹕ Forcing collection of SoftReferences for 127844364-byte allocation
08-11 06:04:31.178 1500-1500/com.example.yahya.fragments D/dalvikvm﹕ GC_BEFORE_OOM freed 9K, 8% free 3169K/3424K, paused 8ms, total 8ms
08-11 06:04:31.178 1500-1500/com.example.yahya.fragments E/dalvikvm-heap﹕ Out of memory on a 127844364-byte allocation.
08-11 06:04:31.178 1500-1500/com.example.yahya.fragments I/dalvikvm﹕ "main" prio=5 tid=1 RUNNABLE
08-11 06:04:31.178 1500-1500/com.example.yahya.fragments I/dalvikvm﹕ | group="main" sCount=0 dsCount=0 obj=0xa4d32bd8 self=0xb9498eb0
08-11 06:04:31.178 1500-1500/com.example.yahya.fragments I/dalvikvm﹕ | sysTid=1500 nice=0 sched=0/0 cgrp=apps handle=-1216720832
08-11 06:04:31.178 1500-1500/com.example.yahya.fragments I/dalvikvm﹕ | state=R schedstat=( 1259106028 86198384 90 ) utm=108 stm=17 core=1
08-11 06:04:31.178 1500-1500/com.example.yahya.fragments I/dalvikvm﹕ at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
08-11 06:04:31.178 1500-1500/com.example.yahya.fragments I/dalvikvm﹕ at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:594)
08-11 06:04:31.178 1500-1500/com.example.yahya.fragments I/dalvikvm﹕ at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:429)
08-11 06:04:31.178 1500-1500/com.example.yahya.fragments I/dalvikvm﹕ at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:840)
08-11 06:04:31.178 1500-1500/com.example.yahya.fragments I/dalvikvm﹕ at android.content.res.Resources.loadDrawable(Resources.java:2110)
08-11 06:04:31.178 1500-1500/com.example.yahya.fragments I/dalvikvm﹕ at android.content.res.TypedArray.getDrawable(TypedArray.java:602)
08-11 06:04:31.178 1500-1500/com.example.yahya.fragments I/dalvikvm﹕ at android.view.View.<init>(View.java:3554)
08-11 06:04:31.178 1500-1500/com.example.yahya.fragments I/dalvikvm﹕ at android.view.View.<init>(View.java:3484)
08-11 06:04:31.178 1500-1500/com.example.yahya.fragments I/dalvikvm﹕ at android.view.ViewGroup.<init>(ViewGroup.java:464)
08-11 06:04:31.178 1500-1500/com.example.yahya.fragments I/dalvikvm﹕ at android.widget.RelativeLayout.<init>(RelativeLayout.java:236)
08-11 06:04:31.178 1500-1500/com.example.yahya.fragments I/dalvikvm﹕ at java.lang.reflect.Constructor.constructNative(Native Method)
08-11 06:04:31.178 1500-1500/com.example.yahya.fragments I/dalvikvm﹕ at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
08-11 06:04:31.178 1500-1500/com.example.yahya.fragments I/dalvikvm﹕ at android.view.LayoutInflater.createView(LayoutInflater.java:594)
08-11 06:04:31.178 1500-1500/com.example.yahya.fragments I/dalvikvm﹕ at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
08-11 06:04:31.178 1500-1500/com.example.yahya.fragments I/dalvikvm﹕ at android.view.LayoutInflater.onCreateView(LayoutInflater.java:669)
08-11 06:04:31.178 1500-1500/com.example.yahya.fragments I/dalvikvm﹕ at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:694)
08-11 06:04:31.178 1500-1500/com.example.yahya.fragments I/dalvikvm﹕ at android.view.LayoutInflater.inflate(LayoutInflater.java:469)
08-11 06:04:31.178 1500-1500/com.example.yahya.fragments I/dalvikvm﹕ at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
08-11 06:04:31.178 1500-1500/com.example.yahya.fragments I/dalvikvm﹕ at com.example.yahya.fragments.pictureFragment.onCreateView(pictureFragment.java:20)
08-11 06:04:31.178 1500-1500/com.example.yahya.fragments I/dalvikvm﹕ at android.support.v4.app.Fragment.performCreateView(Fragment.java:1789)
08-11 06:04:31.178 1500-1500/com.example.yahya.fragments I/dalvikvm﹕ at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:924)
08-11 06:04:31.178 1500-1500/com.example.yahya.fragments I/dalvikvm﹕ at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1116)
08-11 06:04:31.178 1500-1500/com.example.yahya.fragments I/dalvikvm﹕ at android.support.v4.app.FragmentManagerImpl.addFragment(FragmentManager.java:1218)
08-11 06:04:31.178 1500-1500/com.example.yahya.fragments I/dalvikvm﹕ at android.support.v4.app.FragmentManagerImpl.onCreateView(FragmentManager.java:2170)
08-11 06:04:31.178 1500-1500/com.example.yahya.fragments I/dalvikvm﹕ at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:300)
08-11 06:04:31.178 1500-1500/com.example.yahya.fragments I/dalvikvm﹕ at android.support.v7.app.AppCompatDelegateImplV7.callActivityOnCreateView(AppCompatDelegateImplV7.java:842)
08-11 06:04:31.178 1500-1500/com.example.yahya.fragments I/dalvikvm﹕ at android.support.v7.app.AppCompatDelegateImplV11.callActivityOnCreateView(AppCompatDelegateImplV11.java:34)
08-11 06:04:31.178 1500-1500/com.example.yahya.fragments I/dalvikvm﹕ at android.support.v7.app.AppCompatDelegateImplV7.onCreateView(AppCompatDelegateImplV7.java:830)
08-11 06:04:31.178 1500-1500/com.example.yahya.fragments I/dalvikvm﹕ at android.support.v4.view.LayoutInflaterCompatHC$FactoryWrapperHC.onCreateView(LayoutInflaterCompatHC.java:44)
08-11 06:04:31.178 1500-1500/com.example.yahya.fragments I/dalvikvm﹕ at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:684)
08-11 06:04:31.178 1500-1500/com.example.yahya.fragments I/dalvikvm﹕ at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
08-11 06:04:31.178 1500-1500/com.example.yahya.fragments I/dalvikvm﹕ at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
08-11 06:04:31.178 1500-1500/com.example.yahya.fragments I/dalvikvm﹕ at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
08-11 06:04:31.178 1500-1500/com.example.yahya.fragments I/dalvikvm﹕ at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
08-11 06:04:31.178 1500-1500/com.example.yahya.fragments I/dalvikvm﹕ at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:249)
08-11 06:04:31.178 1500-1500/com.example.yahya.fragments I/dalvikvm﹕ at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:106)
08-11 06:04:31.178 1500-1500/com.example.yahya.fragments I/dalvikvm﹕ at com.example.yahya.fragments.MainActivity.onCreate(MainActivity.java:15)
08-11 06:04:31.178 1500-1500/com.example.yahya.fragments I/dalvikvm﹕ at android.app.Activity.performCreate(Activity.java:5231)
08-11 06:04:31.182 1500-1500/com.example.yahya.fragments I/dalvikvm﹕ at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
08-11 06:04:31.182 1500-1500/com.example.yahya.fragments I/dalvikvm﹕ at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2148)
08-11 06:04:31.182 1500-1500/com.example.yahya.fragments I/dalvikvm﹕ at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233)
08-11 06:04:31.182 1500-1500/com.example.yahya.fragments I/dalvikvm﹕ at android.app.ActivityThread.access$800(ActivityThread.java:135)
08-11 06:04:31.182 1500-1500/com.example.yahya.fragments I/dalvikvm﹕ at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
08-11 06:04:31.182 1500-1500/com.example.yahya.fragments I/dalvikvm﹕ at android.os.Handler.dispatchMessage(Handler.java:102)
08-11 06:04:31.182 1500-1500/com.example.yahya.fragments I/dalvikvm﹕ at android.os.Looper.loop(Looper.java:136)
08-11 06:04:31.182 1500-1500/com.example.yahya.fragments I/dalvikvm﹕ at android.app.ActivityThread.main(ActivityThread.java:5001)
08-11 06:04:31.182 1500-1500/com.example.yahya.fragments I/dalvikvm﹕ at java.lang.reflect.Method.invokeNative(Native Method)
08-11 06:04:31.182 1500-1500/com.example.yahya.fragments I/dalvikvm﹕ at java.lang.reflect.Method.invoke(Method.java:515)
08-11 06:04:31.182 1500-1500/com.example.yahya.fragments I/dalvikvm﹕ at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
08-11 06:04:31.182 1500-1500/com.example.yahya.fragments I/dalvikvm﹕ at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
08-11 06:04:31.182 1500-1500/com.example.yahya.fragments I/dalvikvm﹕ at dalvik.system.NativeStart.main(Native Method)
08-11 06:04:31.182 1500-1500/com.example.yahya.fragments I/dalvikvm﹕ [ 08-11 06:04:31.182 1500: 1500 D/skia ]
--- allocation failed for scaled bitmap
08-11 06:04:31.182 1500-1500/com.example.yahya.fragments D/AndroidRuntime﹕ Shutting down VM
08-11 06:04:31.186 1500-1500/com.example.yahya.fragments W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0xa4d31b20)
08-11 06:04:31.186 1500-1500/com.example.yahya.fragments E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.example.yahya.fragments, PID: 1500
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.yahya.fragments/com.example.yahya.fragments.MainActivity}: android.view.InflateException: Binary XML file line #2: Error inflating class <unknown>
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2184)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233)
at android.app.ActivityThread.access$800(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5001)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class <unknown>
at android.view.LayoutInflater.createView(LayoutInflater.java:620)
at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:669)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:694)
at android.view.LayoutInflater.inflate(LayoutInflater.java:469)
at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
at com.example.yahya.fragments.pictureFragment.onCreateView(pictureFragment.java:20)
at android.support.v4.app.Fragment.performCreateView(Fragment.java:1789)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:924)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1116)
at android.support.v4.app.FragmentManagerImpl.addFragment(FragmentManager.java:1218)
at android.support.v4.app.FragmentManagerImpl.onCreateView(FragmentManager.java:2170)
at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:300)
at android.support.v7.app.AppCompatDelegateImplV7.callActivityOnCreateView(AppCompatDelegateImplV7.java:842)
at android.support.v7.app.AppCompatDelegateImplV11.callActivityOnCreateView(AppCompatDelegateImplV11.java:34)
at android.support.v7.app.AppCompatDelegateImplV7.onCreateView(AppCompatDelegateImplV7.java:830)
at android.support.v4.view.LayoutInflaterCompatHC$FactoryWrapperHC.onCreateView(LayoutInflaterCompatHC.java:44)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:684)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:249)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:106)
at com.example.yahya.fragments.MainActivity.onCreate(MainActivity.java:15)
at android.app.Activity.performCreate(Activity.java:5231)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2148)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233)
at android.app.ActivityThread.access$800(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5001)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.constructNative(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at android.view.LayoutInflater.createView(LayoutInflater.java:594)
at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:669)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:694)
at android.view.LayoutInflater.inflate(LayoutInflater.java:469)
at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
at com.example.yahya.fragments.pictureFragment.onCreateView(pictureFragment.java:20)
at android.support.v4.app.Fragment.performCreateView(Fragment.java:1789)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:924)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1116)
at android.support.v4.app.FragmentManagerImpl.addFragment(FragmentManager.java:1218)
at android.support.v4.app.FragmentManagerImpl.onCreateView(FragmentManager.java:2170)
at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:300)
at android.support.v7.app.AppCompatDelegateImplV7.callActivityOnCreateView(AppCompatDelegateImplV7.java:842)
at android.support.v7.app.AppCompatDelegateImplV11.callActivityOnCreateView(AppCompatDelegateImplV11.java:34)
at android.support.v7.app.AppCompatDelegateImplV7.onCreateView(AppCompatDelegateImplV7.java:830)
at android.support.v4.view.LayoutInflaterCompatHC$FactoryWrapperHC.onCreateView(LayoutInflaterCompatHC.java:44)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:684)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:249)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:106)
at com.example.yahya.fragments.MainActivity.onCreate(MainActivity.java:15)
at android.app.Activity.performCreate(Activity.java:5231)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2148)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233)
at android.app.ActivityThread.access$800(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5001)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.OutOfMemoryError
at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:594)
at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:429)
at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.ja
清单文件:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.yahya.fragments" >
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Build.gradle(片段):
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.2.3'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
build.gradle(module:app)
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion "23.0.0 rc3"
defaultConfig {
applicationId "com.example.yahya.fragments"
minSdkVersion 15
targetSdkVersion 22
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.2.1'
}
感谢您的帮助。
答案 0 :(得分:0)
试试这个;
更改 import android.support.v4.app.Fragment;
要 import android.support.v7.app.Fragment;
在你的片段中
答案 1 :(得分:0)
最后我自己找到了答案:
导致以下异常的原因之一是我们在布局中有一个大图像(即使在MB方面)并且VM无法加载它。通过删除它或甚至使其尺寸更小,异常将消失。
引起:android.view.InflateException:二进制XML文件行#2:错误导致类