在Eclipse里面的Android程序为什么一运行就停止运行了 4C

哪位大神帮帮忙!在线等挺急的 谢谢

没加事件光布局运行起来都停止响应 也没有错误提示
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.example.testimage.MainActivity$PlaceholderFragment" >

<ImageView 
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="1"
    android:src="@drawable/ic_launcher"
    />

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal" >

    <Button
        android:id="@+id/pre"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="上一张"
        />
    <view
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:layout_weight="1"
        />
    <Button
        android:id="@+id/next"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="下一张"
        />
</LinearLayout>

MainActivity.java
package com.example.testimage;

import android.support.v7.app.ActionBarActivity;
import android.support.v7.app.ActionBar;
import android.support.v4.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.*;
import android.os.Build;

public class MainActivity extends ActionBarActivity implements OnClickListener{

private Button pre,next;
private ImageView image;

private int[] images={R.drawable.a,R.drawable.b,R.drawable.c,R.drawable.d};
private int position=0;

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    pre=(Button)findViewById(R.id.pre);
    next=(Button)findViewById(R.id.next);

    pre.setOnClickListener(this);
    next.setOnClickListener(this);
}
public void onClick(View v) {
    switch(v.getId())
    {
    case R.id.pre:
        position--;
        if(position<0){
            position=images.length-1;
        }
        image.setImageResource(images[position]);
        break;

    case R.id.next:
        position++;
        if(position>=images.length){
            position=0;
        }
        image.setImageResource(images[position]);
        break;

    default:
        break;
    }
}

}

错误日志
09-21 23:31:45.082: E/AndroidRuntime(8051): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
09-21 23:31:45.082: E/AndroidRuntime(8051): at dalvik.system.NativeStart.main(Native Method)
09-21 23:31:45.082: E/AndroidRuntime(8051): Caused by: android.view.InflateException: Binary XML file line #28: Error inflating class null
09-21 23:31:45.082: E/AndroidRuntime(8051): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
09-21 23:31:45.082: E/AndroidRuntime(8051): at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
09-21 23:31:45.082: E/AndroidRuntime(8051): at android.view.LayoutInflater.rInflate(LayoutInflater.java:749)
09-21 23:31:45.082: E/AndroidRuntime(8051): at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
09-21 23:31:45.082: E/AndroidRuntime(8051): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
09-21 23:31:45.082: E/AndroidRuntime(8051): at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
09-21 23:31:45.082: E/AndroidRuntime(8051): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:270)
09-21 23:31:45.082: E/AndroidRuntime(8051): at android.app.Activity.setContentView(Activity.java:1881)
09-21 23:31:45.082: E/AndroidRuntime(8051): at android.support.v7.app.ActionBarActivity.superSetContentView(ActionBarActivity.java:216)
09-21 23:31:45.082: E/AndroidRuntime(8051): at android.support.v7.app.ActionBarActivityDelegateICS.setContentView(ActionBarActivityDelegateICS.java:111)
09-21 23:31:45.082: E/AndroidRuntime(8051): at android.support.v7.app.ActionBarActivity.setContentView(ActionBarActivity.java:76)
09-21 23:31:45.082: E/AndroidRuntime(8051): at com.example.testimage.MainActivity.onCreate(MainActivity.java:26)
09-21 23:31:45.082: E/AndroidRuntime(8051): at android.app.Activity.performCreate(Activity.java:5104)
09-21 23:31:45.082: E/AndroidRuntime(8051): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1092)
09-21 23:31:45.082: E/AndroidRuntime(8051): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2148)
09-21 23:31:45.082: E/AndroidRuntime(8051): ... 11 more
09-21 23:31:45.082: E/AndroidRuntime(8051): Caused by: java.lang.NullPointerException
09-21 23:31:45.082: E/AndroidRuntime(8051): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:684)
09-21 23:31:45.082: E/AndroidRuntime(8051): ... 25 more

7个回答

异常在这:Caused by: android.view.InflateException: Binary XML file line #28: Error inflating class null

检查你的xml文件的28行哪里有问题。目测是你的View标签里属性的设置有问题,view的标签应该是大写的V吧:View

android:text="上一张"
把字符串放到string.xml里

应该就是你布局文件的view写错了

nflateException: Binary XML file line #28: Error inflating class null
你的布局view初始化失败,view都是null空的,怎么会有视图呢,所以app打都不打不开

android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="1"
/>

            把这个view改成View

android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="1"
/>

改成大写的<View>
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