2012-12-07 12 views
0

나는 응용 프로그램에서 일하고 있으며 이상한 오류가 발생합니다. 로그인 버튼을 탭하고 새로운 활동이 시작될 때 앱을 테스트하기 위해 지금까지 사용 된 3 개의 기기 중 2 개가 완벽하게 작동합니다. 작동하는 두 대의 휴대 전화는 모두 Ice Cream Sandwhich와 제 3의 휴대 전화 (제게 문제를 일으키는 전화)에서 실행됩니다. JellyBean을 실행 중입니다.RuntimeException : 활동을 시작할 수 없습니다 (Android)

JellyBean 전화를 사용하여 로그인 버튼을 탭하면 이러한 현상이 발생합니다.

자바 (등록 페이지)

  // Register button 
      TextView main_body_register_button = new TextView(this); 
      main_body_register_button.setBackgroundResource(R.drawable.register_btn); 
      main_body_register_button.setOnClickListener(new View.OnClickListener() { 
        public void onClick(View v) { 
         // Post to the MySQL database 
         class sendtask extends AsyncTask<String, Void, String> { 
          protected String doInBackground(String... url) { 
           HttpClient httpClient = new DefaultHttpClient(); 
            HttpPost httpPost = new HttpPost("http://website.com/register.php"); 
             List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(); 
              nameValuePairs.add(new BasicNameValuePair("number", ""+main_body_phone_input.getText().toString())); 

              try { 
               httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs)); 
              } catch (UnsupportedEncodingException e) { 
               e.printStackTrace(); 
              } 
              try { 
               httpClient.execute(httpPost); 
              } catch (ClientProtocolException e) { 
               e.printStackTrace(); 
              } catch (IOException e) { 
               e.printStackTrace(); 
              } 
               return ""; 
          } 
           protected void onPostExecute(String result) { 
            if (main_body_phone_input.getText().toString().compareTo("012-345-6789")==0) { 
             // Phone number: Empty 
             Intent base_account_register = new Intent(base_account_register.this,base_account_register.class); 
             startActivity(base_account_register); 
            } else if (main_body_phone_input.getText().toString().compareTo("012-345-6789")!=0) { 
             // Switch to main page 
             Intent TellATextActivity = new Intent(base_account_register.this,TellATextActivity.class); 
             ownAddress = ""+main_body_phone_input.getText().toString(); 
             startActivity(TellATextActivity); 
            } 
           } 
         } 
          new sendtask().execute("Registration form"); 
         // End 
        } 
      }); 
      // END 

자바 (한 OnCreate TellATextActivity)

public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 

    // Global variables 
    Bundle bundle = getIntent().getExtras(); 
    final String ownAddress = bundle.getString("session_number"); 

     // MAIN 
     TextView main_message = new TextView(this); 
      // Select and parse the most recent message 
      Uri uriSMS = Uri.parse("content://sms/"); 
      Cursor cur = getContentResolver().query(uriSMS, null, null, null, null); 

      // EDIT IN   
      if (cur != null && cur.moveToFirst()) { 
      do { 
       // Inflate your data 
      } while (cur.moveToNext()); 
      } 
      cur.close() 
      // END 

      // EDIT OUT 
      cur.moveToNext(); 
      cur.moveToNext(); 
      // END 

      String body = cur.getString(cur.getColumnIndex("body")); 
      String add = cur.getString(cur.getColumnIndex("address")); 
      reply_address = "" +add; 
      String time = cur.getString(cur.getColumnIndex("date")); 
      String protocol = cur.getString(cur.getColumnIndex("protocol")); 
      String contactName = ""; 

      Uri personUri = Uri.withAppendedPath(ContactsContract.PhoneLookup.CONTENT_FILTER_URI, Uri.encode(add)); 
       Cursor c = getContentResolver().query(personUri, new String[] { PhoneLookup.DISPLAY_NAME }, null, null, null); 
        if(c.moveToFirst()) { 
         int nameIndex = c.getColumnIndex(PhoneLookup.DISPLAY_NAME); 
         contactName = c.getString(nameIndex); 
        } 
        c.close(); 
        cur.close(); 
      String out = ""; 
      Date d = new Date(Long.valueOf(time)); 
      // End 

      // Determine status of message 
      if (protocol == null) 
       out = ""+body; 
      else 
       out = ""+body; 
      // End 

      // Create output 
      main_message.setHeight(400); 
      main_message.setWidth(510); 
      main_message.setPadding(10,15,10,0); 
      main_message.setTextSize(23); 
      main_message.setTextColor(Color.rgb(100,100,100)); 
      main_message.setText(out); 
      // End 
     // END 

     TextView bottom_reply = new TextView(this); 
     bottom_reply.setBackgroundResource(R.drawable.reply); 
     bottom_reply.setOnClickListener(new View.OnClickListener() { 
      public void onClick(View v) { 
       // Compose a reply 
       Intent intent = new Intent(Intent.ACTION_SENDTO); 
       intent.setData(Uri.parse("smsto:" +reply_address)); 
       intent.putExtra("compose_mode", true); 
       startActivity(intent); 
      } 
     }); 
     // END 

    } 

