0

Hey, j'essaie d'implémenter deux onglets. Chacun appelle une activité spécifique. Mais quand je tente d'exécuter je cette erreur:Erreur lors de l'exécution TabHost Android

12-07 20:26:22.164: ERROR/AndroidRuntime(363): FATAL EXCEPTION: main 
12-07 20:26:22.164: ERROR/AndroidRuntime(363): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.psyhclo/com.psyhclo.Main}: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.psyhclo/com.psyhclo.RatedCalls}: java.lang.SecurityException: Permission Denial: opening provider com.android.providers.contacts.CallLogProvider from ProcessRecord{405a8ac8 363:com.psyhclo/10030} (pid=363, uid=10030) requires android.permission.READ_CONTACTS or android.permission.WRITE_CONTACTS 
12-07 20:26:22.164: ERROR/AndroidRuntime(363):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1622) 
12-07 20:26:22.164: ERROR/AndroidRuntime(363):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1638) 
12-07 20:26:22.164: ERROR/AndroidRuntime(363):  at android.app.ActivityThread.access$1500(ActivityThread.java:117) 
12-07 20:26:22.164: ERROR/AndroidRuntime(363):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:928) 
12-07 20:26:22.164: ERROR/AndroidRuntime(363):  at android.os.Handler.dispatchMessage(Handler.java:99) 
12-07 20:26:22.164: ERROR/AndroidRuntime(363):  at android.os.Looper.loop(Looper.java:123) 
12-07 20:26:22.164: ERROR/AndroidRuntime(363):  at android.app.ActivityThread.main(ActivityThread.java:3647) 
12-07 20:26:22.164: ERROR/AndroidRuntime(363):  at java.lang.reflect.Method.invokeNative(Native Method) 
12-07 20:26:22.164: ERROR/AndroidRuntime(363):  at java.lang.reflect.Method.invoke(Method.java:507) 
12-07 20:26:22.164: ERROR/AndroidRuntime(363):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839) 
12-07 20:26:22.164: ERROR/AndroidRuntime(363):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597) 
12-07 20:26:22.164: ERROR/AndroidRuntime(363):  at dalvik.system.NativeStart.main(Native Method) 
12-07 20:26:22.164: ERROR/AndroidRuntime(363): Caused by: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.psyhclo/com.psyhclo.RatedCalls}: java.lang.SecurityException: Permission Denial: opening provider com.android.providers.contacts.CallLogProvider from ProcessRecord{405a8ac8 363:com.psyhclo/10030} (pid=363, uid=10030) requires android.permission.READ_CONTACTS or android.permission.WRITE_CONTACTS 
12-07 20:26:22.164: ERROR/AndroidRuntime(363):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1622) 
12-07 20:26:22.164: ERROR/AndroidRuntime(363):  at android.app.ActivityThread.startActivityNow(ActivityThread.java:1462) 
12-07 20:26:22.164: ERROR/AndroidRuntime(363):  at android.app.LocalActivityManager.moveToState(LocalActivityManager.java:127) 
12-07 20:26:22.164: ERROR/AndroidRuntime(363):  at android.app.LocalActivityManager.startActivity(LocalActivityManager.java:339) 
12-07 20:26:22.164: ERROR/AndroidRuntime(363):  at android.widget.TabHost$IntentContentStrategy.getContentView(TabHost.java:654) 
12-07 20:26:22.164: ERROR/AndroidRuntime(363):  at android.widget.TabHost.setCurrentTab(TabHost.java:326) 
12-07 20:26:22.164: ERROR/AndroidRuntime(363):  at android.widget.TabHost.addTab(TabHost.java:216) 
12-07 20:26:22.164: ERROR/AndroidRuntime(363):  at com.psyhclo.Main.onCreate(Main.java:17) 
12-07 20:26:22.164: ERROR/AndroidRuntime(363):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047) 
12-07 20:26:22.164: ERROR/AndroidRuntime(363):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1586) 
12-07 20:26:22.164: ERROR/AndroidRuntime(363):  ... 11 more 
12-07 20:26:22.164: ERROR/AndroidRuntime(363): Caused by: java.lang.SecurityException: Permission Denial: opening provider com.android.providers.contacts.CallLogProvider from ProcessRecord{405a8ac8 363:com.psyhclo/10030} (pid=363, uid=10030) requires android.permission.READ_CONTACTS or android.permission.WRITE_CONTACTS 
12-07 20:26:22.164: ERROR/AndroidRuntime(363):  at android.os.Parcel.readException(Parcel.java:1322) 
12-07 20:26:22.164: ERROR/AndroidRuntime(363):  at android.os.Parcel.readException(Parcel.java:1276) 
12-07 20:26:22.164: ERROR/AndroidRuntime(363):  at android.app.ActivityManagerProxy.getContentProvider(ActivityManagerNative.java:1882) 
12-07 20:26:22.164: ERROR/AndroidRuntime(363):  at android.app.ActivityThread.getProvider(ActivityThread.java:3311) 
12-07 20:26:22.164: ERROR/AndroidRuntime(363):  at android.app.ActivityThread.acquireProvider(ActivityThread.java:3336) 
12-07 20:26:22.164: ERROR/AndroidRuntime(363):  at android.app.ContextImpl$ApplicationContentResolver.acquireProvider(ContextImpl.java:1634) 
12-07 20:26:22.164: ERROR/AndroidRuntime(363):  at android.content.ContentResolver.acquireProvider(ContentResolver.java:748) 
12-07 20:26:22.164: ERROR/AndroidRuntime(363):  at android.content.ContentResolver.query(ContentResolver.java:256) 
12-07 20:26:22.164: ERROR/AndroidRuntime(363):  at com.psyhclo.RatedCalls.onCreate(RatedCalls.java:27) 
12-07 20:26:22.164: ERROR/AndroidRuntime(363):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047) 
12-07 20:26:22.164: ERROR/AndroidRuntime(363):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1586) 
12-07 20:26:22.164: ERROR/AndroidRuntime(363):  ... 20 more 

