0

私はクイズのアプリケーションを作成しています。 ラジオボタンの内容のテキストと質問の説明のためのtextViewは正しく設定されていますが、ラジオボタンをクリックするとアプリケーションが強制終了します。コードを確認してください。これは私の活動... 輸入にjava.io.IOExceptionあるラジオボタンが機能しないとアプリケーションが強制終了する

<%@page contentType="text/html; charset=UTF-8"%> 
<%@page import="org.json.simple.JSONObject"%> 
<%@page import="java.util.*,java.sql.*"%> 

<%! 
Connection con; 
PreparedStatement ps; 
ResultSet rs; 
String x; 

%> 

<% 
Class.forName("oracle.jdbc.driver.OracleDriver"); 
con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl","pro","pro"); 
ps=con.prepareStatement("select * from c_question where id=1"); 
rs=ps.executeQuery(); 

JSONObject obj=new JSONObject(); 
obj.put("id",rs.getString(1)); 
obj.put("desc",rs.getString(2)); 
obj.put("a",rs.getString(3)); 
obj.put("b",rs.getString(4)); 
obj.put("c",rs.getString(5)); 
obj.put("d",rs.getString(6)); 
obj.put("ans",rs.getString(7)); 
out.print(obj); 
out.flush(); 
%> 

これは私のjspページで

行われる変更は..です。

import org.apache.http.HttpEntity; 
import org.apache.http.HttpResponse; 
import org.apache.http.client.ClientProtocolException; 
import org.apache.http.client.HttpClient; 
import org.apache.http.client.methods.HttpGet; 
import org.apache.http.impl.client.DefaultHttpClient; 
import org.apache.http.util.EntityUtils; 

import org.json.JSONException; 
import org.json.JSONObject; 

import android.app.Activity; 
import android.os.AsyncTask; 
import android.os.Bundle; 
import android.widget.RadioButton; 
import android.widget.RadioGroup; 
import android.widget.RadioGroup.OnCheckedChangeListener; 
import android.widget.TextView; 
import android.widget.Toast; 

public class JsonDemo extends Activity 
{ 
JSONObject json; 
HttpClient client; 
TextView q_desc,c_or_w,id_check; 
RadioButton rb_a,rb_b,rb_c,rb_d; 
RadioGroup rg; 
String ans; 
int id; 


final static String URL="http://10.0.2.2:7001/project/json.jsp"; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 

    // TODO Auto-generated method stub 

    super.onCreate(savedInstanceState); 

    setContentView(R.layout.result_json); 

    q_desc=(TextView)findViewById(R.id.q_desc); 
    c_or_w=(TextView)findViewById(R.id.corr_incorrect); 
    id_check=(TextView)findViewById(R.id.id_check); 
    rg=(RadioGroup)findViewById(R.id.rg_option); 
    rb_a=(RadioButton)findViewById(R.id.opt_a); 
    rb_b=(RadioButton)findViewById(R.id.opt_b); 
    rb_c=(RadioButton)findViewById(R.id.opt_c); 
    rb_d=(RadioButton)findViewById(R.id.opt_d); 

    client=new DefaultHttpClient(); 


    new Read().execute("desc"); 

} 
    public JSONObject getData()throws ClientProtocolException,IOException,JSONException 
    { 

    StringBuilder url=new StringBuilder(URL); 
    HttpGet get=new HttpGet(url.toString()); 
    HttpResponse r=client.execute(get); 



    int status=r.getStatusLine().getStatusCode(); 

    if(status == 200) 
    { 
     HttpEntity e=r.getEntity(); 
     String data=EntityUtils.toString(e); 
     JSONObject last=new JSONObject(data); 
     return last; 

    } 
    else 
    { 
     Toast.makeText(JsonDemo.this, "error", Toast.LENGTH_SHORT); 
     return null; 
    } 

} 



