这是我的错误,当我启动我的应用程序时,它崩溃了。我不明白错误的意思是:
02-04 13:45:36.588 7166-7166/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.erik_.tvmanager, PID: 7166
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.erik_.tvmanager/com.example.erik_.tvmanager.MainActivity}: info.movito.themoviedbapi.tools.MovieDbException: Failed to read configuration
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: info.movito.themoviedbapi.tools.MovieDbException: Failed to read configuration
at info.movito.themoviedbapi.TmdbApi.<init>(TmdbApi.java:48)
at info.movito.themoviedbapi.TmdbApi.<init>(TmdbApi.java:35)
at com.example.erik_.tvmanager.MainActivity.onCreate(MainActivity.java:40)
at android.app.Activity.performCreate(Activity.java:6237)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: java.lang.RuntimeException: value of parameter 'api_key' can not be empty
at info.movito.themoviedbapi.tools.ApiUrl.addParam(ApiUrl.java:100)
at info.movito.themoviedbapi.TmdbApi.requestWebPage(TmdbApi.java:57)
at info.movito.themoviedbapi.AbstractTmdbApi.mapJsonResult(AbstractTmdbApi.java:58)
at info.movito.themoviedbapi.AbstractTmdbApi.mapJsonResult(AbstractTmdbApi.java:45)
at info.movito.themoviedbapi.AbstractTmdbApi.mapJsonResult(AbstractTmdbApi.java:40)
at info.movito.themoviedbapi.TmdbConfig.getConfig(TmdbConfig.java:18)
at info.movito.themoviedbapi.TmdbApi.<init>(TmdbApi.java:44)
at info.movito.themoviedbapi.TmdbApi.<init>(TmdbApi.java:35)
at com.example.erik_.tvmanager.MainActivity.onCreate(MainActivity.java:40)
at android.app.Activity.performCreate(Activity.java:6237)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
这是我的傻瓜。我使用了一个库(编译组:'info.movito',名称:'themoviedbapi',版本:'1.1'),它基于api。
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "com.example.erik_.tvmanager"
minSdkVersion 21
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
packagingOptions {
exclude 'META-INF/NOTICE.txt' // will not include NOTICE file
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/LICENSE' // will not include LICENSE file
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:design:23.1.1'
compile group: 'info.movito', name: 'themoviedbapi', version:'1.1'
}
这是我的MainActivity,我想在TextView中设置文本。
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.TextView;
import org.w3c.dom.Text;
import info.movito.themoviedbapi.TmdbApi;
import info.movito.themoviedbapi.TmdbMovies;
import info.movito.themoviedbapi.model.MovieDb;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
}
});
TextView textView=(TextView) findViewById(R.id.prova);
String apiKey = System.getenv("MyapiKey");
TmdbApi tmdbApi = new TmdbApi(apiKey);
TmdbMovies movies = tmdbApi.getMovies();
MovieDb movie = movies.getMovie(5353, "en");
textView.setText(movie.getTitle());
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
答案 0 :(得分:0)
见这里:
java.lang.RuntimeException: value of parameter 'api_key' can not be empty
问题在于以下几行:
TmdbMovies movies = tmdbApi.getMovies();
确保String apiKey
不为空。
String apiKey = System.getenv("MyapiKey");
TmdbApi tmdbApi = new TmdbApi(apiKey);
我不知道System.getenv("Myapikey");
返回什么,但我很确定它什么都没有。