Voici le Main.java

import android.app.TabActivity; 
import android.content.Intent; 
import android.os.Bundle; 
import android.widget.TabHost; 

public class Main extends TabActivity { 

@Override 
public void onCreate(Bundle savedInstanceState) { 

    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main); 

    TabHost tabHost = getTabHost(); 
    tabHost.addTab(tabHost.newTabSpec("one").setIndicator("Rated Calls") 
      .setContent(new Intent(this, RatedCalls.class))); 
    tabHost.addTab(tabHost.newTabSpec("two").setIndicator("Rated Contacts") 
      .setContent(new Intent(this, SMS.class))); 

    tabHost.setCurrentTab(2); 

} 

    } 

Voici le RatedCalls.java classe

import java.text.DateFormat; 
import java.util.ArrayList; 

import com.psyhclo.R; 

import android.app.Activity; 
import android.database.Cursor; 
import android.os.Bundle; 
import android.widget.TextView; 
import android.widget.Toast; 

public class RatedCalls extends Activity { 

private static TextView txtView; 
private CallDataHelper dh; 
StringBuilder sb = new StringBuilder(); 

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

    setContentView(R.layout.ratedcalls);   

    //txtView = (TextView) findViewById(R.id.TextView01); 
    TextView txtView = new TextView(this); 
    Cursor cursor = getContentResolver().query(
      android.provider.CallLog.Calls.CONTENT_URI, null, null, null, 
      android.provider.CallLog.Calls.DATE + " DESC "); 

    startManagingCursor(cursor); 
    int numberColumnId = cursor 
      .getColumnIndex(android.provider.CallLog.Calls.NUMBER); 
    int durationId = cursor 
      .getColumnIndex(android.provider.CallLog.Calls.DURATION); 
    int contactNameId = cursor 
      .getColumnIndex(android.provider.CallLog.Calls.CACHED_NAME); 
    int dateId = cursor.getColumnIndex(android.provider.CallLog.Calls.DATE); 
    int numTypeId = cursor.getColumnIndex(android.provider.CallLog.Calls.CACHED_NUMBER_TYPE); 

    ArrayList<String> callList = new ArrayList<String>(); 
    if (cursor.moveToFirst()) { 
     do { 

      String callerPhoneNumber = cursor.getString(numberColumnId); 
      String contactName = cursor.getString(contactNameId); 
      String duration = cursor.getString(durationId); 
      String callDate = DateFormat.getDateInstance().format(dateId);  
      String numType = cursor.getString(numTypeId); 

      //this.dh.insert(1, contactName, callerPhoneNumber, numType, duration, callDate, "01:20"); 
      Toast.makeText(getBaseContext(), "Inserted!", Toast.LENGTH_LONG); 
      callList.add("\nNew Info: \nContact Number: " 
        + callerPhoneNumber + "\nContact Name: " + contactName 
        + "\nDuration: " + duration + "\nDate: " + callDate); 

     } while (cursor.moveToNext()); 
    } 
    txtView.setText(callList.toString()); 
} 
    } 

Et voici le ratedcalls.xml

<?xml version="1.0" encoding="utf-8"?> 
<TabHost xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@android:id/tabhost" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent"> 
<LinearLayout 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:padding="5dp"> 
    <TabWidget 
     android:id="@android:id/tabs" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" /> 
    <FrameLayout 
     android:id="@android:id/tabcontent" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:padding="5dp" /> 
</LinearLayout> 
</TabHost> 

Et voici le main.xml

<?xml version="1.0" encoding="utf-8"?> 
<TabHost xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@android:id/tabhost" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent"> 
<LinearLayout 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:padding="5dp"> 
    <TabWidget 
     android:id="@android:id/tabs" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" /> 
    <FrameLayout 
     android:id="@android:id/tabcontent" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:padding="5dp" /> 
</LinearLayout> 
</TabHost> 
+0

Sur la base de cette pile, le problème ne se trouve réellement dans aucun de ces fichiers. Vérifiez votre fichier AndroidManifest.xml et assurez-vous que vous disposez des autorisations appropriées (http://developer.android.com/guide/topics/manifest/manifest-intro.html#perms) pour accéder aux contacts. Si vous avez encore besoin d'aide, je vous recommande de poster la source de votre fichier AndroidManifest.xml. – eldarerathis

+0

-1 pour ne pas avoir lu l'erreur – Falmarri

Répondre

2

Le journal indique clairement le problème:

SecurityException: Permission Denial: opening provider 
com.android.providers.contacts.CallLogProvider requires 
android.permission.READ_CONTACTS or android.permission.WRITE_CONTACTS 

Vérifiez vos autorisations dans votre fichier manifeste.

+0

Cette erreur ne se produit pas. Je l'ai changé, et mis les bonnes permissions. J'ai ajouté: \t rogcg

+0

Toujours la même trace de la pile? Avez-vous ajouté les autorisations au bon endroit? – EboMike

+0

Les autorisations vont dans la balise manifeste, pas dans la balise d'application. BTW, il est préférable de modifier votre question et ajouter des informations, plutôt que d'ajouter une réponse. – EboMike