public class Read extends AsyncTask<String,Integer,JSONObject> implements OnCheckedChangeListener 
{ 


@Override 
protected void onPostExecute(JSONObject result) { 
    // TODO Auto-generated method stub 
    try { 
     String desc=json.getString("desc"); 
     String option_a=json.getString("a"); 
     String option_b=json.getString("b"); 
     String option_c=json.getString("c"); 
     String option_d=json.getString("d"); 
     ans=json.getString("ans"); 
     q_desc.setText(desc); 
     rb_a.setText(option_a); 
     rb_b.setText(option_b); 
     rb_c.setText(option_c); 
     rb_d.setText(option_d); 
     rg.setOnCheckedChangeListener(this); 

    } catch (JSONException e) { 
     // TODO Auto-generated catch block 
     e.printStackTrace(); 
    } 
} 

@Override 
protected JSONObject doInBackground(String... params) { 
    try { 
     json=getData(); 
     return json; 
    } catch (ClientProtocolException e) { 
     // TODO Auto-generated catch block 
     e.printStackTrace(); 
    } catch (IOException e) { 
     // TODO Auto-generated catch block 
     e.printStackTrace(); 
    } catch (JSONException e) { 
     // TODO Auto-generated catch block 
     e.printStackTrace(); 
    } 
    return null; 
} 

public void onCheckedChanged(RadioGroup rg, int checkedId) { 

    switch(checkedId) 
    { 
    case R.id.opt_a: 
    { 
     if(ans.equalsIgnoreCase("a")) 
     { 

      id=id+1; 
      c_or_w.setText("Correct"); 
      id_check.setText(id);   
     } 
     else 
     { 
      id=id+1; 
      c_or_w.setText("InCorrect"); 
      id_check.setText(id); 

     } 
     break; 

    } 
    case R.id.opt_b: 
    { 
     if(ans.equalsIgnoreCase("b")) 
     { 

      id=id+1; 
      c_or_w.setText("Correct"); 
      id_check.setText(id);   
     } 
     else 
     { 
      id=id+1; 
      c_or_w.setText("InCorrect"); 
      id_check.setText(id); 

     } 
     break; 
    } 
    case R.id.opt_c: 
    { 
     if(ans.equalsIgnoreCase("c")) 
     { 

      id=id+1; 
      c_or_w.setText("Correct"); 
      id_check.setText(id);   
     } 
     else 
     { 
      id=id+1; 
      c_or_w.setText("InCorrect"); 
      id_check.setText(id); 

     } 
     break; 
    } 
    case R.id.opt_d: 
    { 
     if(ans.equalsIgnoreCase("d")) 
     { 

      id=id+1; 
      c_or_w.setText("Correct"); 
      id_check.setText(id);   
     } 
     else 
     { 
      id=id+1; 
      c_or_w.setText("InCorrect"); 
      id_check.setText(id); 

     } 
     break; 
    } 

    } 

} 


} 

} 

ログの猫...

