2012-09-05 3 views
0

내 애플리케이션에서 TabView를 만들고 AsyncTask를 사용하여 JSON 데이터를로드하고 있습니다. onTabChangedListner()를 사용하여 AsyncTask가 실행되는 perticular 탭을 클릭 할 때 JSON 데이터가로드됩니다. 그 Perticular 탭을 클릭하면 NullPointerException으로 끝나지 만, 내 응용 프로그램이 NullPointerException을 얻는 곳을 파악할 수 없습니다.TabActivity의 AsyncTask에서 Json 데이터로드 중 오류

The following is the code of TabGroups Class:

public class TabGroups extends ActivityGroup { 

ArrayList<String> list; 
Window window; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    // TODO Auto-generated method stub 
    super.onCreate(savedInstanceState); 
    if(list == null) 
     list = new ArrayList<String>(); 
} 

@Override 
public void finishFromChild(Activity child) 
{ 
    LocalActivityManager manager = getLocalActivityManager(); 
    int index = list.size() -1; 
    if(index < 1) 
    { 
     finish(); 
     return; 
    } 
    manager.destroyActivity(list.get(index), true); 
    list.remove(index); 
    index--; 
    String lastId = list.get(index); 
    Intent in = manager.getActivity(lastId).getIntent(); 
    window = manager.startActivity(lastId, in); 
    setContentView(window.getDecorView()); 
} 

public void startChildActivity(String Id, Intent intent) 
{ 
    window = getLocalActivityManager().startActivity(Id, intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)); 
    if(window != null) 
    { 
     list.add(Id); 
     setContentView(window.getDecorView()); 
    } 
} 

@Override 
public boolean onKeyDown(int keyCode, KeyEvent event) 
{ 
    if(keyCode == KeyEvent.KEYCODE_BACK) 
     return true; 
    return super.onKeyDown(keyCode, event); 
} 

@Override 
public boolean onKeyUp(int keyCode, KeyEvent event) 
{ 
    if(keyCode == KeyEvent.KEYCODE_BACK) 
    { 
     onBackPressed(); 
     return true; 
    } 
    return super.onKeyUp(keyCode, event); 
} 

@Override 
public void onBackPressed() 
{ 
    int length = list.size(); 
    if(length > 1) 
    { 
     Activity current = getLocalActivityManager().getActivity(list.get(length - 1)); 
     current.finish(); 
    } 
} 
} 

The following is the code of TabView Class:

public class TabView extends TabActivity implements OnTabChangeListener { 

private static TabHost tabHost; 
@Override 
protected void onCreate(Bundle savedInstanceState) { 
    // TODO Auto-generated method stub 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.tabview); 
    tabHost = getTabHost(); 
    tabHost.addTab(tabHost.newTabSpec("home").setIndicator("Home").setContent(new Intent(this, TabGroup1.class))); 
    tabHost.addTab(tabHost.newTabSpec("top5").setIndicator("My Top5").setContent(new Intent(this, TabGroup2.class))); 
    tabHost.addTab(tabHost.newTabSpec("resv").setIndicator("My Reservation").setContent(new Intent(this, TabGroup3.class))); 
    tabHost.addTab(tabHost.newTabSpec("srch").setIndicator("Search").setContent(new Intent(this, TabGroup4.class))); 
    tabHost.addTab(tabHost.newTabSpec("prfl").setIndicator("Profile").setContent(new Intent(this, TabGroup5.class))); 
    tabHost.setCurrentTab(0); 
    tabHost.setOnTabChangedListener(this); 
} 
public void onTabChanged(String tabId) { 
    // TODO Auto-generated method stub 
    Log.v("tag", String.valueOf(tabId)); 
    if(tabId.equals("home")) 
     new LoadingScreen(this).execute("login"); 
} 
} 

The following is the code of TabGroup1 Class

public class TabGroup1 extends TabGroups { 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    // TODO Auto-generated method stub 
    super.onCreate(savedInstanceState); 
    startChildActivity("Home", new Intent(this, Home.class)); 
} 
} 

The following is the code of LoadingScreen Class:

,994 JsonParser 다른 응용 프로그램에 있지만,이 응용 프로그램에서 잘 woring되어

