Bundle sorunum, bakarmısınız?
Merhaba, burada yeniyim. Yaklaşık 1 aydır android projem üzerinde çalışıyorum. Her şeyi hazır ama işlevlerde sorun çıkıyor.
Sorun tam olarak şu; Bir sayfada textview'ler var. Bu textview'leri string'e atadım. Sayfadaki tuşa basarak listview'e gidiyor. Maddelerin her birinde bundle var, bundle'lar önceki sayfadaki textview'in yazısına farklı bir string ataması gerekiyor. Ama program tam burada budle'ları iletirken hata veriyor ve durduruluyor.
En başta anlattığım sayfanın kodu;
package com.monsterdroid.howtoloseweight;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
public class ekranbir extends Activity{
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.ekran1);Button button1=(Button) findViewById(R.id.button1);
Button button2=(Button) findViewById(R.id.button);
final TextView baslik = (TextView) findViewById(R.id.baslik);
final TextView madde = (TextView) findViewById(R.id.madde);
final TextView icerik = (TextView) findViewById(R.id.icerik);
Bundle veribaslik = getIntent().getExtras();
String baslikveri = veribaslik.getString("baslikveri");
baslik.setText(baslikveri);
Bundle verimadde = getIntent().getExtras();
String maddeveri = verimadde.getString("maddeveri");
madde.setText(maddeveri);
Bundle veriicerik = getIntent().getExtras();
String icerikveri = veriicerik.getString("icerikveri");
icerik.setText(icerikveri);
button1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivity(new Intent("com.monsterdroid.howtoloseweight.ANASAYFA"));
}
});
button2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivity(new Intent("com.monsterdroid.howtoloseweight.MAINACTIVITY"));
}
});
}public boolean onCreateOptionsMenu (Menu menu){
super.onCreateOptionsMenu(menu);
MenuInflater menutanim = getMenuInflater();
menutanim.inflate(R.menu.menu, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// TODO Auto-generated method stub
switch (item.getItemId()){
case R.id.home:
startActivity (new Intent("com.monsterdroid.howtoloseweight.ANASAYFA"));
return true;
case R.id.about:
startActivity (new Intent("com.monsterdroid.howtoloseweight.ABOUUT"));
return true;
case R.id.list:
startActivity (new Intent("com.monsterdroid.howtoloseweight.EKRANBIIR"));
return true;
}
return false;}
}
Bu da listview sayfasının kodu;
package com.monsterdroid.howtoloseweight;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ExpandableListView;
import android.widget.ExpandableListView.OnChildClickListener;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;public class MainActivity extends Activity {
private static List<Country> Countries;
private ExpandableListView expandableListView;
private CountryAdapter adapter;@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);LoadCountries();
expandableListView = (ExpandableListView) findViewById(R.id.expandableListView1);
adapter = new CountryAdapter(this, Countries);
expandableListView.setAdapter(adapter);
final Bundle bundle = new Bundle();
final Intent intent = new Intent("com.monsterdroid.howtoloseweight.EKRANBIIR");
expandableListView.setOnChildClickListener(new OnChildClickListener(){
@Override
public boolean onChildClick(ExpandableListView parent, View v,
int groupPosition, int childPosition, long id) {
// TODO Auto-generated method stub
if (groupPosition==0){
if (childPosition==0){
bundle.putString("baslikveri",getString(R.string.bas1));
bundle.putString("maddeveri",getString(R.string.mad1));
bundle.putString("icerikveri",getString(R.string.ic1));
}
if(childPosition==1)
{
bundle.putString("baslikveri",getString(R.string.bas2));
bundle.putString("maddeveri",getString(R.string.mad2));
bundle.putString("icerikveri",getString(R.string.ic2));
}
if(childPosition==2)
{
bundle.putString("baslikveri",getString(R.string.bas3));
bundle.putString("maddeveri",getString(R.string.mad3));
bundle.putString("icerikveri",getString(R.string.ic3));
}
if(childPosition==3)
{
bundle.putString("baslikveri",getString(R.string.bas4));
bundle.putString("maddeveri",getString(R.string.mad4));
bundle.putString("icerikveri",getString(R.string.ic4));
}
}
if (groupPosition==1){
if(childPosition==4)
{
bundle.putString("baslikveri",getString(R.string.bas5));
bundle.putString("maddeveri",getString(R.string.mad5));
bundle.putString("icerikveri",getString(R.string.ic5));
}
if(childPosition==5)
{
bundle.putString("baslikveri",getString(R.string.bas6));
bundle.putString("maddeveri",getString(R.string.mad6));
bundle.putString("icerikveri",getString(R.string.ic6));
}
if(childPosition==6)
{
bundle.putString("baslikveri",getString(R.string.bas7));
bundle.putString("maddeveri",getString(R.string.mad7));
bundle.putString("icerikveri",getString(R.string.ic7));
}
if(childPosition==7)
{
bundle.putString("baslikveri",getString(R.string.bas8));
bundle.putString("maddeveri",getString(R.string.mad8));
bundle.putString("icerikveri",getString(R.string.ic8));
}
if(childPosition==8)
{
bundle.putString("baslikveri",getString(R.string.bas9));
bundle.putString("maddeveri",getString(R.string.mad9));
bundle.putString("icerikveri",getString(R.string.ic9));
}
if(childPosition==9)
{
bundle.putString("baslikveri",getString(R.string.bas10));
bundle.putString("maddeveri",getString(R.string.mad10));
bundle.putString("icerikveri",getString(R.string.ic10));
}
}
if (groupPosition==2){
if(childPosition==10)
{
bundle.putString("baslikveri",getString(R.string.bas11));
bundle.putString("maddeveri",getString(R.string.mad11));
bundle.putString("icerikveri",getString(R.string.ic11));
}
if(childPosition==11)
{
bundle.putString("baslikveri",getString(R.string.bas12));
bundle.putString("maddeveri",getString(R.string.mad12));
bundle.putString("icerikveri",getString(R.string.ic12));
}
if(childPosition==12)
{
bundle.putString("baslikveri",getString(R.string.bas13));
bundle.putString("maddeveri",getString(R.string.mad13));
bundle.putString("icerikveri",getString(R.string.ic13));
}
}
if (groupPosition==3){
if(childPosition==13)
{
bundle.putString("baslikveri",getString(R.string.bas14));
bundle.putString("maddeveri",getString(R.string.mad14));
bundle.putString("icerikveri",getString(R.string.ic14));
}
if(childPosition==14)
{
bundle.putString("baslikveri",getString(R.string.bas15));
bundle.putString("maddeveri",getString(R.string.mad15));
bundle.putString("icerikveri",getString(R.string.ic15));
}
if(childPosition==15)
{
bundle.putString("baslikveri",getString(R.string.bas16));
bundle.putString("maddeveri",getString(R.string.mad16));
bundle.putString("icerikveri",getString(R.string.ic16));
}
if(childPosition==16)
{
bundle.putString("baslikveri",getString(R.string.bas17));
bundle.putString("maddeveri",getString(R.string.mad17));
bundle.putString("icerikveri",getString(R.string.ic17));
}
}
if (groupPosition==4){
if(childPosition==17)
{
bundle.putString("baslikveri",getString(R.string.bas18));
bundle.putString("maddeveri",getString(R.string.mad18));
bundle.putString("icerikveri",getString(R.string.ic18));
}
if(childPosition==18)
{
bundle.putString("baslikveri",getString(R.string.bas19));
bundle.putString("maddeveri",getString(R.string.mad19));
bundle.putString("icerikveri",getString(R.string.ic19));
}
if(childPosition==19)
{
bundle.putString("baslikveri",getString(R.string.bas20));
bundle.putString("maddeveri",getString(R.string.mad20));
bundle.putString("icerikveri",getString(R.string.ic20));
}
if(childPosition==20)
{
bundle.putString("baslikveri",getString(R.string.bas21));
bundle.putString("maddeveri",getString(R.string.mad21));
bundle.putString("icerikveri",getString(R.string.ic21));
}
if(childPosition==21)
{
bundle.putString("baslikveri",getString(R.string.bas22));
bundle.putString("maddeveri",getString(R.string.mad22));
bundle.putString("icerikveri",getString(R.string.ic22));
}
if(childPosition==22)
{
bundle.putString("baslikveri",getString(R.string.bas23));
bundle.putString("maddeveri",getString(R.string.mad23));
bundle.putString("icerikveri",getString(R.string.ic23));
}
}
if (groupPosition==5){
if(childPosition==23)
{
bundle.putString("baslikveri",getString(R.string.bas24));
bundle.putString("maddeveri",getString(R.string.mad24));
bundle.putString("icerikveri",getString(R.string.ic24));
}
if(childPosition==24)
{
bundle.putString("baslikveri",getString(R.string.bas25));
bundle.putString("maddeveri",getString(R.string.mad25));
bundle.putString("icerikveri",getString(R.string.ic25));
}
if(childPosition==25)
{
bundle.putString("baslikveri",getString(R.string.bas26));
bundle.putString("maddeveri",getString(R.string.mad26));
bundle.putString("icerikveri",getString(R.string.ic26));
}
if(childPosition==26)
{
bundle.putString("baslikveri",getString(R.string.bas27));
bundle.putString("maddeveri",getString(R.string.mad27));
bundle.putString("icerikveri",getString(R.string.ic27));
}
}
intent.putExtras(bundle);
startActivity(intent);
return false;
}
});
}
private void LoadCountries() {
Countries = new ArrayList<Country>();
ArrayList<String> liste1 = new ArrayList<String>(
Arrays.asList(getString(R.string.lis1),getString(R.string.lis2),getString(R.string.lis3),getString(R.string.lis4)));
Countries.add(new Country("Rules of Thumb", liste1));ArrayList<String> liste2 = new ArrayList<String>(
Arrays.asList(getString(R.string.lis5),getString(R.string.lis6),getString(R.string.lis7),getString(R.string.lis8),getString(R.string.lis9),getString(R.string.lis10)));
Countries.add(new Country("Low-Calorie Diet", liste2));ArrayList<String> liste3 = new ArrayList<String>(
Arrays.asList(getString(R.string.lis11),getString(R.string.lis12),getString(R.string.lis13)));
Countries.add(new Country("Low-Carb Diet", liste3));ArrayList<String> liste4 = new ArrayList<String>(
Arrays.asList(getString(R.string.lis14),getString(R.string.lis15),getString(R.string.lis16),getString(R.string.lis17)));
Countries.add(new Country("Other Diets", liste4));ArrayList<String> liste5 = new ArrayList<String>(
Arrays.asList(getString(R.string.lis18),getString(R.string.lis19),getString(R.string.lis20),getString(R.string.lis21),getString(R.string.lis22),getString(R.string.lis23)));
Countries.add(new Country("Burn Calories", liste5));
ArrayList<String> liste6 = new ArrayList<String>(
Arrays.asList(getString(R.string.lis24),getString(R.string.lis25),getString(R.string.lis26),getString(R.string.lis27)));
Countries.add(new Country("Stay Motivated", liste6));
}
}
LogCat'daki hata kodu;
12-13 18:12:35.323: E/Trace(691): error opening trace file: No such file or directory (2)
12-13 18:12:36.373: D/dalvikvm(691): GC_FOR_ALLOC freed 43K, 3% free 8013K/8259K, paused 114ms, total 119ms
12-13 18:12:36.383: I/dalvikvm-heap(691): Grow heap (frag case) to 8.435MB for 588816-byte allocation
12-13 18:12:36.533: D/dalvikvm(691): GC_CONCURRENT freed <1K, 3% free 8587K/8839K, paused 42ms+7ms, total 147ms
12-13 18:12:37.033: D/gralloc_goldfish(691): Emulator without GPU emulation detected.
12-13 18:12:40.923: D/dalvikvm(691): GC_FOR_ALLOC freed 4K, 3% free 8616K/8839K, paused 54ms, total 55ms
12-13 18:21:20.933: D/dalvikvm(691): GC_FOR_ALLOC freed 9K, 3% free 9028K/9223K, paused 62ms, total 72ms
12-13 18:21:21.008: I/dalvikvm-heap(691): Grow heap (frag case) to 9.731MB for 908616-byte allocation
12-13 18:21:21.322: D/dalvikvm(691): GC_CONCURRENT freed 593K, 8% free 9322K/10119K, paused 80ms+149ms, total 315ms
12-13 18:21:21.492: D/AndroidRuntime(691): Shutting down VM
12-13 18:21:21.492: W/dalvikvm(691): threadid=1: thread exiting with uncaught exception (group=0x40a13300)
12-13 18:21:21.622: E/AndroidRuntime(691): FATAL EXCEPTION: main
12-13 18:21:21.622: E/AndroidRuntime(691): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.monsterdroid.howtoloseweight/com.monsterdroid.howtoloseweight.ekranbir}: java.lang.NullPointerException
12-13 18:21:21.622: E/AndroidRuntime(691): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
12-13 18:21:21.622: E/AndroidRuntime(691): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
12-13 18:21:21.622: E/AndroidRuntime(691): at android.app.ActivityThread.access$600(ActivityThread.java:130)
12-13 18:21:21.622: E/AndroidRuntime(691): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
12-13 18:21:21.622: E/AndroidRuntime(691): at android.os.Handler.dispatchMessage(Handler.java:99)
12-13 18:21:21.622: E/AndroidRuntime(691): at android.os.Looper.loop(Looper.java:137)
12-13 18:21:21.622: E/AndroidRuntime(691): at android.app.ActivityThread.main(ActivityThread.java:4745)
12-13 18:21:21.622: E/AndroidRuntime(691): at java.lang.reflect.Method.invokeNative(Native Method)
12-13 18:21:21.622: E/AndroidRuntime(691): at java.lang.reflect.Method.invoke(Method.java:511)
12-13 18:21:21.622: E/AndroidRuntime(691): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
12-13 18:21:21.622: E/AndroidRuntime(691): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
12-13 18:21:21.622: E/AndroidRuntime(691): at dalvik.system.NativeStart.main(Native Method)
12-13 18:21:21.622: E/AndroidRuntime(691): Caused by: java.lang.NullPointerException
12-13 18:21:21.622: E/AndroidRuntime(691): at com.monsterdroid.howtoloseweight.ekranbir.onCreate(ekranbir.java:27)
12-13 18:21:21.622: E/AndroidRuntime(691): at android.app.Activity.performCreate(Activity.java:5008)
12-13 18:21:21.622: E/AndroidRuntime(691): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
12-13 18:21:21.622: E/AndroidRuntime(691): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
12-13 18:21:21.622: E/AndroidRuntime(691): ... 11 more
12-13 18:21:26.423: I/Process(691): Sending signal. PID: 691 SIG: 9
Yardım ederseniz çok teşekkür ederim, herkese iyi çalışmalar...