我正在尝试使用Intent来启动一个Activity,但是在第二个activity的setContentView()中发生了上述错误.
这是我的代码和布局文件.
itemactivity.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:orientation="vertical">
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
主要活动:
Intent i=new Intent(MainActivity.this,ItemActivity.class);
startActivity(i);
Run Code Online (Sandbox Code Playgroud)
ItemActivity:
@Override
protected void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.itemactivity); // this is where error occurs
super.onCreate(savedInstanceState);
}
Run Code Online (Sandbox Code Playgroud)
这是完整的错误日志:
java.lang.RuntimeException: Unable to start activity ComponentInfo{bertaberim.team.beertaberim/bertaberim.team.beertaberim.ItemActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'int android.view.ViewGroup.getPaddingLeft()' on a null object reference
11-04 23:01:20.621 20634-20634/? E/AndroidRuntime: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3119)
11-04 23:01:20.621 20634-20634/? E/AndroidRuntime: at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3218)
11-04 23:01:20.621 20634-20634/? E/AndroidRuntime: at android.app.ActivityThread.access$1000(ActivityThread.java:198)
11-04 23:01:20.621 20634-20634/? E/AndroidRuntime: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1676)
11-04 23:01:20.621 20634-20634/? …
Run Code Online (Sandbox Code Playgroud) 我写了一个程序来自我解决
void hello()
{
printf("hello world\n");
}
int main(int argc, char **argv)
{
char *buf="hello";
void *hndl = dlopen(argv[0], RTLD_LAZY);
void (*fptr)(void) = dlsym(hndl, buf);
if (fptr != NULL)
fptr();
dlclose(hndl);
}
Run Code Online (Sandbox Code Playgroud)
但是我得到了"segemention fault"错误我用.so库测试了这个程序并且它可以工作但不能让它自己工作
我想编写一个从stdin读取的程序:scanf("%s %s", foo, args);
然后使用参数运行函数foo(之前在程序中定义): foo(args);
我不知道如何在C中执行此操作.我之前可以很容易地在Shell中做到这一点,但在C中似乎很难
我需要一个函数来)
从字符串的末尾删除字符.例如,hello,world)
应该转换为hello,world
.
我写了这个:
char *a="hello,world)";
int a_len=strlen(a);
*(a+a_len-1)='\0';
printf("%s", a);
Run Code Online (Sandbox Code Playgroud)
但输出中没有显示任何内容.