我對這個錯誤非常抱歉。我希望有人能夠幫助我。 這是我的錯誤:Android中出現NullPOinterException錯誤,請幫忙
08-30 00:24:29.349: E/AndroidRuntime(2139): at android.view.ViewGroup.addView(ViewGroup.java:3318)
,這是我的代碼:
import android.os.Bundle;
import android.app.Activity;
import android.content.Context;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
public class MainActivity extends Activity {
ViewPager vPager;
private vpAdapter mAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
vPager=(ViewPager)findViewById(R.id.pager);
mAdapter = new vpAdapter();
vPager.setAdapter(mAdapter);
}
private class vpAdapter extends PagerAdapter{
@Override
public int getCount() {
// TODO Auto-generated method stub
return 4;
}
@Override
public boolean isViewFromObject(View view, Object object) {
// TODO Auto-generated method stub
return view==((LinearLayout)object);
}
@Override
public Object instantiateItem(ViewGroup container, int position) {
// TODO Auto-generated method stub
LayoutInflater inflater =(LayoutInflater)container.getContext()
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View v = null;
switch(position){
case 0:
inflater.inflate(R.layout.satu, null);
break;
case 1:
inflater.inflate(R.layout.dua, null);
break;
case 2:
inflater.inflate(R.layout.tiga, null);
break;
case 3:
inflater.inflate(R.layout.empat, null);
break;
}
((ViewPager)container).addView(v,0);
return true;
}
}
我已經嘗試了許多方法,但失敗了。如更改中斷的位置並更改位置視圖組。我忘了導入一個圖書館嗎?請幫助它的主人在這裏:) 如果有人能幫助我,我將非常感激。 謝謝之前:)
添加完整日誌跟蹤 –