홈 클래스 만에서 onCreate를 (포함) 및 아무것도

The Errors that I am getting are:

를 작동하지 않는 그 9,903,210

The following is the code of JsonParser:

public class JsonParser { 

static InputStream is; 
static JSONObject jObj; 
static String json = null; 

public JSONObject getJSONfromUrl(String url) 
{ 
    try 
    { 
     DefaultHttpClient httpClient = new DefaultHttpClient(); 
     HttpGet httpGet = new HttpGet(url); 
     HttpResponse httpResponse = httpClient.execute(httpGet); 
     HttpEntity httpEntity = httpResponse.getEntity(); 
     is = httpEntity.getContent(); 
    } 
    catch(UnsupportedEncodingException e) 
    { 
     e.printStackTrace(); 
    } 
    catch(ClientProtocolException e) 
    { 
     e.printStackTrace(); 
    } 
    catch(IOException e) 
    { 
     e.printStackTrace(); 
    } 

    try 
    { 
     BufferedReader reader = new BufferedReader(new InputStreamReader(is)); 
     StringBuilder sb = new StringBuilder(); 
     String line = null; 
     while((line = reader.readLine()) != null) 
     { 
      sb.append(line + "\n"); 
     } 
     is.close(); 
     json = sb.toString(); 
    } 
    catch(Exception e) 
    { 
     e.printStackTrace(); 
    } 

    try 
    { 
     jObj = new JSONObject(json); 
    } 
    catch(JSONException e) 
    { 
     e.printStackTrace(); 
    } 
    return jObj; 
} 
} 