의 AndroidManifest.xml

<activity 
     android:name=".TellATextActivity" 
     android:label="@string/app_name" 
     android:configChanges="orientation|keyboardHidden" 
     android:screenOrientation="portrait" > 
     <intent-filter> 
      <action android:name="android.intent.action.VIEW" /> 
      <category android:name="android.intent.category.DEFAULT" /> 
      <data android:mimeType="vnd.android-dir/mms-sms" /> 
     </intent-filter> 
     <intent-filter> 
      <action android:name="android.intent.action.VIEW" /> 
      <action android:name="android.intent.action.SENDTO" /> 
      <category android:name="android.intent.category.DEFAULT" /> 
      <category android:name="android.intent.category.BROWSABLE" /> 
      <data android:scheme="sms" /> 
      <data android:scheme="smsto" /> 
     </intent-filter> 
     <intent-filter> 
      <action android:name="android.intent.action.SEND" /> 
      <category android:name="android.intent.category.DEFAULT" /> 
      <data android:mimeType="text/plain" /> 
     </intent-filter> 
    </activity> 

충돌 보고서

java.lang.RuntimeException: Unable to start activity 
ComponentInfo{tellatext.sms.app/tellatext.sms.app.TellATextActivity}: 
android.database.CursorIndexOutOfBoundsException: Index 1 requested, with a size of 1 
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2049) 
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2083) 
at android.app.ActivityThread.access$600(ActivityThread.java:134) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1233) 
at android.os.Handler.dispatchMessage(Handler.java:99) 
at android.os.Looper.loop(Looper.java:137) 
at android.app.ActivityThread.main(ActivityThread.java:4697) 
at java.lang.reflect.Method.invokeNative(Native Method) 
at java.lang.reflect.Method.invoke(Method.java:511) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:790) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:557) 
at dalvik.system.NativeStart.main(Native Method) 
Caused by: android.database.CursorIndexOutOfBoundsException: Index 1 requested, with a size of 1 
at android.database.AbstractCursor.checkPosition(AbstractCursor.java:407) 
at android.database.AbstractWindowedCursor.checkPosition(AbstractWindowedCursor.java:136) 
at android.database.AbstractWindowedCursor.getString(AbstractWindowedCursor.java:50) 
at android.database.CursorWrapper.getString(CursorWrapper.java:114) 
at tellatext.sms.app.TellATextActivity.onCreate(TellATextActivity.java:82) 
at android.app.Activity.performCreate(Activity.java:4539) 
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049) 
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2013) 
... 11 more 

사람이 여기에 올바른 방향으로 날 지점 수 있을까? 나는 모든 옵션을 다 써 버렸고 그 문제에 대해 다른 사람의 관점을 필요로했습니다.

감사합니다.

+0

저는 성가 시게하고 싶지 않지만 클래스를 리스너로 정의하지 않으려합니다. (자바 스크립트가 아닙니다). 처음 엔 충돌이 났니? 디버깅을 시도 했습니까? –

+1

TelATextActivity 만들기에서 메소드 코드를 게시하십시오. 어떤 라인이 라인인지를 지정하십시오. – yDelouis

+0

"OnCreate TellATextActivity"에서 내 OnCreate 메소드를 확인하십시오. 방금 게시했습니다. 누구라도 왜이 오류가 발생하는지 설명 할 수 있습니까? – localhost

답변

0

누군가가 자신의받은 편지함에 3 개 미만의 문자 메시지로 앱을 사용하고있을 때 문제가 발생했습니다. 받은 편지함 커서를 텍스트 메시지가없는 지점으로 이동하면 해당 지점이 없기 때문에 응용 프로그램이 다운되는 경우가 있습니다.

1

코드에서 슬롯 1의 첫 번째 슬롯이라고 생각되는 커서 항목을 슬롯 1에서 요청하고 있습니다. 올바르지 않습니다. Cusors는 0으로 인덱싱되므로 0은 첫 번째 슬롯입니다. 0

편집 예에 개시 인덱스를 변경해보십시오 :

Cursor cur = null; // Your query not null 

if (cur != null && cur.moveToFirst()) { 
    do { 
     // Inflate your data 
    } while (cur.moveToNext()); 
} 
cur.close() 
+0

내 개정판을 살펴 보시겠습니까? OnCreate 메서드를 게시했습니다. 커서 인덱스를 어디에서 변경합니까? – localhost

+0

확실히 말할 수는 없지만'cur.moveToFirst()'를 순차적으로 두 번 호출하는 부분 일 것입니다. 'onCreate (Bundle)'메소드에서 13 행과 14 행. – AedonEtLIRA

+0

그게 문제라면 해결책이 있습니까? – localhost

0

그것은이 부분에 있지 않습니다. 실제로 onCreate 메서드입니다 (82 행). Aedon에서 제안한대로 1을 0으로 변경하면 모두 작동합니다.

관련 문제