04-06 09:48:10.849: W/ResourceType(354): No package identifier when getting value for resource number 0x00000001 
04-06 09:48:10.859: D/AndroidRuntime(354): Shutting down VM 
04-06 09:48:10.859: W/dalvikvm(354): threadid=1: thread exiting with uncaught exception (group=0x4001d800) 
04-06 09:48:10.889: E/AndroidRuntime(354): FATAL EXCEPTION: main 
04-06 09:48:10.889: E/AndroidRuntime(354): android.content.res.Resources$NotFoundException: String resource ID #0x1 
04-06 09:48:10.889: E/AndroidRuntime(354): at android.content.res.Resources.getText(Resources.java:201) 
04-06 09:48:10.889: E/AndroidRuntime(354): at android.widget.TextView.setText(TextView.java:2817) 
04-06 09:48:10.889: E/AndroidRuntime(354): at com.campuspro.start.JsonDemo.onCheckedChanged(JsonDemo.java:151) 
04-06 09:48:10.889: E/AndroidRuntime(354): at android.widget.RadioGroup.setCheckedId(RadioGroup.java:172) 
04-06 09:48:10.889: E/AndroidRuntime(354): at android.widget.RadioGroup.access$600(RadioGroup.java:52) 
04-06 09:48:10.889: E/AndroidRuntime(354): at android.widget.RadioGroup$CheckedStateTracker.onCheckedChanged(RadioGroup.java:342) 
04-06 09:48:10.889: E/AndroidRuntime(354): at android.widget.CompoundButton.setChecked(CompoundButton.java:127) 
04-06 09:48:10.889: E/AndroidRuntime(354): at android.widget.CompoundButton.toggle(CompoundButton.java:86) 
04-06 09:48:10.889: E/AndroidRuntime(354): at android.widget.RadioButton.toggle(RadioButton.java:69) 
04-06 09:48:10.889: E/AndroidRuntime(354): at android.widget.CompoundButton.performClick(CompoundButton.java:98) 
04-06 09:48:10.889: E/AndroidRuntime(354): at android.view.View$PerformClick.run(View.java:8816) 
04-06 09:48:10.889: E/AndroidRuntime(354): at android.os.Handler.handleCallback(Handler.java:587) 
04-06 09:48:10.889: E/AndroidRuntime(354): at android.os.Handler.dispatchMessage(Handler.java:92) 
04-06 09:48:10.889: E/AndroidRuntime(354): at android.os.Looper.loop(Looper.java:123) 
04-06 09:48:10.889: E/AndroidRuntime(354): at android.app.ActivityThread.main(ActivityThread.java:4627) 
04-06 09:48:10.889: E/AndroidRuntime(354): at java.lang.reflect.Method.invokeNative(Native Method) 
04-06 09:48:10.889: E/AndroidRuntime(354): at java.lang.reflect.Method.invoke(Method.java:521) 
04-06 09:48:10.889: E/AndroidRuntime(354): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868) 
04-06 09:48:10.889: E/AndroidRuntime(354): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626) 
04-06 09:48:10.889: E/AndroidRuntime(354): at dalvik.system.NativeStart.main(Native Method) 
04-06 09:48:13.419: I/Process(354): Sending signal. PID: 354 SIG: 9 
04-06 09:51:50.868: W/ResourceType(388): No package identifier when getting value for resource number 0x00000001 
04-06 09:51:50.868: D/AndroidRuntime(388): Shutting down VM 
04-06 09:51:50.879: W/dalvikvm(388): threadid=1: thread exiting with uncaught exception (group=0x4001d800) 
04-06 09:51:50.909: E/AndroidRuntime(388): FATAL EXCEPTION: main 
04-06 09:51:50.909: E/AndroidRuntime(388): android.content.res.Resources$NotFoundException: String resource ID #0x1 
04-06 09:51:50.909: E/AndroidRuntime(388): at android.content.res.Resources.getText(Resources.java:201) 
04-06 09:51:50.909: E/AndroidRuntime(388): at android.widget.TextView.setText(TextView.java:2817) 
04-06 09:51:50.909: E/AndroidRuntime(388): at com.campuspro.start.JsonDemo$Read.onCheckedChanged(JsonDemo.java:147) 
04-06 09:51:50.909: E/AndroidRuntime(388): at android.widget.RadioGroup.setCheckedId(RadioGroup.java:172) 
04-06 09:51:50.909: E/AndroidRuntime(388): at android.widget.RadioGroup.access$600(RadioGroup.java:52) 
04-06 09:51:50.909: E/AndroidRuntime(388): at android.widget.RadioGroup$CheckedStateTracker.onCheckedChanged(RadioGroup.java:342) 
04-06 09:51:50.909: E/AndroidRuntime(388): at android.widget.CompoundButton.setChecked(CompoundButton.java:127) 
04-06 09:51:50.909: E/AndroidRuntime(388): at android.widget.CompoundButton.toggle(CompoundButton.java:86) 
04-06 09:51:50.909: E/AndroidRuntime(388): at android.widget.RadioButton.toggle(RadioButton.java:69) 
04-06 09:51:50.909: E/AndroidRuntime(388): at android.widget.CompoundButton.performClick(CompoundButton.java:98) 
04-06 09:51:50.909: E/AndroidRuntime(388): at android.view.View$PerformClick.run(View.java:8816) 
04-06 09:51:50.909: E/AndroidRuntime(388): at android.os.Handler.handleCallback(Handler.java:587) 
04-06 09:51:50.909: E/AndroidRuntime(388): at android.os.Handler.dispatchMessage(Handler.java:92) 
04-06 09:51:50.909: E/AndroidRuntime(388): at android.os.Looper.loop(Looper.java:123) 
04-06 09:51:50.909: E/AndroidRuntime(388): at android.app.ActivityThread.main(ActivityThread.java:4627) 
04-06 09:51:50.909: E/AndroidRuntime(388): at java.lang.reflect.Method.invokeNative(Native Method) 
04-06 09:51:50.909: E/AndroidRuntime(388): at java.lang.reflect.Method.invoke(Method.java:521) 
04-06 09:51:50.909: E/AndroidRuntime(388): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868) 
04-06 09:51:50.909: E/AndroidRuntime(388): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626) 
04-06 09:51:50.909: E/AndroidRuntime(388): at dalvik.system.NativeStart.main(Native Method) 
04-06 10:08:07.398: W/ResourceType(399): No package identifier when getting value for resource number 0x00000001 
04-06 10:08:07.508: D/AndroidRuntime(399): Shutting down VM 
04-06 10:08:07.508: W/dalvikvm(399): threadid=1: thread exiting with uncaught exception (group=0x4001d800) 
04-06 10:08:07.618: E/AndroidRuntime(399): FATAL EXCEPTION: main 
04-06 10:08:07.618: E/AndroidRuntime(399): android.content.res.Resources$NotFoundException: String resource ID #0x1 
04-06 10:08:07.618: E/AndroidRuntime(399): at android.content.res.Resources.getText(Resources.java:201) 
04-06 10:08:07.618: E/AndroidRuntime(399): at android.widget.TextView.setText(TextView.java:2817) 
04-06 10:08:07.618: E/AndroidRuntime(399): at com.campuspro.start.JsonDemo$Read.onCheckedChanged(JsonDemo.java:147) 
04-06 10:08:07.618: E/AndroidRuntime(399): at android.widget.RadioGroup.setCheckedId(RadioGroup.java:172) 
04-06 10:08:07.618: E/AndroidRuntime(399): at android.widget.RadioGroup.access$600(RadioGroup.java:52) 
04-06 10:08:07.618: E/AndroidRuntime(399): at android.widget.RadioGroup$CheckedStateTracker.onCheckedChanged(RadioGroup.java:342) 
04-06 10:08:07.618: E/AndroidRuntime(399): at android.widget.CompoundButton.setChecked(CompoundButton.java:127) 
04-06 10:08:07.618: E/AndroidRuntime(399): at android.widget.CompoundButton.toggle(CompoundButton.java:86) 
04-06 10:08:07.618: E/AndroidRuntime(399): at android.widget.RadioButton.toggle(RadioButton.java:69) 
04-06 10:08:07.618: E/AndroidRuntime(399): at android.widget.CompoundButton.performClick(CompoundButton.java:98) 
04-06 10:08:07.618: E/AndroidRuntime(399): at android.view.View$PerformClick.run(View.java:8816) 
04-06 10:08:07.618: E/AndroidRuntime(399): at android.os.Handler.handleCallback(Handler.java:587) 
04-06 10:08:07.618: E/AndroidRuntime(399): at android.os.Handler.dispatchMessage(Handler.java:92) 
04-06 10:08:07.618: E/AndroidRuntime(399): at android.os.Looper.loop(Looper.java:123) 
04-06 10:08:07.618: E/AndroidRuntime(399): at android.app.ActivityThread.main(ActivityThread.java:4627) 
04-06 10:08:07.618: E/AndroidRuntime(399): at java.lang.reflect.Method.invokeNative(Native Method) 
04-06 10:08:07.618: E/AndroidRuntime(399): at java.lang.reflect.Method.invoke(Method.java:521) 
04-06 10:08:07.618: E/AndroidRuntime(399): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868) 
04-06 10:08:07.618: E/AndroidRuntime(399): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626) 
04-06 10:08:07.618: E/AndroidRuntime(399): at dalvik.system.NativeStart.main(Native Method) 
04-06 10:08:12.848: I/Process(399): Sending signal. PID: 399 SIG: 9 

答えて

2

のでString

id_check.setText(""+id);  

または

でそれを変換する....あなたは setText as a Stringに持っていて、 Integerとして設定
id_check.setText(Integer.toString(id)); 
+0

あなたはいつも正しいです... @ Samir – sagar

+0

しかし、どうしてこのような長いプログラムからのエラーを知ったのですか?あなたはエラーのログの猫をチェックするか?もしあれば、ログcatのどの行から私のエラーを知るようになったのですか? – sagar

+0

例外 'リソース$ NotFoundExceptionから:文字列リソースID#0x1 'とあなたのコードを参照してください...私はそれを得る... –

関連する問題