08-29 08:21:39.021: E/AndroidRuntime(4156): FATAL EXCEPTION: AsyncTask #1 08-29 08:21:39.021: E/AndroidRuntime(4156): java.lang.RuntimeException: An error occured while executing doInBackground() 08-29 08:21:39.021: E/AndroidRuntime(4156): at android.os.AsyncTask$3.done(AsyncTask.java:200) 08-29 08:21:39.021: E/AndroidRuntime(4156): at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273) 08-29 08:21:39.021: E/AndroidRuntime(4156): at java.util.concurrent.FutureTask.setException(FutureTask.java:124) 08-29 08:21:39.021: E/AndroidRuntime(4156): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307) 08-29 08:21:39.021: E/AndroidRuntime(4156): at java.util.concurrent.FutureTask.run(FutureTask.java:137) 08-29 08:21:39.021: E/AndroidRuntime(4156): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1068) 08-29 08:21:39.021: E/AndroidRuntime(4156): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:561) 08-29 08:21:39.021: E/AndroidRuntime(4156): at java.lang.Thread.run(Thread.java:1096) 08-29 08:21:39.021: E/AndroidRuntime(4156): Caused by: java.lang.NullPointerException 08-29 08:21:39.021: E/AndroidRuntime(4156): at org.json.JSONTokener.nextCleanInternal(JSONTokener.java:112) 08-29 08:21:39.021: E/AndroidRuntime(4156): at org.json.JSONTokener.nextValue(JSONTokener.java:90) 08-29 08:21:39.021: E/AndroidRuntime(4156): at org.json.JSONObject.<init>(JSONObject.java:154) 08-29 08:21:39.021: E/AndroidRuntime(4156): at org.json.JSONObject.<init>(JSONObject.java:171) 08-29 08:21:39.021: E/AndroidRuntime(4156): at com.pnf.gogolf.JsonParser.getJSONfromUrl(JsonParser.java:65) 08-29 08:21:39.021: E/AndroidRuntime(4156): at com.pnf.gogolf.LoadingScreen.doInBackground(LoadingScreen.java:48) 08-29 08:21:39.021: E/AndroidRuntime(4156): at com.pnf.gogolf.LoadingScreen.doInBackground(LoadingScreen.java:1) 08-29 08:21:39.021: E/AndroidRuntime(4156): at android.os.AsyncTask$2.call(AsyncTask.java:185) 08-29 08:21:39.021: E/AndroidRuntime(4156): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305) 08-29 08:21:39.021: E/AndroidRuntime(4156): ... 4 more 08-29 08:21:40.052: E/WindowManager(4156): Activity com.pnf.gogolf.TabView has leaked window [email protected] that was originally added here 08-29 08:21:40.052: E/WindowManager(4156): android.view.WindowLeaked: Activity com.pnf.gogolf.TabView has leaked window [email protected] that was originally added here 08-29 08:21:40.052: E/WindowManager(4156): at android.view.ViewRoot.<init>(ViewRoot.java:247) 08-29 08:21:40.052: E/WindowManager(4156): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:148) 08-29 08:21:40.052: E/WindowManager(4156): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91) 08-29 08:21:40.052: E/WindowManager(4156): at android.view.Window$LocalWindowManager.addView(Window.java:424) 08-29 08:21:40.052: E/WindowManager(4156): at android.app.Dialog.show(Dialog.java:241) 08-29 08:21:40.052: E/WindowManager(4156): at com.pnf.gogolf.LoadingScreen.onPreExecute(LoadingScreen.java:37) 08-29 08:21:40.052: E/WindowManager(4156): at android.os.AsyncTask.execute(AsyncTask.java:391) 08-29 08:21:40.052: E/WindowManager(4156): at com.pnf.gogolf.TabView.onTabChanged(TabView.java:34) 08-29 08:21:40.052: E/WindowManager(4156): at android.widget.TabHost.invokeOnTabChangeListener(TabHost.java:356) 08-29 08:21:40.052: E/WindowManager(4156): at android.widget.TabHost.setCurrentTab(TabHost.java:341) 08-29 08:21:40.052: E/WindowManager(4156): at android.widget.TabHost$2.onTabSelectionChanged(TabHost.java:129) 08-29 08:21:40.052: E/WindowManager(4156): at android.widget.TabWidget$TabClickListener.onClick(TabWidget.java:453) 08-29 08:21:40.052: E/WindowManager(4156): at android.view.View.performClick(View.java:2408) 08-29 08:21:40.052: E/WindowManager(4156): at android.view.View$PerformClick.run(View.java:8816) 08-29 08:21:40.052: E/WindowManager(4156): at android.os.Handler.handleCallback(Handler.java:587) 08-29 08:21:40.052: E/WindowManager(4156): at android.os.Handler.dispatchMessage(Handler.java:92) 08-29 08:21:40.052: E/WindowManager(4156): at android.os.Looper.loop(Looper.java:123) 08-29 08:21:40.052: E/WindowManager(4156): at android.app.ActivityThread.main(ActivityThread.java:4627) 08-29 08:21:40.052: E/WindowManager(4156): at java.lang.reflect.Method.invokeNative(Native Method) 08-29 08:21:40.052: E/WindowManager(4156): at java.lang.reflect.Method.invoke(Method.java:521) 08-29 08:21:40.052: E/WindowManager(4156): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868) 08-29 08:21:40.052: E/WindowManager(4156): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626) 08-29 08:21:40.052: E/WindowManager(4156): at dalvik.system.NativeStart.main(Native Method) 

탭을 사용하여 신청서를 다시 디자인해야하므로 도와주세요 ..

미리 감사드립니다.

답변

0

Stacktrace에서 LoadingScreen 클래스의 doInBackground 메서드에서 NullPointerException 예외가 발생합니다. 내 댓글에 아래 doInBackground의 코드를 참조하십시오

@Override 
protected String doInBackground(String... data) { 
// TODO Auto-generated method stub 
rqst = data[0]; 
if(rqst.equals("login")) 
{ 
    String url = "http://mygogolfteetime.com/iphone/login/[email protected]/123456"; 
    JsonParser jParser = new JsonParser(); 
    // error could be here, json object is null 
    JSONObject json = jParser.getJSONfromUrl(url); 
    try 
    { 
     message = json.getString(TAG_MESAG); 
    } 
    catch(JSONException e) 
    { 
     Log.v("Log", String.valueOf(e)); 
    } 
} 
return null; 

}

0

난 당신이 진행 막대에 잘못된 컨텍스트를 전달하는 것 같아요.

progress = new ProgressBar(getParent()); 

이 그것을 시도하고 무슨 일이 생긴 것을 볼 등의 ProgressBar를 정의하십시오.